#6 Added ability to view other users' certificates

This commit is contained in:
Mark Nelson 2016-08-23 16:22:58 +08:00
parent a135007160
commit ff049e2c1b
16 changed files with 90 additions and 32 deletions

View file

@ -160,8 +160,9 @@ abstract class element {
*
* @param \pdf $pdf the pdf object
* @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.

View file

@ -68,15 +68,18 @@ class report_table extends \table_sql {
'fullname',
'timecreated',
'code',
'download'
));
$this->define_headers(array(
get_string('fullname'),
get_string('receiveddate', 'customcert'),
get_string('code', 'customcert')
get_string('code', 'customcert'),
get_string('file')
));
$this->collapsible(false);
$this->sortable(true);
$this->no_sorting('code');
$this->no_sorting('download');
$this->is_downloadable(true);
$this->customcertid = $customcertid;
@ -116,6 +119,24 @@ class report_table extends \table_sql {
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.
*

View file

@ -247,9 +247,16 @@ class template {
* Generate the PDF for the template.
*
* @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) {
global $CFG, $DB;
public function generate_pdf($preview = false, $userid = null) {
global $CFG, $DB, $USER;
if (empty($userid)) {
$user = $USER;
} else {
$user = \core_user::get_user($userid);
}
require_once($CFG->libdir . '/pdflib.php');
@ -289,7 +296,7 @@ class template {
foreach ($elements as $element) {
// Get an instance of the element class.
if ($e = \mod_customcert\element::instance($element)) {
$e->render($pdf, $preview);
$e->render($pdf, $preview, $user);
}
}
}