#6 Added ability to view other users' certificates
This commit is contained in:
parent
a135007160
commit
ff049e2c1b
|
@ -160,8 +160,9 @@ abstract class element {
|
||||||
*
|
*
|
||||||
* @param \pdf $pdf the pdf object
|
* @param \pdf $pdf the pdf object
|
||||||
* @param bool $preview true if it is a preview, false otherwise
|
* @param bool $preview true if it is a preview, false otherwise
|
||||||
|
* @param \stdClass $user the user we are rendering this for
|
||||||
*/
|
*/
|
||||||
public abstract function render($pdf, $preview);
|
public abstract function render($pdf, $preview, $user);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Render the element in html.
|
* Render the element in html.
|
||||||
|
|
|
@ -68,15 +68,18 @@ class report_table extends \table_sql {
|
||||||
'fullname',
|
'fullname',
|
||||||
'timecreated',
|
'timecreated',
|
||||||
'code',
|
'code',
|
||||||
|
'download'
|
||||||
));
|
));
|
||||||
$this->define_headers(array(
|
$this->define_headers(array(
|
||||||
get_string('fullname'),
|
get_string('fullname'),
|
||||||
get_string('receiveddate', 'customcert'),
|
get_string('receiveddate', 'customcert'),
|
||||||
get_string('code', 'customcert')
|
get_string('code', 'customcert'),
|
||||||
|
get_string('file')
|
||||||
));
|
));
|
||||||
$this->collapsible(false);
|
$this->collapsible(false);
|
||||||
$this->sortable(true);
|
$this->sortable(true);
|
||||||
$this->no_sorting('code');
|
$this->no_sorting('code');
|
||||||
|
$this->no_sorting('download');
|
||||||
$this->is_downloadable(true);
|
$this->is_downloadable(true);
|
||||||
|
|
||||||
$this->customcertid = $customcertid;
|
$this->customcertid = $customcertid;
|
||||||
|
@ -116,6 +119,24 @@ class report_table extends \table_sql {
|
||||||
return $user->code;
|
return $user->code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate the download column.
|
||||||
|
*
|
||||||
|
* @param \stdClass $user
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function col_download($user) {
|
||||||
|
global $OUTPUT;
|
||||||
|
|
||||||
|
$icon = new \pix_icon('i/import', get_string('download'));
|
||||||
|
$link = new \moodle_url('/mod/customcert/report.php',
|
||||||
|
array('id' => $this->cm->id,
|
||||||
|
'downloadcert' => '1',
|
||||||
|
'userid' => $user->id));
|
||||||
|
|
||||||
|
return $OUTPUT->action_link($link, '', null, null, $icon);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Query the reader.
|
* Query the reader.
|
||||||
*
|
*
|
||||||
|
|
|
@ -247,9 +247,16 @@ class template {
|
||||||
* Generate the PDF for the template.
|
* Generate the PDF for the template.
|
||||||
*
|
*
|
||||||
* @param bool $preview true if it is a preview, false otherwise
|
* @param bool $preview true if it is a preview, false otherwise
|
||||||
|
* @param int $userid the id of the user whose certificate we want to view
|
||||||
*/
|
*/
|
||||||
public function generate_pdf($preview = false) {
|
public function generate_pdf($preview = false, $userid = null) {
|
||||||
global $CFG, $DB;
|
global $CFG, $DB, $USER;
|
||||||
|
|
||||||
|
if (empty($userid)) {
|
||||||
|
$user = $USER;
|
||||||
|
} else {
|
||||||
|
$user = \core_user::get_user($userid);
|
||||||
|
}
|
||||||
|
|
||||||
require_once($CFG->libdir . '/pdflib.php');
|
require_once($CFG->libdir . '/pdflib.php');
|
||||||
|
|
||||||
|
@ -289,7 +296,7 @@ class template {
|
||||||
foreach ($elements as $element) {
|
foreach ($elements as $element) {
|
||||||
// Get an instance of the element class.
|
// Get an instance of the element class.
|
||||||
if ($e = \mod_customcert\element::instance($element)) {
|
if ($e = \mod_customcert\element::instance($element)) {
|
||||||
$e->render($pdf, $preview);
|
$e->render($pdf, $preview, $user);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,8 +47,9 @@ class element extends \mod_customcert\element {
|
||||||
*
|
*
|
||||||
* @param \pdf $pdf the pdf object
|
* @param \pdf $pdf the pdf object
|
||||||
* @param bool $preview true if it is a preview, false otherwise
|
* @param bool $preview true if it is a preview, false otherwise
|
||||||
|
* @param \stdClass $user the user we are rendering this for
|
||||||
*/
|
*/
|
||||||
public function render($pdf, $preview) {
|
public function render($pdf, $preview, $user) {
|
||||||
$colour = \TCPDF_COLORS::convertHTMLColorToDec($this->element->colour, $colour);
|
$colour = \TCPDF_COLORS::convertHTMLColorToDec($this->element->colour, $colour);
|
||||||
$pdf->SetLineStyle(array('width' => $this->element->data, 'color' => $colour));
|
$pdf->SetLineStyle(array('width' => $this->element->data, 'color' => $colour));
|
||||||
$pdf->Line(0, 0, $pdf->getPageWidth(), 0);
|
$pdf->Line(0, 0, $pdf->getPageWidth(), 0);
|
||||||
|
|
|
@ -32,8 +32,9 @@ class element extends \mod_customcert\element {
|
||||||
*
|
*
|
||||||
* @param \pdf $pdf the pdf object
|
* @param \pdf $pdf the pdf object
|
||||||
* @param bool $preview true if it is a preview, false otherwise
|
* @param bool $preview true if it is a preview, false otherwise
|
||||||
|
* @param \stdClass $user the user we are rendering this for
|
||||||
*/
|
*/
|
||||||
public function render($pdf, $preview) {
|
public function render($pdf, $preview, $user) {
|
||||||
\mod_customcert\element_helper::render_content($pdf, $this, self::get_category_name());
|
\mod_customcert\element_helper::render_content($pdf, $this, self::get_category_name());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,9 +32,10 @@ class element extends \mod_customcert\element {
|
||||||
*
|
*
|
||||||
* @param \pdf $pdf the pdf object
|
* @param \pdf $pdf the pdf object
|
||||||
* @param bool $preview true if it is a preview, false otherwise
|
* @param bool $preview true if it is a preview, false otherwise
|
||||||
|
* @param \stdClass $user the user we are rendering this for
|
||||||
*/
|
*/
|
||||||
public function render($pdf, $preview) {
|
public function render($pdf, $preview, $user) {
|
||||||
global $DB, $USER;
|
global $DB;
|
||||||
|
|
||||||
if ($preview) {
|
if ($preview) {
|
||||||
$code = \mod_customcert\certificate::generate_code();
|
$code = \mod_customcert\certificate::generate_code();
|
||||||
|
@ -44,7 +45,7 @@ class element extends \mod_customcert\element {
|
||||||
// Get the customcert this page belongs to.
|
// Get the customcert this page belongs to.
|
||||||
$customcert = $DB->get_record('customcert', array('templateid' => $page->templateid), '*', MUST_EXIST);
|
$customcert = $DB->get_record('customcert', array('templateid' => $page->templateid), '*', MUST_EXIST);
|
||||||
// Now we can get the issue for this user.
|
// Now we can get the issue for this user.
|
||||||
$issue = $DB->get_record('customcert_issues', array('userid' => $USER->id, 'customcertid' => $customcert->id), '*', MUST_EXIST);
|
$issue = $DB->get_record('customcert_issues', array('userid' => $user->id, 'customcertid' => $customcert->id), '*', MUST_EXIST);
|
||||||
$code = $issue->code;
|
$code = $issue->code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,8 +32,9 @@ class element extends \mod_customcert\element {
|
||||||
*
|
*
|
||||||
* @param \pdf $pdf the pdf object
|
* @param \pdf $pdf the pdf object
|
||||||
* @param bool $preview true if it is a preview, false otherwise
|
* @param bool $preview true if it is a preview, false otherwise
|
||||||
|
* @param \stdClass $user the user we are rendering this for
|
||||||
*/
|
*/
|
||||||
public function render($pdf, $preview) {
|
public function render($pdf, $preview, $user) {
|
||||||
global $COURSE;
|
global $COURSE;
|
||||||
|
|
||||||
\mod_customcert\element_helper::render_content($pdf, $this, $COURSE->fullname);
|
\mod_customcert\element_helper::render_content($pdf, $this, $COURSE->fullname);
|
||||||
|
|
|
@ -83,9 +83,10 @@ class element extends \mod_customcert\element {
|
||||||
*
|
*
|
||||||
* @param \pdf $pdf the pdf object
|
* @param \pdf $pdf the pdf object
|
||||||
* @param bool $preview true if it is a preview, false otherwise
|
* @param bool $preview true if it is a preview, false otherwise
|
||||||
|
* @param \stdClass $user the user we are rendering this for
|
||||||
*/
|
*/
|
||||||
public function render($pdf, $preview) {
|
public function render($pdf, $preview, $user) {
|
||||||
global $COURSE, $DB, $USER;
|
global $COURSE, $DB;
|
||||||
|
|
||||||
// If there is no element data, we have nothing to display.
|
// If there is no element data, we have nothing to display.
|
||||||
if (empty($this->element->data)) {
|
if (empty($this->element->data)) {
|
||||||
|
@ -106,7 +107,7 @@ class element extends \mod_customcert\element {
|
||||||
// Get the customcert this page belongs to.
|
// Get the customcert this page belongs to.
|
||||||
$customcert = $DB->get_record('customcert', array('templateid' => $page->templateid), '*', MUST_EXIST);
|
$customcert = $DB->get_record('customcert', array('templateid' => $page->templateid), '*', MUST_EXIST);
|
||||||
// Now we can get the issue for this user.
|
// Now we can get the issue for this user.
|
||||||
$issue = $DB->get_record('customcert_issues', array('userid' => $USER->id, 'customcertid' => $customcert->id), '*', MUST_EXIST);
|
$issue = $DB->get_record('customcert_issues', array('userid' => $user->id, 'customcertid' => $customcert->id), '*', MUST_EXIST);
|
||||||
|
|
||||||
if ($dateitem == CUSTOMCERT_DATE_ISSUE) {
|
if ($dateitem == CUSTOMCERT_DATE_ISSUE) {
|
||||||
$date = $issue->timecreated;
|
$date = $issue->timecreated;
|
||||||
|
|
|
@ -83,9 +83,10 @@ class element extends \mod_customcert\element {
|
||||||
*
|
*
|
||||||
* @param \pdf $pdf the pdf object
|
* @param \pdf $pdf the pdf object
|
||||||
* @param bool $preview true if it is a preview, false otherwise
|
* @param bool $preview true if it is a preview, false otherwise
|
||||||
|
* @param \stdClass $user the user we are rendering this for
|
||||||
*/
|
*/
|
||||||
public function render($pdf, $preview) {
|
public function render($pdf, $preview, $user) {
|
||||||
global $COURSE, $USER;
|
global $COURSE;
|
||||||
|
|
||||||
// If there is no element data, we have nothing to display.
|
// If there is no element data, we have nothing to display.
|
||||||
if (empty($this->element->data)) {
|
if (empty($this->element->data)) {
|
||||||
|
@ -101,7 +102,7 @@ class element extends \mod_customcert\element {
|
||||||
$grade = grade_format_gradevalue('100', $courseitem, true, $gradeinfo->gradeformat, 2);
|
$grade = grade_format_gradevalue('100', $courseitem, true, $gradeinfo->gradeformat, 2);
|
||||||
} else {
|
} else {
|
||||||
// Get the grade for the grade item.
|
// Get the grade for the grade item.
|
||||||
$grade = self::get_grade($gradeinfo, $USER->id);
|
$grade = self::get_grade($gradeinfo, $user->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
\mod_customcert\element_helper::render_content($pdf, $this, $grade);
|
\mod_customcert\element_helper::render_content($pdf, $this, $grade);
|
||||||
|
|
|
@ -60,8 +60,9 @@ class element extends \mod_customcert\element {
|
||||||
*
|
*
|
||||||
* @param \pdf $pdf the pdf object
|
* @param \pdf $pdf the pdf object
|
||||||
* @param bool $preview true if it is a preview, false otherwise
|
* @param bool $preview true if it is a preview, false otherwise
|
||||||
|
* @param \stdClass $user the user we are rendering this for
|
||||||
*/
|
*/
|
||||||
public function render($pdf, $preview) {
|
public function render($pdf, $preview, $user) {
|
||||||
global $DB;
|
global $DB;
|
||||||
|
|
||||||
// Check that the grade item is not empty.
|
// Check that the grade item is not empty.
|
||||||
|
|
|
@ -133,8 +133,9 @@ class element extends \mod_customcert\element {
|
||||||
*
|
*
|
||||||
* @param \pdf $pdf the pdf object
|
* @param \pdf $pdf the pdf object
|
||||||
* @param bool $preview true if it is a preview, false otherwise
|
* @param bool $preview true if it is a preview, false otherwise
|
||||||
|
* @param \stdClass $user the user we are rendering this for
|
||||||
*/
|
*/
|
||||||
public function render($pdf, $preview) {
|
public function render($pdf, $preview, $user) {
|
||||||
global $CFG;
|
global $CFG;
|
||||||
|
|
||||||
// If there is no element data, we have nothing to display.
|
// If there is no element data, we have nothing to display.
|
||||||
|
|
|
@ -32,11 +32,10 @@ class element extends \mod_customcert\element {
|
||||||
*
|
*
|
||||||
* @param \pdf $pdf the pdf object
|
* @param \pdf $pdf the pdf object
|
||||||
* @param bool $preview true if it is a preview, false otherwise
|
* @param bool $preview true if it is a preview, false otherwise
|
||||||
|
* @param \stdClass $user the user we are rendering this for
|
||||||
*/
|
*/
|
||||||
public function render($pdf, $preview) {
|
public function render($pdf, $preview, $user) {
|
||||||
global $USER;
|
\mod_customcert\element_helper::render_content($pdf, $this, fullname($user));
|
||||||
|
|
||||||
\mod_customcert\element_helper::render_content($pdf, $this, fullname($USER));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -58,8 +58,9 @@ class element extends \mod_customcert\element {
|
||||||
*
|
*
|
||||||
* @param \pdf $pdf the pdf object
|
* @param \pdf $pdf the pdf object
|
||||||
* @param bool $preview true if it is a preview, false otherwise
|
* @param bool $preview true if it is a preview, false otherwise
|
||||||
|
* @param \stdClass $user the user we are rendering this for
|
||||||
*/
|
*/
|
||||||
public function render($pdf, $preview) {
|
public function render($pdf, $preview, $user) {
|
||||||
global $DB;
|
global $DB;
|
||||||
|
|
||||||
$teacher = $DB->get_record('user', array('id' => $this->element->data));
|
$teacher = $DB->get_record('user', array('id' => $this->element->data));
|
||||||
|
|
|
@ -56,8 +56,9 @@ class element extends \mod_customcert\element {
|
||||||
*
|
*
|
||||||
* @param \pdf $pdf the pdf object
|
* @param \pdf $pdf the pdf object
|
||||||
* @param bool $preview true if it is a preview, false otherwise
|
* @param bool $preview true if it is a preview, false otherwise
|
||||||
|
* @param \stdClass $user the user we are rendering this for
|
||||||
*/
|
*/
|
||||||
public function render($pdf, $preview) {
|
public function render($pdf, $preview, $user) {
|
||||||
\mod_customcert\element_helper::render_content($pdf, $this, $this->element->data);
|
\mod_customcert\element_helper::render_content($pdf, $this, $this->element->data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -87,9 +87,10 @@ class element extends \mod_customcert\element {
|
||||||
*
|
*
|
||||||
* @param \pdf $pdf the pdf object
|
* @param \pdf $pdf the pdf object
|
||||||
* @param bool $preview true if it is a preview, false otherwise
|
* @param bool $preview true if it is a preview, false otherwise
|
||||||
|
* @param \stdClass $user the user we are rendering this for
|
||||||
*/
|
*/
|
||||||
public function render($pdf, $preview) {
|
public function render($pdf, $preview, $user) {
|
||||||
global $DB, $USER;
|
global $CFG, $DB;
|
||||||
|
|
||||||
// The user field to display.
|
// The user field to display.
|
||||||
$field = $this->element->data;
|
$field = $this->element->data;
|
||||||
|
@ -97,10 +98,17 @@ class element extends \mod_customcert\element {
|
||||||
$value = '';
|
$value = '';
|
||||||
if (is_number($field)) { // Must be a custom user profile field.
|
if (is_number($field)) { // Must be a custom user profile field.
|
||||||
if ($field = $DB->get_record('user_info_field', array('id' => $field))) {
|
if ($field = $DB->get_record('user_info_field', array('id' => $field))) {
|
||||||
$value = $USER->profile[$field->shortname];
|
$file = $CFG->dirroot . '/user/profile/field/' . $field->datatype . '/field.class.php';
|
||||||
|
if (file_exists($file)) {
|
||||||
|
require_once($CFG->dirroot . '/user/profile/lib.php');
|
||||||
|
require_once($file);
|
||||||
|
$class = "profile_field_{$field->datatype}";
|
||||||
|
$field = new $class($field->id, $user->id);
|
||||||
|
$value = $field->display_data();
|
||||||
}
|
}
|
||||||
} else if (!empty($USER->$field)) { // Field in the user table.
|
}
|
||||||
$value = $USER->$field;
|
} else if (!empty($user->$field)) { // Field in the user table.
|
||||||
|
$value = $user->$field;
|
||||||
}
|
}
|
||||||
|
|
||||||
\mod_customcert\element_helper::render_content($pdf, $this, $value);
|
\mod_customcert\element_helper::render_content($pdf, $this, $value);
|
||||||
|
|
14
report.php
14
report.php
|
@ -26,6 +26,10 @@ require_once('../../config.php');
|
||||||
|
|
||||||
$id = required_param('id', PARAM_INT);
|
$id = required_param('id', PARAM_INT);
|
||||||
$download = optional_param('download', '', PARAM_ALPHA);
|
$download = optional_param('download', '', PARAM_ALPHA);
|
||||||
|
$downloadcert = optional_param('downloadcert', '', PARAM_BOOL);
|
||||||
|
if ($downloadcert) {
|
||||||
|
$userid = required_param('userid', PARAM_INT);
|
||||||
|
}
|
||||||
|
|
||||||
$page = optional_param('page', 0, PARAM_INT);
|
$page = optional_param('page', 0, PARAM_INT);
|
||||||
$perpage = optional_param('perpage', \mod_customcert\certificate::CUSTOMCERT_PER_PAGE, PARAM_INT);
|
$perpage = optional_param('perpage', \mod_customcert\certificate::CUSTOMCERT_PER_PAGE, PARAM_INT);
|
||||||
|
@ -42,7 +46,15 @@ require_login($course, false, $cm);
|
||||||
$context = context_module::instance($cm->id);
|
$context = context_module::instance($cm->id);
|
||||||
require_capability('mod/customcert:manage', $context);
|
require_capability('mod/customcert:manage', $context);
|
||||||
|
|
||||||
// Get the users who have been issued.
|
// Check if we requested to download another user's certificate.
|
||||||
|
if ($downloadcert) {
|
||||||
|
$template = $DB->get_record('customcert_templates', array('id' => $customcert->templateid), '*', MUST_EXIST);
|
||||||
|
$template = new \mod_customcert\template($template);
|
||||||
|
$template->generate_pdf(false, $userid);
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if we are in group mode.
|
||||||
if ($groupmode = groups_get_activity_groupmode($cm)) {
|
if ($groupmode = groups_get_activity_groupmode($cm)) {
|
||||||
groups_get_activity_group($cm, true);
|
groups_get_activity_group($cm, true);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue