Compare commits
26 commits
main
...
MOODLE_29_
Author | SHA1 | Date | |
---|---|---|---|
|
a98a860e3a | ||
|
3e638fbeb6 | ||
|
6fffb1a89a | ||
|
583368656e | ||
|
39284f7891 | ||
|
40c4cffa38 | ||
|
dab7ebfeb5 | ||
|
e5d523de91 | ||
|
e7d5cbca6e | ||
|
9224b057f7 | ||
|
e5f5e4297a | ||
|
88b7a7839b | ||
|
c1ac1b9e43 | ||
|
e4db1591dd | ||
|
787746e4a8 | ||
|
c6540b1cd9 | ||
|
1eada36b1f | ||
|
571052e1aa | ||
|
6d28a15851 | ||
|
d6ebc95c77 | ||
|
0f77856e90 | ||
|
fdb0609990 | ||
|
92fda00268 | ||
|
8e23e39bcd | ||
|
986badd1e9 | ||
|
a3fb3a7af4 |
44 changed files with 608 additions and 213 deletions
25
README.md
25
README.md
|
@ -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.
|
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.
|
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"
|
|
@ -52,12 +52,7 @@ class certificate {
|
||||||
* @var int the number of issues that will be displayed on each page in the report
|
* @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.
|
* If you want to display all customcerts on a page set this to 0.
|
||||||
*/
|
*/
|
||||||
const CUSTOMCERT_PER_PAGE = '20';
|
const CUSTOMCERT_PER_PAGE = '50';
|
||||||
|
|
||||||
/**
|
|
||||||
* @var int the max number of issues to display
|
|
||||||
*/
|
|
||||||
const CUSTOMCERT_MAX_PER_PAGE = '300';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles setting the protection field for the customcert
|
* Handles setting the protection field for the customcert
|
||||||
|
@ -233,11 +228,12 @@ class certificate {
|
||||||
* @param int $customcertid
|
* @param int $customcertid
|
||||||
* @param bool $groupmode are we in group mode
|
* @param bool $groupmode are we in group mode
|
||||||
* @param \stdClass $cm the course module
|
* @param \stdClass $cm the course module
|
||||||
* @param int $page offset
|
* @param int $limitfrom
|
||||||
* @param int $perpage total per page
|
* @param int $limitnum
|
||||||
|
* @param string $sort
|
||||||
* @return \stdClass the users
|
* @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;
|
global $DB;
|
||||||
|
|
||||||
// Get the conditional SQL.
|
// Get the conditional SQL.
|
||||||
|
@ -252,15 +248,21 @@ class certificate {
|
||||||
$allparams = $conditionsparams + array('customcertid' => $customcertid);
|
$allparams = $conditionsparams + array('customcertid' => $customcertid);
|
||||||
|
|
||||||
// Return the issues.
|
// 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
|
FROM {user} u
|
||||||
INNER JOIN {customcert_issues} ci
|
INNER JOIN {customcert_issues} ci
|
||||||
ON u.id = ci.userid
|
ON u.id = ci.userid
|
||||||
WHERE u.deleted = 0
|
WHERE u.deleted = 0
|
||||||
AND ci.customcertid = :customcertid
|
AND ci.customcertid = :customcertid
|
||||||
$conditionssql
|
$conditionssql";
|
||||||
ORDER BY " . $DB->sql_fullname();
|
if ($sort) {
|
||||||
return $DB->get_records_sql($sql, $allparams, $page * $perpage, $perpage);
|
$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();
|
$conditionsparams = array();
|
||||||
|
|
||||||
// Get all users that can manage this certificate to exclude them from the report.
|
// 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()));
|
$certmanagers = array_merge($certmanagers, array_keys(get_admins()));
|
||||||
list($sql, $params) = $DB->get_in_or_equal($certmanagers, SQL_PARAMS_NAMED, 'cert');
|
list($sql, $params) = $DB->get_in_or_equal($certmanagers, SQL_PARAMS_NAMED, 'cert');
|
||||||
$conditionssql .= "AND NOT u.id $sql \n";
|
$conditionssql .= "AND NOT u.id $sql \n";
|
||||||
|
@ -379,62 +381,4 @@ class certificate {
|
||||||
|
|
||||||
return $code;
|
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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -128,17 +128,8 @@ class edit_form extends \moodleform {
|
||||||
* @return array the errors that were found
|
* @return array the errors that were found
|
||||||
*/
|
*/
|
||||||
public function validation($data, $files) {
|
public function validation($data, $files) {
|
||||||
global $DB;
|
|
||||||
|
|
||||||
$errors = parent::validation($data, $files);
|
$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.
|
// Go through the data and check any width, height or margin values.
|
||||||
foreach ($data as $key => $value) {
|
foreach ($data as $key => $value) {
|
||||||
if (strpos($key, 'pagewidth_') !== false) {
|
if (strpos($key, 'pagewidth_') !== false) {
|
||||||
|
@ -240,12 +231,7 @@ class edit_form extends \moodleform {
|
||||||
// Create a table to display these elements.
|
// Create a table to display these elements.
|
||||||
$table = new \html_table();
|
$table = new \html_table();
|
||||||
$table->head = array(get_string('name', 'customcert'), get_string('type', 'customcert'), '');
|
$table->head = array(get_string('name', 'customcert'), get_string('type', 'customcert'), '');
|
||||||
$table->align = array('left', 'left', 'center');
|
$table->align = array('left', 'left', 'left');
|
||||||
// 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';
|
|
||||||
}
|
|
||||||
// Loop through and add the elements to the table.
|
// Loop through and add the elements to the table.
|
||||||
foreach ($elements as $element) {
|
foreach ($elements as $element) {
|
||||||
$row = new \html_table_row();
|
$row = new \html_table_row();
|
||||||
|
|
|
@ -159,8 +159,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.
|
||||||
|
|
|
@ -38,15 +38,29 @@ class load_template_form extends \moodleform {
|
||||||
|
|
||||||
$mform =& $this->_form;
|
$mform =& $this->_form;
|
||||||
|
|
||||||
|
// Get the context.
|
||||||
|
$context = $this->_customdata['context'];
|
||||||
|
|
||||||
$mform->addElement('header', 'loadtemplateheader', get_string('loadtemplate', 'customcert'));
|
$mform->addElement('header', 'loadtemplateheader', get_string('loadtemplate', 'customcert'));
|
||||||
|
|
||||||
$templates = $DB->get_records_menu('customcert_templates',
|
// Display a link to the manage templates page.
|
||||||
array('contextid' => \CONTEXT_SYSTEM::instance()->id), 'name ASC', 'id, name');
|
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 = array();
|
||||||
$group[] = $mform->createElement('select', 'ltid', '', $templates);
|
$group[] = $mform->createElement('select', 'ltid', '', $templates);
|
||||||
$group[] = $mform->createElement('submit', 'loadtemplatesubmit', get_string('load', 'customcert'));
|
$group[] = $mform->createElement('submit', 'loadtemplatesubmit', get_string('load', 'customcert'));
|
||||||
$mform->addElement('group', 'loadtemplategroup', '', $group, '', false);
|
$mform->addElement('group', 'loadtemplategroup', '', $group, '', false);
|
||||||
$mform->setType('ltid', PARAM_INT);
|
$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
182
classes/report_table.php
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -146,7 +146,7 @@ class template {
|
||||||
* @return bool return true if the deletion was successful, false otherwise
|
* @return bool return true if the deletion was successful, false otherwise
|
||||||
*/
|
*/
|
||||||
public function delete() {
|
public function delete() {
|
||||||
global $CFG, $DB;
|
global $DB;
|
||||||
|
|
||||||
// Delete the elements.
|
// Delete the elements.
|
||||||
$sql = "SELECT e.*
|
$sql = "SELECT e.*
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -322,8 +329,15 @@ class template {
|
||||||
} else { // Must be down.
|
} else { // Must be down.
|
||||||
$sequence = $moveitem->sequence + 1;
|
$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.
|
// Check that there is an item to move, and an item to swap it with.
|
||||||
|
|
9
edit.php
9
edit.php
|
@ -66,11 +66,6 @@ if ($context->contextlevel == CONTEXT_SYSTEM) {
|
||||||
$PAGE->navbar->add(get_string('editcustomcert', 'customcert'));
|
$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.
|
// Flag to determine if we are deleting anything.
|
||||||
$deleting = false;
|
$deleting = false;
|
||||||
|
@ -225,7 +220,9 @@ if ($data = $mform->get_data()) {
|
||||||
echo $OUTPUT->header();
|
echo $OUTPUT->header();
|
||||||
echo $OUTPUT->heading(get_string('editcustomcert', 'customcert'));
|
echo $OUTPUT->heading(get_string('editcustomcert', 'customcert'));
|
||||||
$mform->display();
|
$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();
|
$loadtemplateform->display();
|
||||||
}
|
}
|
||||||
echo $OUTPUT->footer();
|
echo $OUTPUT->footer();
|
||||||
|
|
132
element/bgimage/classes/element.php
Normal file
132
element/bgimage/classes/element.php
Normal 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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
25
element/bgimage/lang/en/customcertelement_bgimage.php
Normal file
25
element/bgimage/lang/en/customcertelement_bgimage.php
Normal 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';
|
29
element/bgimage/version.php
Normal file
29
element/bgimage/version.php
Normal 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';
|
|
@ -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);
|
||||||
|
|
|
@ -24,6 +24,6 @@
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
|
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->requires = 2015051100; // Requires this Moodle version (2.9).
|
||||||
$plugin->component = 'customcertelement_border';
|
$plugin->component = 'customcertelement_border';
|
||||||
|
|
|
@ -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());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,6 @@
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
|
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->requires = 2015051100; // Requires this Moodle version (2.9).
|
||||||
$plugin->component = 'customcertelement_categoryname';
|
$plugin->component = 'customcertelement_categoryname';
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,6 @@
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
|
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->requires = 2015051100; // Requires this Moodle version (2.9).
|
||||||
$plugin->component = 'customcertelement_code';
|
$plugin->component = 'customcertelement_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);
|
||||||
|
|
|
@ -24,6 +24,6 @@
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
|
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->requires = 2015051100; // Requires this Moodle version (2.9).
|
||||||
$plugin->component = 'customcertelement_coursename';
|
$plugin->component = 'customcertelement_coursename';
|
||||||
|
|
|
@ -21,12 +21,12 @@ defined('MOODLE_INTERNAL') || die();
|
||||||
/**
|
/**
|
||||||
* Date - Issue
|
* Date - Issue
|
||||||
*/
|
*/
|
||||||
define('CUSTOMCERT_DATE_ISSUE', '1');
|
define('CUSTOMCERT_DATE_ISSUE', '-1');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Date - Completion
|
* Date - Completion
|
||||||
*/
|
*/
|
||||||
define('CUSTOMCERT_DATE_COMPLETION', '2');
|
define('CUSTOMCERT_DATE_COMPLETION', '-2');
|
||||||
|
|
||||||
require_once($CFG->dirroot . '/lib/grade/constants.php');
|
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 \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;
|
||||||
|
@ -251,11 +252,11 @@ class element extends \mod_customcert\element {
|
||||||
switch ($day % 10) {
|
switch ($day % 10) {
|
||||||
// Handle 1st, 2nd, 3rd.
|
// Handle 1st, 2nd, 3rd.
|
||||||
case 1:
|
case 1:
|
||||||
return get_string('numbersuffix_st', 'customcertelement_date');
|
return get_string('numbersuffix_st_as_in_first', 'customcertelement_date');
|
||||||
case 2:
|
case 2:
|
||||||
return get_string('numbersuffix_nd', 'customcertelement_date');
|
return get_string('numbersuffix_nd_as_in_second', 'customcertelement_date');
|
||||||
case 3:
|
case 3:
|
||||||
return get_string('numbersuffix_rd', 'customcertelement_date');
|
return get_string('numbersuffix_rd_as_in_third', 'customcertelement_date');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 'th';
|
return 'th';
|
||||||
|
|
|
@ -29,7 +29,7 @@ $string['dateitem'] = 'Date item';
|
||||||
$string['dateitem_help'] = 'This will be the date that is printed on the certificate';
|
$string['dateitem_help'] = 'This will be the date that is printed on the certificate';
|
||||||
$string['issueddate'] = 'Issued date';
|
$string['issueddate'] = 'Issued date';
|
||||||
$string['pluginname'] = 'Date';
|
$string['pluginname'] = 'Date';
|
||||||
$string['numbersuffix_nd'] = 'nd';
|
$string['numbersuffix_nd_as_in_second'] = 'nd';
|
||||||
$string['numbersuffix_rd'] = 'rd';
|
$string['numbersuffix_rd_as_in_third'] = 'rd';
|
||||||
$string['numbersuffix_st'] = 'st';
|
$string['numbersuffix_st_as_in_first'] = 'st';
|
||||||
$string['userdateformat'] = 'User date format';
|
$string['userdateformat'] = 'User date format';
|
||||||
|
|
|
@ -24,6 +24,6 @@
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
|
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->requires = 2015051100; // Requires this Moodle version (2.9).
|
||||||
$plugin->component = 'customcertelement_date';
|
$plugin->component = 'customcertelement_date';
|
||||||
|
|
|
@ -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);
|
||||||
|
|
|
@ -24,6 +24,6 @@
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
|
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->requires = 2015051100; // Requires this Moodle version (2.9).
|
||||||
$plugin->component = 'customcertelement_grade';
|
$plugin->component = 'customcertelement_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.
|
||||||
|
|
|
@ -24,6 +24,6 @@
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
|
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->requires = 2015051100; // Requires this Moodle version (2.9).
|
||||||
$plugin->component = 'customcertelement_gradeitemname';
|
$plugin->component = 'customcertelement_gradeitemname';
|
||||||
|
|
|
@ -101,10 +101,17 @@ class element extends \mod_customcert\element {
|
||||||
* @param \stdClass $data the form data
|
* @param \stdClass $data the form data
|
||||||
*/
|
*/
|
||||||
public function save_form_elements($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.
|
// 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);
|
parent::save_form_elements($data);
|
||||||
}
|
}
|
||||||
|
@ -132,8 +139,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.
|
||||||
|
@ -205,7 +213,7 @@ class element extends \mod_customcert\element {
|
||||||
* @param \mod_customcert\edit_element_form $mform the edit_form instance
|
* @param \mod_customcert\edit_element_form $mform the edit_form instance
|
||||||
*/
|
*/
|
||||||
public function definition_after_data($mform) {
|
public function definition_after_data($mform) {
|
||||||
global $COURSE;
|
global $COURSE, $SITE;
|
||||||
|
|
||||||
// Set the image, width and height for this element.
|
// Set the image, width and height for this element.
|
||||||
if (!empty($this->element->data)) {
|
if (!empty($this->element->data)) {
|
||||||
|
@ -215,9 +223,17 @@ class element extends \mod_customcert\element {
|
||||||
$this->element->height = $imageinfo->height;
|
$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.
|
// Editing existing instance - copy existing files into draft area.
|
||||||
$draftitemid = file_get_submitted_draft_itemid('customcertimage');
|
$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 = $mform->getElement('customcertimage');
|
||||||
$element->setValue($draftitemid);
|
$element->setValue($draftitemid);
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,6 @@
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
|
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->requires = 2015051100; // Requires this Moodle version (2.9).
|
||||||
$plugin->component = 'customcertelement_image';
|
$plugin->component = 'customcertelement_image';
|
||||||
|
|
|
@ -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));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -24,6 +24,6 @@
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
|
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->requires = 2015051100; // Requires this Moodle version (2.9).
|
||||||
$plugin->component = 'customcertelement_studentname';
|
$plugin->component = 'customcertelement_studentname';
|
||||||
|
|
|
@ -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));
|
||||||
|
|
|
@ -24,6 +24,6 @@
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
|
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->requires = 2015051100; // Requires this Moodle version (2.9).
|
||||||
$plugin->component = 'customcertelement_teachername';
|
$plugin->component = 'customcertelement_teachername';
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,6 @@
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
|
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->requires = 2015051100; // Requires this Moodle version (2.9).
|
||||||
$plugin->component = 'customcertelement_text';
|
$plugin->component = 'customcertelement_text';
|
||||||
|
|
|
@ -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);
|
||||||
|
@ -113,15 +121,27 @@ class element extends \mod_customcert\element {
|
||||||
* drag and drop interface to position it.
|
* drag and drop interface to position it.
|
||||||
*/
|
*/
|
||||||
public function render_html() {
|
public function render_html() {
|
||||||
global $DB, $USER;
|
global $CFG, $DB, $USER;
|
||||||
|
|
||||||
// The user field to display.
|
// The user field to display.
|
||||||
$field = $this->element->data;
|
$field = $this->element->data;
|
||||||
// The value to display on the PDF.
|
// The value to display - we always want to show a value here so it can be repositioned.
|
||||||
$value = '';
|
$value = $field;
|
||||||
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];
|
// 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.
|
} else if (!empty($USER->$field)) { // Field in the user table.
|
||||||
$value = $USER->$field;
|
$value = $USER->$field;
|
||||||
|
|
|
@ -24,6 +24,6 @@
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
|
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->requires = 2015051100; // Requires this Moodle version (2.9).
|
||||||
$plugin->component = 'customcertelement_userfield';
|
$plugin->component = 'customcertelement_userfield';
|
||||||
|
|
|
@ -33,7 +33,7 @@ require_login($course);
|
||||||
|
|
||||||
// Set up the page variables.
|
// Set up the page variables.
|
||||||
$pageurl = new moodle_url('/mod/customcert/index.php', array('id' => $course->id));
|
$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'));
|
get_string('modulenameplural', 'customcert'));
|
||||||
|
|
||||||
// Additional page setup needed.
|
// Additional page setup needed.
|
||||||
|
|
|
@ -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
|
$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.';
|
the certificate.';
|
||||||
$string['createtemplate'] = 'Create template';
|
$string['createtemplate'] = 'Create template';
|
||||||
$string['customcertnameexists'] = 'A certificate already exists with this name';
|
|
||||||
$string['customcertreport'] = 'Custom certificate report';
|
$string['customcertreport'] = 'Custom certificate report';
|
||||||
$string['customcert:addinstance'] = 'Add a new custom certificate instance';
|
$string['customcert:addinstance'] = 'Add a new custom certificate instance';
|
||||||
$string['customcert:manage'] = 'Manage a custom certificate';
|
$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
|
$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.';
|
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'] = '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'] = 'Width';
|
||||||
$string['elementwidth_help'] = 'Specify the width of the element - \'0\' means that there is no width constraint.';
|
$string['elementwidth_help'] = 'Specify the width of the element - \'0\' means that there is no width constraint.';
|
||||||
$string['font'] = 'Font';
|
$string['font'] = 'Font';
|
||||||
|
@ -93,11 +94,11 @@ $string['pluginadministration'] = 'Custom certificate administration';
|
||||||
$string['pluginname'] = 'Custom certificate';
|
$string['pluginname'] = 'Custom certificate';
|
||||||
$string['print'] = 'Print';
|
$string['print'] = 'Print';
|
||||||
$string['portrait'] = 'Portrait';
|
$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['rearrangeelementsheading'] = 'Drag and drop elements to change where they are positioned on the certificate.';
|
||||||
$string['receiveddate'] = 'Received date';
|
$string['receiveddate'] = 'Received date';
|
||||||
$string['refpoint'] = 'Reference point location';
|
$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['replacetemplate'] = 'Replace';
|
||||||
$string['rightmargin'] = 'Right margin';
|
$string['rightmargin'] = 'Right margin';
|
||||||
$string['rightmargin_help'] = 'This is the right margin of the certificate PDF in mm.';
|
$string['rightmargin_help'] = 'This is the right margin of the certificate PDF in mm.';
|
||||||
|
|
2
lib.php
2
lib.php
|
@ -234,7 +234,7 @@ function customcert_pluginfile($course, $cm, $context, $filearea, $args, $forced
|
||||||
if ($filearea === 'image') {
|
if ($filearea === 'image') {
|
||||||
if ($context->contextlevel == CONTEXT_MODULE) {
|
if ($context->contextlevel == CONTEXT_MODULE) {
|
||||||
require_login($course, false, $cm);
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
|
|
||||||
require_once('../../config.php');
|
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);
|
$action = optional_param('action', '', PARAM_ALPHA);
|
||||||
$confirm = optional_param('confirm', 0, PARAM_INT);
|
$confirm = optional_param('confirm', 0, PARAM_INT);
|
||||||
|
|
||||||
|
|
|
@ -46,6 +46,19 @@ $template->require_manage();
|
||||||
$pageurl = new moodle_url('/mod/customcert/rearrange.php', array('pid' => $pid));
|
$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'));
|
\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.
|
// Include the JS we need.
|
||||||
$PAGE->requires->yui_module('moodle-mod_customcert-rearrange', 'M.mod_customcert.rearrange.init',
|
$PAGE->requires->yui_module('moodle-mod_customcert-rearrange', 'M.mod_customcert.rearrange.init',
|
||||||
array($template->get_id(),
|
array($template->get_id(),
|
||||||
|
|
65
report.php
65
report.php
|
@ -25,20 +25,16 @@
|
||||||
require_once('../../config.php');
|
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', null, 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);
|
||||||
$pageurl = $url = new moodle_url('/mod/customcert/report.php', array('id' => $id, 'page' => $page, 'perpage' => $perpage));
|
$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);
|
$cm = get_coursemodule_from_id('customcert', $id, 0, false, MUST_EXIST);
|
||||||
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
|
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
|
||||||
$customcert = $DB->get_record('customcert', array('id' => $cm->instance), '*', 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);
|
$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);
|
||||||
}
|
}
|
||||||
$users = \mod_customcert\certificate::get_issues($customcert->id, $groupmode, $cm, $page, $perpage);
|
|
||||||
|
|
||||||
if ($download) {
|
$table = new \mod_customcert\report_table($customcert->id, $cm, $groupmode, $download);
|
||||||
\mod_customcert\certificate::generate_report_file($customcert, $users, $download);
|
$table->define_baseurl($pageurl);
|
||||||
exit;
|
|
||||||
|
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.
|
// Set up the page.
|
||||||
\mod_customcert\page_helper::page_setup($pageurl, $context, get_string('customcertreport', 'customcert'));
|
\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->header();
|
||||||
echo $OUTPUT->heading(get_string('modulenameplural', 'customcert'));
|
echo $OUTPUT->heading(get_string('modulenameplural', 'customcert'));
|
||||||
|
|
||||||
groups_print_activity_menu($cm, $url);
|
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) {
|
$table->out($perpage, false);
|
||||||
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%'));
|
|
||||||
echo $OUTPUT->footer($course);
|
echo $OUTPUT->footer($course);
|
||||||
|
|
|
@ -24,10 +24,10 @@
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
|
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->requires = 2015051100; // Requires this Moodle version (2.9).
|
||||||
$plugin->cron = 0; // Period for cron to check this module (secs).
|
$plugin->cron = 0; // Period for cron to check this module (secs).
|
||||||
$plugin->component = 'mod_customcert';
|
$plugin->component = 'mod_customcert';
|
||||||
|
|
||||||
$plugin->maturity = MATURITY_BETA;
|
$plugin->maturity = MATURITY_STABLE;
|
||||||
$plugin->release = "Beta release (Build: 2016021900)"; // User-friendly version number.
|
$plugin->release = "Stable 2.9/3.0 release (Build: 2016032201)"; // User-friendly version number.
|
||||||
|
|
7
view.php
7
view.php
|
@ -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));
|
\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.
|
// 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)) {
|
if (\mod_customcert\certificate::get_course_time($course->id) < ($customcert->requiredtime * 60)) {
|
||||||
$a = new stdClass;
|
$a = new stdClass;
|
||||||
$a->requiredtime = $customcert->requiredtime;
|
$a->requiredtime = $customcert->requiredtime;
|
||||||
|
@ -122,6 +122,11 @@ if (empty($action)) {
|
||||||
// Insert the record into the database.
|
// Insert the record into the database.
|
||||||
$DB->insert_record('customcert_issues', $customcertissue);
|
$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.
|
// Now we want to generate the PDF.
|
||||||
$template = new \mod_customcert\template($template);
|
$template = new \mod_customcert\template($template);
|
||||||
$template->generate_pdf();
|
$template->generate_pdf();
|
||||||
|
|
Loading…
Reference in a new issue