Compare commits

...

26 commits

Author SHA1 Message Date
Mark Nelson
a98a860e3a Bumped version 2016-12-13 10:54:17 +08:00
Mark Nelson
3e638fbeb6 #57 Set the activity as viewed when downloaded 2016-11-29 15:49:20 +08:00
Mark Nelson
6fffb1a89a #49 Allow templates to have the same name 2016-11-29 15:49:18 +08:00
Mark Nelson
583368656e #55 Fixed references to capabilities from mod_certificate 2016-11-29 13:31:53 +08:00
Mark Nelson
39284f7891 Updated maturity 2016-08-26 19:33:14 +08:00
Mark Nelson
40c4cffa38 Bumped version 2016-08-26 19:12:07 +08:00
Mark Nelson
dab7ebfeb5 Ensure date indexes do not conflict with module ids 2016-08-26 17:15:59 +08:00
Mark Nelson
e5d523de91 #14 Help translators with date suffixes
AMOS BEGIN
 MOV [numbersuffix_st,mod_customcert],[numbersuffix_st_as_in_first,mod_customcert]
 MOV [numbersuffix_nd,mod_customcert],[numbersuffix_nd_as_in_second,mod_customcert]
 MOV [numbersuffix_rd,mod_customcert],[numbersuffix_rd_as_in_third,mod_customcert]
AMOS END
2016-08-26 17:15:55 +08:00
Mark Nelson
e7d5cbca6e Improved navigation bar for the element repositioning page 2016-08-26 15:07:20 +08:00
Mark Nelson
9224b057f7 #32 Fixed issue with images not loading from site templates 2016-08-26 15:07:13 +08:00
Mark Nelson
e5f5e4297a Show a link to manage templates 2016-08-25 18:47:42 +08:00
Mark Nelson
88b7a7839b Uncapitalised usages of the 'context_*' classes 2016-08-25 18:47:31 +08:00
Mark Nelson
c1ac1b9e43 Uncapitalised usage of the 'context_system' class 2016-08-25 16:22:43 +08:00
Mark Nelson
e4db1591dd Removed 'File' column when downloading report 2016-08-25 16:22:33 +08:00
Mark Nelson
787746e4a8 Removed unused global 2016-08-25 16:22:23 +08:00
Mark Nelson
c6540b1cd9 Fixed issue with reordering retrieving more than one record 2016-08-24 15:16:18 +08:00
Mark Nelson
1eada36b1f Added a background image element 2016-08-24 15:16:18 +08:00
Mark Nelson
571052e1aa #23 Ensure the user field is always shown when repositioning elements 2016-08-24 15:16:18 +08:00
Mark Nelson
6d28a15851 #6 Added ability to view other users' certificates 2016-08-24 15:16:18 +08:00
Mark Nelson
d6ebc95c77 #4 Added ability to sort the reports table
The table is now an instance of 'table_sql', not 'html_table'.
This made sorting easy to implement, with the added benefit
of taking advantage of the spout library for exporting data.
2016-08-24 15:16:18 +08:00
bobmosh
0f77856e90 Added a tutorial on how to add fonts
Added a tutorial to the README.md, explaining how to add fonts to tcpdf
and therefore making them available in the Custom Certificate module.
2016-08-24 15:16:18 +08:00
Mark Nelson
fdb0609990 #17 Improved reference point location help string 2016-08-24 15:16:18 +08:00
Mark Nelson
92fda00268 #21 Changed 'Rearrange' to 'Reposition' for clarity 2016-08-24 15:16:18 +08:00
Mark Nelson
8e23e39bcd Removed unused element list table column
Also left aligned action icons.
2016-08-24 15:16:18 +08:00
Mark Nelson
986badd1e9 #22 Described importance of element order 2016-08-24 15:16:18 +08:00
Mark Nelson
a3fb3a7af4 #26 Fixed userfields not displaying data correctly 2016-08-24 15:16:18 +08:00
44 changed files with 608 additions and 213 deletions

View file

@ -22,3 +22,28 @@ Use git pull to update this repository periodically to ensure you have the lates
Visit https://github.com/markn86/moodle-mod_customcert and download the zip, uncompress this zip and extract the folder. The folder will have a name similar to markn86-moodle-mod_customcert-c9fbadb, you MUST rename this to customcert. Place this folder in your mod folder in your Moodle directory.
nb. The reason this is not the recommended method is due to the fact you have to over-write the contents of this folder to apply any future updates to the customcert module. In the above method there is a simple command to update the files.
Customisation
=============
========================= Add Fonts to TCPDF. =========================
For customization, you have a couple of options in the Custom Certificate module. One of the most common customizations is, adding fonts to the Certificate creator.
Custom Certificate uses a pdf creator called TCPDF, which embeds fonts into the PDF file, so that you can view fonts, even though they are not installed on the target machine. This requires you to tell TCPDF which fonts to take.
Importing Fonts into TCPDF is quite simple:
1. Convert the font you want embedded into the tcpdf format (for example using [http://fonts.snm-portal.com][1] or [http://www.xml-convert.com/en/convert-tff-font-to-afm-pfa-fpdf-tcpdf][2])
2. Put the converted files into the folder: `/path/to/moodle/lib/tcpdf/fonts`
3. Use the font in your certificate builder
4. Enjoy
> Please note that inserting a file into the tcpdf folder is considered a "core hack" and might not be available on some commercially hosted systems. Please check your providers agreement on the topic to make sure this is something you're allowed to do.
[1]: http://fonts.snm-portal.com "http://fonts.snm-portal.com"
[2]: http://www.xml-convert.com/en/convert-tff-font-to-afm-pfa-fpdf-tcpdf "http://www.xml-convert.com/en/convert-tff-font-to-afm-pfa-fpdf-tcpdf"

View file

@ -52,12 +52,7 @@ class certificate {
* @var int the number of issues that will be displayed on each page in the report
* If you want to display all customcerts on a page set this to 0.
*/
const CUSTOMCERT_PER_PAGE = '20';
/**
* @var int the max number of issues to display
*/
const CUSTOMCERT_MAX_PER_PAGE = '300';
const CUSTOMCERT_PER_PAGE = '50';
/**
* Handles setting the protection field for the customcert
@ -233,11 +228,12 @@ class certificate {
* @param int $customcertid
* @param bool $groupmode are we in group mode
* @param \stdClass $cm the course module
* @param int $page offset
* @param int $perpage total per page
* @param int $limitfrom
* @param int $limitnum
* @param string $sort
* @return \stdClass the users
*/
public static function get_issues($customcertid, $groupmode, $cm, $page, $perpage) {
public static function get_issues($customcertid, $groupmode, $cm, $limitfrom, $limitnum, $sort = '') {
global $DB;
// Get the conditional SQL.
@ -252,15 +248,21 @@ class certificate {
$allparams = $conditionsparams + array('customcertid' => $customcertid);
// Return the issues.
$sql = "SELECT u.*, ci.code, ci.timecreated
$ufields = \user_picture::fields('u');
$sql = "SELECT $ufields, ci.code, ci.timecreated
FROM {user} u
INNER JOIN {customcert_issues} ci
ON u.id = ci.userid
WHERE u.deleted = 0
AND ci.customcertid = :customcertid
$conditionssql
ORDER BY " . $DB->sql_fullname();
return $DB->get_records_sql($sql, $allparams, $page * $perpage, $perpage);
$conditionssql";
if ($sort) {
$sql .= "ORDER BY " . $sort;
} else {
$sql .= "ORDER BY " . $DB->sql_fullname();
}
return $DB->get_records_sql($sql, $allparams, $limitfrom, $limitnum);
}
/**
@ -312,7 +314,7 @@ class certificate {
$conditionsparams = array();
// Get all users that can manage this certificate to exclude them from the report.
$certmanagers = array_keys(get_users_by_capability($context, 'mod/certificate:manage', 'u.id'));
$certmanagers = array_keys(get_users_by_capability($context, 'mod/customcert:manage', 'u.id'));
$certmanagers = array_merge($certmanagers, array_keys(get_admins()));
list($sql, $params) = $DB->get_in_or_equal($certmanagers, SQL_PARAMS_NAMED, 'cert');
$conditionssql .= "AND NOT u.id $sql \n";
@ -379,62 +381,4 @@ class certificate {
return $code;
}
/**
* Generate the report.
*
* @param \stdClass $customcert
* @param \stdClass $users the list of users who have had a customcert issued
* @param string $type
*/
public static function generate_report_file($customcert, $users, $type) {
global $CFG, $COURSE;
if ($type == 'ods') {
require_once($CFG->libdir . '/odslib.class.php');
$workbook = new \MoodleODSWorkbook('-');
} else if ($type == 'xls') {
require_once($CFG->libdir . '/excellib.class.php');
$workbook = new \MoodleExcelWorkbook('-');
}
$filename = clean_filename($COURSE->shortname . ' ' . rtrim($customcert->name, '.') . '.' . $type);
// Send HTTP headers.
$workbook->send($filename);
// Creating the first worksheet.
$myxls = $workbook->add_worksheet(get_string('report', 'customcert'));
// Print names of all the fields.
$myxls->write_string(0, 0, get_string('lastname'));
$myxls->write_string(0, 1, get_string('firstname'));
$myxls->write_string(0, 2, get_string('idnumber'));
$myxls->write_string(0, 3, get_string('group'));
$myxls->write_string(0, 4, get_string('receiveddate', 'customcert'));
$myxls->write_string(0, 5, get_string('code', 'customcert'));
// Generate the data for the body of the spreadsheet.
$row = 1;
if ($users) {
foreach ($users as $user) {
$myxls->write_string($row, 0, $user->lastname);
$myxls->write_string($row, 1, $user->firstname);
$studentid = (!empty($user->idnumber)) ? $user->idnumber : ' ';
$myxls->write_string($row, 2, $studentid);
$ug2 = '';
if ($usergrps = groups_get_all_groups($COURSE->id, $user->id)) {
foreach ($usergrps as $ug) {
$ug2 = $ug2 . $ug->name;
}
}
$myxls->write_string($row, 3, $ug2);
$myxls->write_string($row, 4, userdate($user->timecreated));
$myxls->write_string($row, 5, $user->code);
$row++;
}
}
// Close the workbook.
$workbook->close();
}
}

View file

@ -128,17 +128,8 @@ class edit_form extends \moodleform {
* @return array the errors that were found
*/
public function validation($data, $files) {
global $DB;
$errors = parent::validation($data, $files);
// Check that the template name does not already exist for another template.
if ($template = $DB->get_record('customcert_templates', array('name' => $data['name']))) {
if (empty($data['tid']) || $template->id != $data['tid']) {
$errors['name'] = get_string('customcertnameexists', 'customcert');
}
}
// Go through the data and check any width, height or margin values.
foreach ($data as $key => $value) {
if (strpos($key, 'pagewidth_') !== false) {
@ -240,12 +231,7 @@ class edit_form extends \moodleform {
// Create a table to display these elements.
$table = new \html_table();
$table->head = array(get_string('name', 'customcert'), get_string('type', 'customcert'), '');
$table->align = array('left', 'left', 'center');
// If we have more than one element then we can change the order, so add extra column for the up and down arrow.
if ($numelements > 1) {
$table->head[] = '';
$table->align[] = 'center';
}
$table->align = array('left', 'left', 'left');
// Loop through and add the elements to the table.
foreach ($elements as $element) {
$row = new \html_table_row();

View file

@ -159,8 +159,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

@ -38,15 +38,29 @@ class load_template_form extends \moodleform {
$mform =& $this->_form;
// Get the context.
$context = $this->_customdata['context'];
$mform->addElement('header', 'loadtemplateheader', get_string('loadtemplate', 'customcert'));
$templates = $DB->get_records_menu('customcert_templates',
array('contextid' => \CONTEXT_SYSTEM::instance()->id), 'name ASC', 'id, name');
// Display a link to the manage templates page.
if ($context->contextlevel != CONTEXT_SYSTEM && has_capability('mod/customcert:manage', \context_system::instance())) {
$link = \html_writer::link(new \moodle_url('/mod/customcert/manage_templates.php'),
get_string('managetemplates', 'customcert'));
$mform->addElement('static', 'managetemplates', '', $link);
}
$templates = $DB->get_records_menu('customcert_templates',
array('contextid' => \context_system::instance()->id), 'name ASC', 'id, name');
if ($templates) {
$group = array();
$group[] = $mform->createElement('select', 'ltid', '', $templates);
$group[] = $mform->createElement('submit', 'loadtemplatesubmit', get_string('load', 'customcert'));
$mform->addElement('group', 'loadtemplategroup', '', $group, '', false);
$mform->setType('ltid', PARAM_INT);
} else {
$msg = \html_writer::tag('div', get_string('notemplates', 'customcert'), array('class' => 'alert'));
$mform->addElement('static', 'notemplates', '', $msg);
}
}
}

182
classes/report_table.php Normal file
View file

@ -0,0 +1,182 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* The report that displays issued certificates.
*
* @package mod_customcert
* @copyright 2016 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_customcert;
defined('MOODLE_INTERNAL') || die;
global $CFG;
require_once($CFG->libdir . '/tablelib.php');
/**
* Class for the report that displays issued certificates.
*
* @package mod_customcert
* @copyright 2016 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class report_table extends \table_sql {
/**
* @var int $customcertid The custom certificate id
*/
protected $customcertid;
/**
* @var \stdClass $cm The course module.
*/
protected $cm;
/**
* @var bool $groupmode are we in group mode?
*/
protected $groupmode;
/**
* Sets up the table.
*
* @param int $customcertid
* @param \stdClass $cm the course module
* @param bool $groupmode are we in group mode?
* @param string|null $download The file type, null if we are not downloading
*/
public function __construct($customcertid, $cm, $groupmode, $download = null) {
parent::__construct('mod_customcert_report_table');
$columns = array(
'fullname',
'timecreated',
'code'
);
$headers = array(
get_string('fullname'),
get_string('receiveddate', 'customcert'),
get_string('code', 'customcert')
);
// Check if we were passed a filename, which means we want to download it.
if ($download) {
$this->is_downloading($download, 'customcert-report');
}
if (!$this->is_downloading()) {
$columns[] = 'download';
$headers[] = get_string('file');
}
$this->define_columns($columns);
$this->define_headers($headers);
$this->collapsible(false);
$this->sortable(true);
$this->no_sorting('code');
$this->no_sorting('download');
$this->is_downloadable(true);
$this->customcertid = $customcertid;
$this->cm = $cm;
$this->groupmode = $groupmode;
}
/**
* Generate the fullname column.
*
* @param \stdClass $user
* @return string
*/
public function col_fullname($user) {
global $OUTPUT;
return $OUTPUT->user_picture($user) . ' ' . fullname($user);
}
/**
* Generate the certificate time created column.
*
* @param \stdClass $user
* @return string
*/
public function col_timecreated($user) {
return userdate($user->timecreated);
}
/**
* Generate the code column.
*
* @param \stdClass $user
* @return string
*/
public function col_code($user) {
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.
*
* @param int $pagesize size of page for paginated displayed table.
* @param bool $useinitialsbar do you want to use the initials bar.
*/
public function query_db($pagesize, $useinitialsbar = true) {
$total = \mod_customcert\certificate::get_number_of_issues($this->customcertid, $this->cm, $this->groupmode);
$this->pagesize($pagesize, $total);
$this->rawdata = \mod_customcert\certificate::get_issues($this->customcertid, $this->groupmode, $this->cm,
$this->get_page_start(), $this->get_page_size(), $this->get_sql_sort());
// Set initial bars.
if ($useinitialsbar) {
$this->initialbars($total > $pagesize);
}
}
/**
* Download the data.
*/
public function download() {
\core\session\manager::write_close();
$total = \mod_customcert\certificate::get_number_of_issues($this->customcertid, $this->cm, $this->groupmode);
$this->out($total, false);
exit;
}
}

View file

@ -146,7 +146,7 @@ class template {
* @return bool return true if the deletion was successful, false otherwise
*/
public function delete() {
global $CFG, $DB;
global $DB;
// Delete the elements.
$sql = "SELECT e.*
@ -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);
}
}
}
@ -322,8 +329,15 @@ class template {
} else { // Must be down.
$sequence = $moveitem->sequence + 1;
}
// Get the item we will be swapping with it.
$swapitem = $DB->get_record($table, array('sequence' => $sequence));
// Get the item we will be swapping with. Make sure it is related to the same template (if it's
// a page) or the same page (if it's an element).
if ($itemname == 'page') {
$params = array('templateid' => $moveitem->templateid);
} else { // Must be an element.
$params = array('pageid' => $moveitem->pageid);
}
$swapitem = $DB->get_record($table, $params + array('sequence' => $sequence));
}
// Check that there is an item to move, and an item to swap it with.

View file

@ -66,11 +66,6 @@ if ($context->contextlevel == CONTEXT_SYSTEM) {
$PAGE->navbar->add(get_string('editcustomcert', 'customcert'));
}
// The form for loading a customcert templates.
if ($tid && $DB->count_records('customcert_templates', array('contextid' => CONTEXT_SYSTEM::instance()->id)) > 0) {
$loadtemplateurl = new moodle_url('/mod/customcert/load_template.php', array('tid' => $tid));
$loadtemplateform = new \mod_customcert\load_template_form($loadtemplateurl);
}
// Flag to determine if we are deleting anything.
$deleting = false;
@ -225,7 +220,9 @@ if ($data = $mform->get_data()) {
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('editcustomcert', 'customcert'));
$mform->display();
if (isset($loadtemplateform)) {
if ($tid) {
$loadtemplateurl = new moodle_url('/mod/customcert/load_template.php', array('tid' => $tid));
$loadtemplateform = new \mod_customcert\load_template_form($loadtemplateurl, array('context' => $context));
$loadtemplateform->display();
}
echo $OUTPUT->footer();

View file

@ -0,0 +1,132 @@
<?php
// This file is part of the customcert module for Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace customcertelement_bgimage;
defined('MOODLE_INTERNAL') || die();
/**
* The customcert element background image's core interaction API.
*
* @package customcertelement_bgimage
* @copyright 2016 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class element extends \customcertelement_image\element {
/**
* This function renders the form elements when adding a customcert element.
*
* @param \mod_customcert\edit_element_form $mform the edit_form instance
*/
public function render_form_elements($mform) {
$mform->addElement('select', 'image', get_string('image', 'customcertelement_image'), self::get_images());
$mform->addElement('filemanager', 'customcertimage', get_string('uploadimage', 'customcert'), '', $this->filemanageroptions);
}
/**
* Performs validation on the element values.
*
* @param array $data the submitted data
* @param array $files the submitted files
* @return array the validation errors
*/
public function validate_form_elements($data, $files) {
// Array to return the errors.
return array();
}
/**
* This will handle how form data will be saved into the data column in the
* customcert_elements table.
*
* @param \stdClass $data the form data
* @return string the json encoded array
*/
public function save_unique_data($data) {
// Array of data we will be storing in the database.
$arrtostore = array(
'pathnamehash' => $data->image,
'width' => 0,
'height' => 0
);
return json_encode($arrtostore);
}
/**
* Handles rendering the element on the pdf.
*
* @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 function render($pdf, $preview, $user) {
global $CFG;
// If there is no element data, we have nothing to display.
if (empty($this->element->data)) {
return;
}
$imageinfo = json_decode($this->element->data);
// Get the image.
$fs = get_file_storage();
if ($file = $fs->get_file_by_hash($imageinfo->pathnamehash)) {
$contenthash = $file->get_contenthash();
$l1 = $contenthash[0] . $contenthash[1];
$l2 = $contenthash[2] . $contenthash[3];
$location = $CFG->dataroot . '/filedir' . '/' . $l1 . '/' . $l2 . '/' . $contenthash;
// Set the image to the size of the PDF page.
$pdf->Image($location, 0, 0, $pdf->getPageWidth(), $pdf->getPageHeight());
}
}
/**
* Render the element in html.
*
* This function is used to render the element when we are using the
* drag and drop interface to position it.
*
* @return string the html
*/
public function render_html() {
global $DB;
// If there is no element data, we have nothing to display.
if (empty($this->element->data)) {
return '';
}
$imageinfo = json_decode($this->element->data);
// Get the image.
$fs = get_file_storage();
if ($file = $fs->get_file_by_hash($imageinfo->pathnamehash)) {
$url = \moodle_url::make_pluginfile_url($file->get_contextid(), 'mod_customcert', 'image', $file->get_itemid(),
$file->get_filepath(), $file->get_filename());
// Get the page we are rendering this on.
$page = $DB->get_record('customcert_pages', array('id' => $this->element->pageid), '*', MUST_EXIST);
// Set the image to the size of the page.
$style = 'width: ' . $page->width . 'mm; height: ' . $page->height . 'mm';
return \html_writer::tag('img', '', array('src' => $url, 'style' => $style));
}
}
}

View file

@ -0,0 +1,25 @@
<?php
// This file is part of the customcert module for Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Strings for component 'customcertelement_bgimage', language 'en'.
*
* @package customcertelement_bgimage
* @copyright 2016 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['pluginname'] = 'Background image';

View file

@ -0,0 +1,29 @@
<?php
// This file is part of the customcert module for Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This file contains the version information for the background image plugin.
*
* @package customcertelement_bgimage
* @copyright 2016 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
$plugin->version = 2016032201; // The current module version (Date: YYYYMMDDXX).
$plugin->requires = 2015051100; // Requires this Moodle version (2.9).
$plugin->component = 'customcertelement_bgimage';

View file

@ -47,8 +47,9 @@ class element extends \mod_customcert\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 function render($pdf, $preview) {
public function render($pdf, $preview, $user) {
$colour = \TCPDF_COLORS::convertHTMLColorToDec($this->element->colour, $colour);
$pdf->SetLineStyle(array('width' => $this->element->data, 'color' => $colour));
$pdf->Line(0, 0, $pdf->getPageWidth(), 0);

View file

@ -24,6 +24,6 @@
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
$plugin->version = 2016021900; // The current module version (Date: YYYYMMDDXX).
$plugin->version = 2016032201; // The current module version (Date: YYYYMMDDXX).
$plugin->requires = 2015051100; // Requires this Moodle version (2.9).
$plugin->component = 'customcertelement_border';

View file

@ -32,8 +32,9 @@ class element extends \mod_customcert\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 function render($pdf, $preview) {
public function render($pdf, $preview, $user) {
\mod_customcert\element_helper::render_content($pdf, $this, self::get_category_name());
}

View file

@ -24,6 +24,6 @@
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
$plugin->version = 2016021900; // The current module version (Date: YYYYMMDDXX).
$plugin->version = 2016032201; // The current module version (Date: YYYYMMDDXX).
$plugin->requires = 2015051100; // Requires this Moodle version (2.9).
$plugin->component = 'customcertelement_categoryname';

View file

@ -32,9 +32,10 @@ class element extends \mod_customcert\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 function render($pdf, $preview) {
global $DB, $USER;
public function render($pdf, $preview, $user) {
global $DB;
if ($preview) {
$code = \mod_customcert\certificate::generate_code();
@ -44,7 +45,7 @@ class element extends \mod_customcert\element {
// Get the customcert this page belongs to.
$customcert = $DB->get_record('customcert', array('templateid' => $page->templateid), '*', MUST_EXIST);
// 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;
}

View file

@ -24,6 +24,6 @@
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
$plugin->version = 2016021900; // The current module version (Date: YYYYMMDDXX).
$plugin->version = 2016032201; // The current module version (Date: YYYYMMDDXX).
$plugin->requires = 2015051100; // Requires this Moodle version (2.9).
$plugin->component = 'customcertelement_code';

View file

@ -32,8 +32,9 @@ class element extends \mod_customcert\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 function render($pdf, $preview) {
public function render($pdf, $preview, $user) {
global $COURSE;
\mod_customcert\element_helper::render_content($pdf, $this, $COURSE->fullname);

View file

@ -24,6 +24,6 @@
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
$plugin->version = 2016021900; // The current module version (Date: YYYYMMDDXX).
$plugin->version = 2016032201; // The current module version (Date: YYYYMMDDXX).
$plugin->requires = 2015051100; // Requires this Moodle version (2.9).
$plugin->component = 'customcertelement_coursename';

View file

@ -21,12 +21,12 @@ defined('MOODLE_INTERNAL') || die();
/**
* Date - Issue
*/
define('CUSTOMCERT_DATE_ISSUE', '1');
define('CUSTOMCERT_DATE_ISSUE', '-1');
/**
* Date - Completion
*/
define('CUSTOMCERT_DATE_COMPLETION', '2');
define('CUSTOMCERT_DATE_COMPLETION', '-2');
require_once($CFG->dirroot . '/lib/grade/constants.php');
@ -83,9 +83,10 @@ class element extends \mod_customcert\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 function render($pdf, $preview) {
global $COURSE, $DB, $USER;
public function render($pdf, $preview, $user) {
global $COURSE, $DB;
// If there is no element data, we have nothing to display.
if (empty($this->element->data)) {
@ -106,7 +107,7 @@ class element extends \mod_customcert\element {
// Get the customcert this page belongs to.
$customcert = $DB->get_record('customcert', array('templateid' => $page->templateid), '*', MUST_EXIST);
// 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) {
$date = $issue->timecreated;
@ -251,11 +252,11 @@ class element extends \mod_customcert\element {
switch ($day % 10) {
// Handle 1st, 2nd, 3rd.
case 1:
return get_string('numbersuffix_st', 'customcertelement_date');
return get_string('numbersuffix_st_as_in_first', 'customcertelement_date');
case 2:
return get_string('numbersuffix_nd', 'customcertelement_date');
return get_string('numbersuffix_nd_as_in_second', 'customcertelement_date');
case 3:
return get_string('numbersuffix_rd', 'customcertelement_date');
return get_string('numbersuffix_rd_as_in_third', 'customcertelement_date');
}
}
return 'th';

View file

@ -29,7 +29,7 @@ $string['dateitem'] = 'Date item';
$string['dateitem_help'] = 'This will be the date that is printed on the certificate';
$string['issueddate'] = 'Issued date';
$string['pluginname'] = 'Date';
$string['numbersuffix_nd'] = 'nd';
$string['numbersuffix_rd'] = 'rd';
$string['numbersuffix_st'] = 'st';
$string['numbersuffix_nd_as_in_second'] = 'nd';
$string['numbersuffix_rd_as_in_third'] = 'rd';
$string['numbersuffix_st_as_in_first'] = 'st';
$string['userdateformat'] = 'User date format';

View file

@ -24,6 +24,6 @@
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
$plugin->version = 2016021900; // The current module version (Date: YYYYMMDDXX).
$plugin->version = 2016032201; // The current module version (Date: YYYYMMDDXX).
$plugin->requires = 2015051100; // Requires this Moodle version (2.9).
$plugin->component = 'customcertelement_date';

View file

@ -83,9 +83,10 @@ class element extends \mod_customcert\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 function render($pdf, $preview) {
global $COURSE, $USER;
public function render($pdf, $preview, $user) {
global $COURSE;
// If there is no element data, we have nothing to display.
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);
} else {
// 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);

View file

@ -24,6 +24,6 @@
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
$plugin->version = 2016021900; // The current module version (Date: YYYYMMDDXX).
$plugin->version = 2016032201; // The current module version (Date: YYYYMMDDXX).
$plugin->requires = 2015051100; // Requires this Moodle version (2.9).
$plugin->component = 'customcertelement_grade';

View file

@ -60,8 +60,9 @@ class element extends \mod_customcert\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 function render($pdf, $preview) {
public function render($pdf, $preview, $user) {
global $DB;
// Check that the grade item is not empty.

View file

@ -24,6 +24,6 @@
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
$plugin->version = 2016021900; // The current module version (Date: YYYYMMDDXX).
$plugin->version = 2016032201; // The current module version (Date: YYYYMMDDXX).
$plugin->requires = 2015051100; // Requires this Moodle version (2.9).
$plugin->component = 'customcertelement_gradeitemname';

View file

@ -101,10 +101,17 @@ class element extends \mod_customcert\element {
* @param \stdClass $data the form data
*/
public function save_form_elements($data) {
global $COURSE;
global $COURSE, $SITE;
// Set the context.
if ($COURSE->id == $SITE->id) {
$context = \context_system::instance();
} else {
$context = \context_course::instance($COURSE->id);
}
// Handle file uploads.
\mod_customcert\certificate::upload_imagefiles($data->customcertimage, \context_course::instance($COURSE->id)->id);
\mod_customcert\certificate::upload_imagefiles($data->customcertimage, $context->id);
parent::save_form_elements($data);
}
@ -132,8 +139,9 @@ class element extends \mod_customcert\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 function render($pdf, $preview) {
public function render($pdf, $preview, $user) {
global $CFG;
// If there is no element data, we have nothing to display.
@ -205,7 +213,7 @@ class element extends \mod_customcert\element {
* @param \mod_customcert\edit_element_form $mform the edit_form instance
*/
public function definition_after_data($mform) {
global $COURSE;
global $COURSE, $SITE;
// Set the image, width and height for this element.
if (!empty($this->element->data)) {
@ -215,9 +223,17 @@ class element extends \mod_customcert\element {
$this->element->height = $imageinfo->height;
}
// Set the context.
if ($COURSE->id == $SITE->id) {
$context = \context_system::instance();
} else {
$context = \context_course::instance($COURSE->id);
}
// Editing existing instance - copy existing files into draft area.
$draftitemid = file_get_submitted_draft_itemid('customcertimage');
file_prepare_draft_area($draftitemid, \context_course::instance($COURSE->id)->id, 'mod_customcert', 'image', 0, $this->filemanageroptions);
file_prepare_draft_area($draftitemid, $context->id, 'mod_customcert', 'image', 0, $this->filemanageroptions);
$element = $mform->getElement('customcertimage');
$element->setValue($draftitemid);

View file

@ -24,6 +24,6 @@
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
$plugin->version = 2016021900; // The current module version (Date: YYYYMMDDXX).
$plugin->version = 2016032201; // The current module version (Date: YYYYMMDDXX).
$plugin->requires = 2015051100; // Requires this Moodle version (2.9).
$plugin->component = 'customcertelement_image';

View file

@ -32,11 +32,10 @@ class element extends \mod_customcert\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 function render($pdf, $preview) {
global $USER;
\mod_customcert\element_helper::render_content($pdf, $this, fullname($USER));
public function render($pdf, $preview, $user) {
\mod_customcert\element_helper::render_content($pdf, $this, fullname($user));
}
/**

View file

@ -24,6 +24,6 @@
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
$plugin->version = 2016021900; // The current module version (Date: YYYYMMDDXX).
$plugin->version = 2016032201; // The current module version (Date: YYYYMMDDXX).
$plugin->requires = 2015051100; // Requires this Moodle version (2.9).
$plugin->component = 'customcertelement_studentname';

View file

@ -58,8 +58,9 @@ class element extends \mod_customcert\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 function render($pdf, $preview) {
public function render($pdf, $preview, $user) {
global $DB;
$teacher = $DB->get_record('user', array('id' => $this->element->data));

View file

@ -24,6 +24,6 @@
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
$plugin->version = 2016021900; // The current module version (Date: YYYYMMDDXX).
$plugin->version = 2016032201; // The current module version (Date: YYYYMMDDXX).
$plugin->requires = 2015051100; // Requires this Moodle version (2.9).
$plugin->component = 'customcertelement_teachername';

View file

@ -56,8 +56,9 @@ class element extends \mod_customcert\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 function render($pdf, $preview) {
public function render($pdf, $preview, $user) {
\mod_customcert\element_helper::render_content($pdf, $this, $this->element->data);
}

View file

@ -24,6 +24,6 @@
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
$plugin->version = 2016021900; // The current module version (Date: YYYYMMDDXX).
$plugin->version = 2016032201; // The current module version (Date: YYYYMMDDXX).
$plugin->requires = 2015051100; // Requires this Moodle version (2.9).
$plugin->component = 'customcertelement_text';

View file

@ -87,9 +87,10 @@ class element extends \mod_customcert\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 function render($pdf, $preview) {
global $DB, $USER;
public function render($pdf, $preview, $user) {
global $CFG, $DB;
// The user field to display.
$field = $this->element->data;
@ -97,10 +98,17 @@ class element extends \mod_customcert\element {
$value = '';
if (is_number($field)) { // Must be a custom user profile 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);
@ -113,15 +121,27 @@ class element extends \mod_customcert\element {
* drag and drop interface to position it.
*/
public function render_html() {
global $DB, $USER;
global $CFG, $DB, $USER;
// The user field to display.
$field = $this->element->data;
// The value to display on the PDF.
$value = '';
// The value to display - we always want to show a value here so it can be repositioned.
$value = $field;
if (is_number($field)) { // Must be a custom user profile field.
if ($field = $DB->get_record('user_info_field', array('id' => $field))) {
$value = $USER->profile[$field->shortname];
// Found the field name, let's update the value to display.
$value = $field->name;
$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);
if ($fieldvalue = $field->display_data()) {
// Ok, found a value for the user, let's show that instead.
$value = $fieldvalue;
}
}
}
} else if (!empty($USER->$field)) { // Field in the user table.
$value = $USER->$field;

View file

@ -24,6 +24,6 @@
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
$plugin->version = 2016021900; // The current module version (Date: YYYYMMDDXX).
$plugin->version = 2016032201; // The current module version (Date: YYYYMMDDXX).
$plugin->requires = 2015051100; // Requires this Moodle version (2.9).
$plugin->component = 'customcertelement_userfield';

View file

@ -33,7 +33,7 @@ require_login($course);
// Set up the page variables.
$pageurl = new moodle_url('/mod/customcert/index.php', array('id' => $course->id));
\mod_customcert\page_helper::page_setup($pageurl, CONTEXT_COURSE::instance($id),
\mod_customcert\page_helper::page_setup($pageurl, context_course::instance($id),
get_string('modulenameplural', 'customcert'));
// Additional page setup needed.

View file

@ -31,7 +31,6 @@ $string['coursetimereq'] = 'Required minutes in course';
$string['coursetimereq_help'] = 'Enter here the minimum amount of time, in minutes, that a student must be logged into the course before they will be able to receive
the certificate.';
$string['createtemplate'] = 'Create template';
$string['customcertnameexists'] = 'A certificate already exists with this name';
$string['customcertreport'] = 'Custom certificate report';
$string['customcert:addinstance'] = 'Add a new custom certificate instance';
$string['customcert:manage'] = 'Manage a custom certificate';
@ -50,7 +49,9 @@ $string['elementname'] = 'Element name';
$string['elementname_help'] = 'This will be the name used to identify this element when editing a custom certificate. For example, you may have multiple images on a
page and will want to distinguish between them quickly when editing the certificate. Note: this will not displayed on the PDF.';
$string['elements'] = 'Elements';
$string['elements_help'] = 'These are the list of elements that will be displayed on this PDF page.';
$string['elements_help'] = 'This is the list of elements that will be displayed on the certificate.
Please note: The elements are rendered in this order. The order can be changed by using the arrows next to each element.';
$string['elementwidth'] = 'Width';
$string['elementwidth_help'] = 'Specify the width of the element - \'0\' means that there is no width constraint.';
$string['font'] = 'Font';
@ -93,11 +94,11 @@ $string['pluginadministration'] = 'Custom certificate administration';
$string['pluginname'] = 'Custom certificate';
$string['print'] = 'Print';
$string['portrait'] = 'Portrait';
$string['rearrangeelements'] = 'Rearrange elements';
$string['rearrangeelements'] = 'Reposition elements';
$string['rearrangeelementsheading'] = 'Drag and drop elements to change where they are positioned on the certificate.';
$string['receiveddate'] = 'Received date';
$string['refpoint'] = 'Reference point location';
$string['refpoint_help'] = 'This specifies which location of the element to be located at position X and position Y.';
$string['refpoint_help'] = 'The reference point is the location of an element from which its x and y coordinates are determined. It is indicated by the \'+\' that appears in the centre or corners of the element.';
$string['replacetemplate'] = 'Replace';
$string['rightmargin'] = 'Right margin';
$string['rightmargin_help'] = 'This is the right margin of the certificate PDF in mm.';

View file

@ -234,7 +234,7 @@ function customcert_pluginfile($course, $cm, $context, $filearea, $args, $forced
if ($filearea === 'image') {
if ($context->contextlevel == CONTEXT_MODULE) {
require_login($course, false, $cm);
} else if ($context->contextlevel == CONTEXT_SYSTEM && !has_capability('mod/certificate:manage', $context)) {
} else if ($context->contextlevel == CONTEXT_SYSTEM && !has_capability('mod/customcert:manage', $context)) {
return false;
}

View file

@ -24,7 +24,7 @@
require_once('../../config.php');
$contextid = optional_param('contextid', CONTEXT_SYSTEM::instance()->id, PARAM_INT);
$contextid = optional_param('contextid', context_system::instance()->id, PARAM_INT);
$action = optional_param('action', '', PARAM_ALPHA);
$confirm = optional_param('confirm', 0, PARAM_INT);

View file

@ -46,6 +46,19 @@ $template->require_manage();
$pageurl = new moodle_url('/mod/customcert/rearrange.php', array('pid' => $pid));
\mod_customcert\page_helper::page_setup($pageurl, $template->get_context(), get_string('rearrangeelements', 'customcert'));
// Add more links to the navigation.
if (!$cm = $template->get_cm()) {
$str = get_string('managetemplates', 'customcert');
$link = new moodle_url('/mod/customcert/manage_templates.php');
$PAGE->navbar->add($str, new \action_link($link, $str));
}
$str = get_string('editcustomcert', 'customcert');
$link = new moodle_url('/mod/customcert/edit.php', array('tid' => $template->get_id()));
$PAGE->navbar->add($str, new \action_link($link, $str));
$PAGE->navbar->add(get_string('rearrangeelements', 'customcert'));
// Include the JS we need.
$PAGE->requires->yui_module('moodle-mod_customcert-rearrange', 'M.mod_customcert.rearrange.init',
array($template->get_id(),

View file

@ -25,20 +25,16 @@
require_once('../../config.php');
$id = required_param('id', PARAM_INT);
$download = optional_param('download', '', PARAM_ALPHA);
$download = optional_param('download', null, PARAM_ALPHA);
$downloadcert = optional_param('downloadcert', '', PARAM_BOOL);
if ($downloadcert) {
$userid = required_param('userid', PARAM_INT);
}
$page = optional_param('page', 0, PARAM_INT);
$perpage = optional_param('perpage', \mod_customcert\certificate::CUSTOMCERT_PER_PAGE, PARAM_INT);
$pageurl = $url = new moodle_url('/mod/customcert/report.php', array('id' => $id, 'page' => $page, 'perpage' => $perpage));
// Ensure the perpage variable does not exceed the max allowed if
// the user has not specified they wish to view all customcerts.
if (\mod_customcert\certificate::CUSTOMCERT_PER_PAGE !== 0) {
if (($perpage > \mod_customcert\certificate::CUSTOMCERT_MAX_PER_PAGE) || ($perpage === 0)) {
$perpage = \mod_customcert\certificate::CUSTOMCERT_PER_PAGE;
}
}
$cm = get_coursemodule_from_id('customcert', $id, 0, false, MUST_EXIST);
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
$customcert = $DB->get_record('customcert', array('id' => $cm->instance), '*', MUST_EXIST);
@ -50,37 +46,27 @@ require_login($course, false, $cm);
$context = context_module::instance($cm->id);
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)) {
groups_get_activity_group($cm, true);
}
$users = \mod_customcert\certificate::get_issues($customcert->id, $groupmode, $cm, $page, $perpage);
if ($download) {
\mod_customcert\certificate::generate_report_file($customcert, $users, $download);
exit;
$table = new \mod_customcert\report_table($customcert->id, $cm, $groupmode, $download);
$table->define_baseurl($pageurl);
if ($table->is_downloading()) {
$table->download();
exit();
}
// Create the table for the users.
$table = new html_table();
$table->attributes['class'] = 'generaltable centre';
$table->attributes['style'] = 'width: 95%;';
$table->head = array(get_string('awardedto', 'customcert'), get_string('receiveddate', 'customcert'), get_string('code', 'customcert'));
$table->align = array('left', 'left', 'center');
foreach ($users as $user) {
$name = $OUTPUT->user_picture($user) . fullname($user);
$date = userdate($user->timecreated);
$code = $user->code;
$table->data[] = array($name, $date, $code);
}
// Create table to store buttons.
$tablebutton = new html_table();
$tablebutton->attributes['class'] = 'centre';
$btndownloadods = $OUTPUT->single_button(new moodle_url('report.php', array('id' => $cm->id, 'download' => 'ods')), get_string("downloadods"));
$btndownloadxls = $OUTPUT->single_button(new moodle_url('report.php', array('id' => $cm->id, 'download' => 'xls')), get_string("downloadexcel"));
$tablebutton->data[] = array($btndownloadods, $btndownloadxls);
// Set up the page.
\mod_customcert\page_helper::page_setup($pageurl, $context, get_string('customcertreport', 'customcert'));
@ -89,12 +75,9 @@ $PAGE->navbar->add(get_string('customcertreport', 'customcert'));
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('modulenameplural', 'customcert'));
groups_print_activity_menu($cm, $url);
// If perpage is not set to 0 (displaying all issues), we may need a paging bar.
if ($perpage !== 0) {
echo $OUTPUT->paging_bar(count((array) $users), $page, $perpage, $url);
}
echo '<br />';
echo html_writer::table($table);
echo html_writer::tag('div', html_writer::table($tablebutton), array('style' => 'margin:auto; width:50%'));
$table->out($perpage, false);
echo $OUTPUT->footer($course);

View file

@ -24,10 +24,10 @@
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
$plugin->version = 2016032200; // The current module version (Date: YYYYMMDDXX).
$plugin->version = 2016032202; // The current module version (Date: YYYYMMDDXX).
$plugin->requires = 2015051100; // Requires this Moodle version (2.9).
$plugin->cron = 0; // Period for cron to check this module (secs).
$plugin->component = 'mod_customcert';
$plugin->maturity = MATURITY_BETA;
$plugin->release = "Beta release (Build: 2016021900)"; // User-friendly version number.
$plugin->maturity = MATURITY_STABLE;
$plugin->release = "Stable 2.9/3.0 release (Build: 2016032201)"; // User-friendly version number.

View file

@ -42,7 +42,7 @@ $pageurl = new moodle_url('/mod/customcert/view.php', array('id' => $cm->id));
\mod_customcert\page_helper::page_setup($pageurl, $context, format_string($customcert->name));
// Check if the user can view the certificate based on time spent in course.
if ($customcert->requiredtime && !has_capability('mod/certificate:manage', $context)) {
if ($customcert->requiredtime && !has_capability('mod/customcert:manage', $context)) {
if (\mod_customcert\certificate::get_course_time($course->id) < ($customcert->requiredtime * 60)) {
$a = new stdClass;
$a->requiredtime = $customcert->requiredtime;
@ -122,6 +122,11 @@ if (empty($action)) {
// Insert the record into the database.
$DB->insert_record('customcert_issues', $customcertissue);
}
// Set the custom certificate as viewed.
$completion = new completion_info($course);
$completion->set_module_viewed($cm);
// Now we want to generate the PDF.
$template = new \mod_customcert\template($template);
$template->generate_pdf();