Matheus Garcia
7 years ago
50 changed files with 3043 additions and 1562 deletions
@ -0,0 +1,72 @@ |
|||
<?php |
|||
|
|||
// This program 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. |
|||
// |
|||
// This program 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 this program. If not, see <http://www.gnu.org/licenses/>. |
|||
|
|||
/** |
|||
* Certificate module data generator. |
|||
* |
|||
* @package mod_certificate |
|||
* @copyright 2014 Totara Learning Solutions Ltd {@link http://www.totaralms.com/} |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
* @author Petr Skoda <petr.skoda@totaralms.com> |
|||
*/ |
|||
|
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
require_once($CFG->libdir.'/adminlib.php'); |
|||
|
|||
class mod_certificate_admin_setting_font extends admin_setting_configselect { |
|||
/** |
|||
* Constructor |
|||
* @param string $name unique ascii name, either 'mysetting' for settings that in config, or 'myplugin/mysetting' for ones in config_plugins. |
|||
* @param string $visiblename localised |
|||
* @param string $description long localised info |
|||
* @param string|int $defaultsetting |
|||
*/ |
|||
public function __construct($name, $visiblename, $description, $defaultsetting) { |
|||
parent::__construct($name, $visiblename, $description, $defaultsetting, null); |
|||
} |
|||
/** |
|||
* Lazy load the font options. |
|||
* |
|||
* @return bool true if loaded, false if error |
|||
*/ |
|||
public function load_choices() { |
|||
global $CFG; |
|||
|
|||
if (is_array($this->choices)) { |
|||
return true; |
|||
} |
|||
|
|||
require_once("$CFG->libdir/pdflib.php"); |
|||
|
|||
$doc = new pdf(); |
|||
|
|||
if (method_exists($doc, 'get_font_families')) { |
|||
$this->choices = array(); |
|||
$fontfamilies = $doc->get_font_families(); |
|||
foreach ($fontfamilies as $family => $fonts) { |
|||
$this->choices[$family] = $family; |
|||
} |
|||
|
|||
} else { |
|||
$this->choices = array( |
|||
'freeserif' => 'freeserif', |
|||
'freesans' => 'freesans', |
|||
); |
|||
} |
|||
|
|||
return true; |
|||
} |
|||
} |
@ -0,0 +1,46 @@ |
|||
<?php |
|||
|
|||
// This file is part of the Certificate 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/>. |
|||
|
|||
/** |
|||
* Creates an upload form on the settings page |
|||
* |
|||
* @package mod_certificate |
|||
* @copyright Michael Avelar <michaela@moodlerooms.com> |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
|
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
require_once($CFG->libdir.'/adminlib.php'); |
|||
|
|||
/** |
|||
* Class extends admin setting class to allow/process an uploaded file |
|||
**/ |
|||
class mod_certificate_admin_setting_upload extends admin_setting_configtext { |
|||
public function __construct($name, $visiblename, $description, $defaultsetting) { |
|||
parent::__construct($name, $visiblename, $description, $defaultsetting, PARAM_RAW, 50); |
|||
} |
|||
|
|||
function output_html($data, $query='') { |
|||
// Create a dummy var for this field. |
|||
$this->config_write($this->name, ''); |
|||
|
|||
return format_admin_setting($this, $this->visiblename, |
|||
html_writer::link(new moodle_url('/mod/certificate/upload_image.php'), get_string('upload')), |
|||
$this->description, true, '', null, $query); |
|||
} |
|||
} |
@ -0,0 +1,32 @@ |
|||
<?php |
|||
|
|||
// This file is part of the Certificate 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 page lists all the instances of certificate in a particular course |
|||
* |
|||
* @package mod |
|||
* @subpackage certificate |
|||
* @copyright Mark Nelson <markn@moodle.com> |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
|
|||
namespace mod_certificate\event; |
|||
|
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
class course_module_instance_list_viewed extends \core\event\course_module_instance_list_viewed { |
|||
} |
@ -0,0 +1,36 @@ |
|||
<?php |
|||
|
|||
// This file is part of the Certificate 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 page lists all the instances of certificate in a particular course |
|||
* |
|||
* @package mod |
|||
* @subpackage certificate |
|||
* @copyright Mark Nelson <markn@moodle.com> |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
|
|||
namespace mod_certificate\event; |
|||
|
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
class course_module_viewed extends \core\event\course_module_viewed { |
|||
protected function init() { |
|||
$this->data['objecttable'] = 'certificate'; |
|||
parent::init(); |
|||
} |
|||
} |
@ -0,0 +1,455 @@ |
|||
<?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/>. |
|||
|
|||
/** |
|||
* Certificate module external API |
|||
* |
|||
* @package mod_certificate |
|||
* @category external |
|||
* @copyright 2016 Juan Leyva <juan@moodle.com> |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
|
|||
defined('MOODLE_INTERNAL') || die; |
|||
|
|||
require_once($CFG->libdir . '/externallib.php'); |
|||
require_once($CFG->dirroot . '/mod/certificate/locallib.php'); |
|||
|
|||
/** |
|||
* Certificate module external functions |
|||
* |
|||
* @package mod_certificate |
|||
* @category external |
|||
* @copyright 2015 Juan Leyva <juan@moodle.com> |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
class mod_certificate_external extends external_api { |
|||
|
|||
/** |
|||
* Describes the parameters for get_certificates_by_courses. |
|||
* |
|||
* @return external_function_parameters |
|||
*/ |
|||
public static function get_certificates_by_courses_parameters() { |
|||
return new external_function_parameters ( |
|||
array( |
|||
'courseids' => new external_multiple_structure( |
|||
new external_value(PARAM_INT, 'course id'), 'Array of course ids', VALUE_DEFAULT, array() |
|||
), |
|||
) |
|||
); |
|||
} |
|||
|
|||
/** |
|||
* Returns a list of certificates in a provided list of courses, |
|||
* if no list is provided all certificates that the user can view will be returned. |
|||
* |
|||
* @param array $courseids the course ids |
|||
* @return array the certificate details |
|||
*/ |
|||
public static function get_certificates_by_courses($courseids = array()) { |
|||
global $CFG; |
|||
|
|||
$returnedcertificates = array(); |
|||
$warnings = array(); |
|||
|
|||
$params = self::validate_parameters(self::get_certificates_by_courses_parameters(), array('courseids' => $courseids)); |
|||
|
|||
if (empty($params['courseids'])) { |
|||
$params['courseids'] = array_keys(enrol_get_my_courses()); |
|||
} |
|||
|
|||
// Ensure there are courseids to loop through. |
|||
if (!empty($params['courseids'])) { |
|||
|
|||
list($courses, $warnings) = external_util::validate_courses($params['courseids']); |
|||
|
|||
// Get the certificates in this course, this function checks users visibility permissions. |
|||
// We can avoid then additional validate_context calls. |
|||
$certificates = get_all_instances_in_courses("certificate", $courses); |
|||
|
|||
foreach ($certificates as $certificate) { |
|||
|
|||
$context = context_module::instance($certificate->coursemodule); |
|||
|
|||
// Entry to return. |
|||
$module = array(); |
|||
|
|||
// First, we return information that any user can see in (or can deduce from) the web interface. |
|||
$module['id'] = $certificate->id; |
|||
$module['coursemodule'] = $certificate->coursemodule; |
|||
$module['course'] = $certificate->course; |
|||
$module['name'] = external_format_string($certificate->name, $context->id); |
|||
|
|||
$viewablefields = []; |
|||
if (has_capability('mod/certificate:view', $context)) { |
|||
list($module['intro'], $module['introformat']) = |
|||
external_format_text($certificate->intro, $certificate->introformat, $context->id, |
|||
'mod_certificate', 'intro', $certificate->id); |
|||
|
|||
// Check certificate requeriments for current user. |
|||
$viewablefields[] = 'requiredtime'; |
|||
$module['requiredtimenotmet'] = 0; |
|||
if ($certificate->requiredtime && !has_capability('mod/certificate:manage', $context)) { |
|||
if (certificate_get_course_time($certificate->course) < ($certificate->requiredtime * 60)) { |
|||
$module['requiredtimenotmet'] = 1; |
|||
} |
|||
} |
|||
} |
|||
|
|||
// Check additional permissions for returning optional private settings. |
|||
if (has_capability('moodle/course:manageactivities', $context)) { |
|||
|
|||
$additionalfields = array('emailteachers', 'emailothers', 'savecert', |
|||
'reportcert', 'delivery', 'certificatetype', 'orientation', 'borderstyle', 'bordercolor', |
|||
'printwmark', 'printdate', 'datefmt', 'printnumber', 'printgrade', 'gradefmt', 'printoutcome', |
|||
'printhours', 'printteacher', 'customtext', 'printsignature', 'printseal', 'timecreated', 'timemodified', |
|||
'section', 'visible', 'groupmode', 'groupingid'); |
|||
$viewablefields = array_merge($viewablefields, $additionalfields); |
|||
|
|||
} |
|||
|
|||
foreach ($viewablefields as $field) { |
|||
$module[$field] = $certificate->{$field}; |
|||
} |
|||
|
|||
$returnedcertificates[] = $module; |
|||
} |
|||
} |
|||
|
|||
$result = array(); |
|||
$result['certificates'] = $returnedcertificates; |
|||
$result['warnings'] = $warnings; |
|||
return $result; |
|||
} |
|||
|
|||
/** |
|||
* Describes the get_certificates_by_courses return value. |
|||
* |
|||
* @return external_single_structure |
|||
*/ |
|||
public static function get_certificates_by_courses_returns() { |
|||
|
|||
return new external_single_structure( |
|||
array( |
|||
'certificates' => new external_multiple_structure( |
|||
new external_single_structure( |
|||
array( |
|||
'id' => new external_value(PARAM_INT, 'Certificate id'), |
|||
'coursemodule' => new external_value(PARAM_INT, 'Course module id'), |
|||
'course' => new external_value(PARAM_INT, 'Course id'), |
|||
'name' => new external_value(PARAM_RAW, 'Certificate name'), |
|||
'intro' => new external_value(PARAM_RAW, 'The Certificate intro', VALUE_OPTIONAL), |
|||
'introformat' => new external_format_value('intro', VALUE_OPTIONAL), |
|||
'requiredtimenotmet' => new external_value(PARAM_INT, 'Whether the time req is met', VALUE_OPTIONAL), |
|||
'emailteachers' => new external_value(PARAM_INT, 'Email teachers?', VALUE_OPTIONAL), |
|||
'emailothers' => new external_value(PARAM_RAW, 'Email others?', VALUE_OPTIONAL), |
|||
'savecert' => new external_value(PARAM_INT, 'Save certificate?', VALUE_OPTIONAL), |
|||
'reportcert' => new external_value(PARAM_INT, 'Report certificate?', VALUE_OPTIONAL), |
|||
'delivery' => new external_value(PARAM_INT, 'Delivery options', VALUE_OPTIONAL), |
|||
'requiredtime' => new external_value(PARAM_INT, 'Required time', VALUE_OPTIONAL), |
|||
'certificatetype' => new external_value(PARAM_RAW, 'Type', VALUE_OPTIONAL), |
|||
'orientation' => new external_value(PARAM_ALPHANUM, 'Orientation', VALUE_OPTIONAL), |
|||
'borderstyle' => new external_value(PARAM_RAW, 'Border style', VALUE_OPTIONAL), |
|||
'bordercolor' => new external_value(PARAM_RAW, 'Border color', VALUE_OPTIONAL), |
|||
'printwmark' => new external_value(PARAM_RAW, 'Print water mark?', VALUE_OPTIONAL), |
|||
'printdate' => new external_value(PARAM_RAW, 'Print date?', VALUE_OPTIONAL), |
|||
'datefmt' => new external_value(PARAM_INT, 'Date format', VALUE_OPTIONAL), |
|||
'printnumber' => new external_value(PARAM_INT, 'Print number?', VALUE_OPTIONAL), |
|||
'printgrade' => new external_value(PARAM_INT, 'Print grade?', VALUE_OPTIONAL), |
|||
'gradefmt' => new external_value(PARAM_INT, 'Grade format', VALUE_OPTIONAL), |
|||
'printoutcome' => new external_value(PARAM_INT, 'Print outcome?', VALUE_OPTIONAL), |
|||
'printhours' => new external_value(PARAM_TEXT, 'Print hours?', VALUE_OPTIONAL), |
|||
'printteacher' => new external_value(PARAM_INT, 'Print teacher?', VALUE_OPTIONAL), |
|||
'customtext' => new external_value(PARAM_RAW, 'Custom text', VALUE_OPTIONAL), |
|||
'printsignature' => new external_value(PARAM_RAW, 'Print signature?', VALUE_OPTIONAL), |
|||
'printseal' => new external_value(PARAM_RAW, 'Print seal?', VALUE_OPTIONAL), |
|||
'timecreated' => new external_value(PARAM_INT, 'Time created', VALUE_OPTIONAL), |
|||
'timemodified' => new external_value(PARAM_INT, 'Time modified', VALUE_OPTIONAL), |
|||
'section' => new external_value(PARAM_INT, 'course section id', VALUE_OPTIONAL), |
|||
'visible' => new external_value(PARAM_INT, 'visible', VALUE_OPTIONAL), |
|||
'groupmode' => new external_value(PARAM_INT, 'group mode', VALUE_OPTIONAL), |
|||
'groupingid' => new external_value(PARAM_INT, 'group id', VALUE_OPTIONAL), |
|||
), 'Tool' |
|||
) |
|||
), |
|||
'warnings' => new external_warnings(), |
|||
) |
|||
); |
|||
} |
|||
|
|||
/** |
|||
* Returns description of method parameters |
|||
* |
|||
* @return external_function_parameters |
|||
*/ |
|||
public static function view_certificate_parameters() { |
|||
return new external_function_parameters( |
|||
array( |
|||
'certificateid' => new external_value(PARAM_INT, 'certificate instance id') |
|||
) |
|||
); |
|||
} |
|||
|
|||
/** |
|||
* Trigger the course module viewed event and update the module completion status. |
|||
* |
|||
* @param int $certificateid the certificate instance id |
|||
* @return array of warnings and status result |
|||
* @throws moodle_exception |
|||
*/ |
|||
public static function view_certificate($certificateid) { |
|||
global $DB; |
|||
|
|||
$params = self::validate_parameters(self::view_certificate_parameters(), |
|||
array( |
|||
'certificateid' => $certificateid |
|||
) |
|||
); |
|||
$warnings = array(); |
|||
|
|||
// Request and permission validation. |
|||
$certificate = $DB->get_record('certificate', array('id' => $params['certificateid']), '*', MUST_EXIST); |
|||
list($course, $cm) = get_course_and_cm_from_instance($certificate, 'certificate'); |
|||
|
|||
$context = context_module::instance($cm->id); |
|||
self::validate_context($context); |
|||
require_capability('mod/certificate:view', $context); |
|||
|
|||
$event = \mod_certificate\event\course_module_viewed::create(array( |
|||
'objectid' => $certificate->id, |
|||
'context' => $context, |
|||
)); |
|||
$event->add_record_snapshot('course', $course); |
|||
$event->add_record_snapshot('certificate', $certificate); |
|||
$event->trigger(); |
|||
|
|||
$completion = new completion_info($course); |
|||
$completion->set_module_viewed($cm); |
|||
|
|||
$result = array(); |
|||
$result['status'] = true; |
|||
$result['warnings'] = $warnings; |
|||
return $result; |
|||
} |
|||
|
|||
/** |
|||
* Returns description of method result value |
|||
* |
|||
* @return external_description |
|||
*/ |
|||
public static function view_certificate_returns() { |
|||
return new external_single_structure( |
|||
array( |
|||
'status' => new external_value(PARAM_BOOL, 'status: true if success'), |
|||
'warnings' => new external_warnings() |
|||
) |
|||
); |
|||
} |
|||
|
|||
/** |
|||
* Check if the user can issue certificates. |
|||
* |
|||
* @param int $certificateid certificate instance id |
|||
* @return array array containing context related data |
|||
*/ |
|||
private static function check_can_issue($certificateid) { |
|||
global $DB; |
|||
|
|||
$certificate = $DB->get_record('certificate', array('id' => $certificateid), '*', MUST_EXIST); |
|||
list($course, $cm) = get_course_and_cm_from_instance($certificate, 'certificate'); |
|||
|
|||
$context = context_module::instance($cm->id); |
|||
self::validate_context($context); |
|||
require_capability('mod/certificate:view', $context); |
|||
|
|||
// Check if the user can view the certificate. |
|||
if ($certificate->requiredtime && !has_capability('mod/certificate:manage', $context)) { |
|||
if (certificate_get_course_time($course->id) < ($certificate->requiredtime * 60)) { |
|||
$a = new stdClass(); |
|||
$a->requiredtime = $certificate->requiredtime; |
|||
throw new moodle_exception('requiredtimenotmet', 'certificate', '', $a); |
|||
} |
|||
} |
|||
return array($certificate, $course, $cm, $context); |
|||
} |
|||
|
|||
/** |
|||
* Returns a issued certificated structure |
|||
* |
|||
* @return external_single_structure External single structure |
|||
*/ |
|||
private static function issued_structure() { |
|||
return new external_single_structure( |
|||
array( |
|||
'id' => new external_value(PARAM_INT, 'Issue id'), |
|||
'userid' => new external_value(PARAM_INT, 'User id'), |
|||
'certificateid' => new external_value(PARAM_INT, 'Certificate id'), |
|||
'code' => new external_value(PARAM_RAW, 'Certificate code'), |
|||
'timecreated' => new external_value(PARAM_INT, 'Time created'), |
|||
'filename' => new external_value(PARAM_FILE, 'Time created'), |
|||
'fileurl' => new external_value(PARAM_URL, 'Time created'), |
|||
'mimetype' => new external_value(PARAM_RAW, 'mime type'), |
|||
'grade' => new external_value(PARAM_NOTAGS, 'Certificate grade', VALUE_OPTIONAL), |
|||
) |
|||
); |
|||
} |
|||
|
|||
/** |
|||
* Add extra required information to the issued certificate |
|||
* |
|||
* @param stdClass $issue issue object |
|||
* @param stdClass $certificate certificate object |
|||
* @param stdClass $course course object |
|||
* @param stdClass $cm course module object |
|||
* @param stdClass $context context object |
|||
*/ |
|||
private static function add_extra_issue_data($issue, $certificate, $course, $cm, $context) { |
|||
global $CFG; |
|||
|
|||
// Grade data. |
|||
if ($certificate->printgrade) { |
|||
$issue->grade = certificate_get_grade($certificate, $course); |
|||
} |
|||
|
|||
// File data. |
|||
$issue->mimetype = 'application/pdf'; |
|||
$issue->filename = certificate_get_certificate_filename($certificate, $cm, $course) . '.pdf'; |
|||
// We need to use a special file area to be able to download certificates (in most cases are not stored in the site). |
|||
$issue->fileurl = moodle_url::make_webservice_pluginfile_url( |
|||
$context->id, 'mod_certificate', 'onthefly', $issue->id, '/', $issue->filename)->out(false); |
|||
} |
|||
|
|||
/** |
|||
* Returns description of method parameters |
|||
* |
|||
* @return external_function_parameters |
|||
*/ |
|||
public static function issue_certificate_parameters() { |
|||
return new external_function_parameters( |
|||
array( |
|||
'certificateid' => new external_value(PARAM_INT, 'certificate instance id') |
|||
) |
|||
); |
|||
} |
|||
|
|||
/** |
|||
* Create new certificate record, or return existing record. |
|||
* |
|||
* @param int $certificateid the certificate instance id |
|||
* @return array of warnings and status result |
|||
* @throws moodle_exception |
|||
*/ |
|||
public static function issue_certificate($certificateid) { |
|||
global $USER; |
|||
|
|||
$params = self::validate_parameters(self::issue_certificate_parameters(), |
|||
array( |
|||
'certificateid' => $certificateid |
|||
) |
|||
); |
|||
$warnings = array(); |
|||
|
|||
// Request and permission validation. |
|||
list($certificate, $course, $cm, $context) = self::check_can_issue($params['certificateid']); |
|||
|
|||
$issue = certificate_get_issue($course, $USER, $certificate, $cm); |
|||
self::add_extra_issue_data($issue, $certificate, $course, $cm, $context); |
|||
|
|||
$result = array(); |
|||
$result['issue'] = $issue; |
|||
$result['warnings'] = $warnings; |
|||
return $result; |
|||
} |
|||
|
|||
/** |
|||
* Returns description of method result value |
|||
* |
|||
* @return external_description |
|||
*/ |
|||
public static function issue_certificate_returns() { |
|||
return new external_single_structure( |
|||
array( |
|||
'issue' => self::issued_structure(), |
|||
'warnings' => new external_warnings() |
|||
) |
|||
); |
|||
} |
|||
|
|||
/** |
|||
* Returns description of method parameters |
|||
* |
|||
* @return external_function_parameters |
|||
*/ |
|||
public static function get_issued_certificates_parameters() { |
|||
return new external_function_parameters( |
|||
array( |
|||
'certificateid' => new external_value(PARAM_INT, 'certificate instance id') |
|||
) |
|||
); |
|||
} |
|||
|
|||
/** |
|||
* Get the list of issued certificates for the current user. |
|||
* |
|||
* @param int $certificateid the certificate instance id |
|||
* @return array of warnings and status result |
|||
* @throws moodle_exception |
|||
*/ |
|||
public static function get_issued_certificates($certificateid) { |
|||
|
|||
$params = self::validate_parameters(self::get_issued_certificates_parameters(), |
|||
array( |
|||
'certificateid' => $certificateid |
|||
) |
|||
); |
|||
$warnings = array(); |
|||
|
|||
// Request and permission validation. |
|||
list($certificate, $course, $cm, $context) = self::check_can_issue($params['certificateid']); |
|||
|
|||
$issues = certificate_get_attempts($certificate->id); |
|||
|
|||
if ($issues !== false ) { |
|||
foreach ($issues as $issue) { |
|||
self::add_extra_issue_data($issue, $certificate, $course, $cm, $context); |
|||
|
|||
} |
|||
} else { |
|||
$issues = array(); |
|||
} |
|||
|
|||
$result = array(); |
|||
$result['issues'] = $issues; |
|||
$result['warnings'] = $warnings; |
|||
return $result; |
|||
} |
|||
|
|||
/** |
|||
* Returns description of method result value |
|||
* |
|||
* @return external_description |
|||
*/ |
|||
public static function get_issued_certificates_returns() { |
|||
return new external_single_structure( |
|||
array( |
|||
'issues' => new external_multiple_structure(self::issued_structure()), |
|||
'warnings' => new external_warnings() |
|||
) |
|||
); |
|||
} |
|||
|
|||
} |
@ -0,0 +1,16 @@ |
|||
<?php |
|||
namespace mod_certificate\task; |
|||
|
|||
class cron_task extends \core\task\scheduled_task { |
|||
public function get_name() { |
|||
return get_string('crontask', 'mod_certificate'); |
|||
} |
|||
|
|||
public function execute() { |
|||
global $CFG; |
|||
require_once($CFG->dirroot . '/mod/certificate/lib.php'); |
|||
certificate_cron(); |
|||
} |
|||
} |
|||
|
|||
?> |
@ -1,56 +1,56 @@ |
|||
<?xml version="1.0" encoding="UTF-8" ?> |
|||
<XMLDB PATH="mod/certificate/db" VERSION="20070613" COMMENT="XMLDB file for Moodle mod/certificate" |
|||
<XMLDB PATH="mod/certificate/db" VERSION="20140928" COMMENT="XMLDB file for Moodle mod/certificate" |
|||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
|||
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd" |
|||
> |
|||
<TABLES> |
|||
<TABLE NAME="certificate" COMMENT="Defines certificates" NEXT="certificate_issues"> |
|||
<TABLE NAME="certificate" COMMENT="Defines certificates"> |
|||
<FIELDS> |
|||
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" ENUM="false" NEXT="course"/> |
|||
<FIELD NAME="course" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="id" NEXT="name"/> |
|||
<FIELD NAME="name" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="course" NEXT="intro"/> |
|||
<FIELD NAME="intro" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" ENUM="false" PREVIOUS="name" NEXT="introformat"/> |
|||
<FIELD NAME="introformat" TYPE="int" LENGTH="4" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="intro" NEXT="emailteachers"/> |
|||
<FIELD NAME="emailteachers" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="introformat" NEXT="emailothers"/> |
|||
<FIELD NAME="emailothers" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" ENUM="false" PREVIOUS="emailteachers" NEXT="savecert"/> |
|||
<FIELD NAME="savecert" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="emailothers" NEXT="reportcert"/> |
|||
<FIELD NAME="reportcert" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="savecert" NEXT="delivery"/> |
|||
<FIELD NAME="delivery" TYPE="int" LENGTH="3" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="reportcert" NEXT="requiredtime"/> |
|||
<FIELD NAME="requiredtime" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="delivery" NEXT="certificatetype"/> |
|||
<FIELD NAME="certificatetype" TYPE="char" LENGTH="50" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="requiredtime" NEXT="orientation"/> |
|||
<FIELD NAME="orientation" TYPE="char" LENGTH="10" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="certificatetype" NEXT="borderstyle"/> |
|||
<FIELD NAME="borderstyle" TYPE="char" LENGTH="255" NOTNULL="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="orientation" NEXT="bordercolor"/> |
|||
<FIELD NAME="bordercolor" TYPE="char" LENGTH="30" NOTNULL="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="borderstyle" NEXT="printwmark"/> |
|||
<FIELD NAME="printwmark" TYPE="char" LENGTH="255" NOTNULL="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="bordercolor" NEXT="printdate"/> |
|||
<FIELD NAME="printdate" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="printwmark" NEXT="datefmt"/> |
|||
<FIELD NAME="datefmt" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="printdate" NEXT="printnumber"/> |
|||
<FIELD NAME="printnumber" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="datefmt" NEXT="printgrade"/> |
|||
<FIELD NAME="printgrade" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="printnumber" NEXT="gradefmt"/> |
|||
<FIELD NAME="gradefmt" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="printgrade" NEXT="printoutcome"/> |
|||
<FIELD NAME="printoutcome" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="gradefmt" NEXT="printhours"/> |
|||
<FIELD NAME="printhours" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false" ENUM="false" PREVIOUS="printoutcome" NEXT="printteacher"/> |
|||
<FIELD NAME="printteacher" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="printhours" NEXT="customtext"/> |
|||
<FIELD NAME="customtext" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" ENUM="false" PREVIOUS="printteacher" NEXT="printsignature"/> |
|||
<FIELD NAME="printsignature" TYPE="char" LENGTH="255" NOTNULL="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="customtext" NEXT="printseal"/> |
|||
<FIELD NAME="printseal" TYPE="char" LENGTH="255" NOTNULL="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="printsignature" NEXT="timecreated"/> |
|||
<FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="printseal" NEXT="timemodified"/> |
|||
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="timecreated"/> |
|||
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/> |
|||
<FIELD NAME="course" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/> |
|||
<FIELD NAME="name" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false"/> |
|||
<FIELD NAME="intro" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false"/> |
|||
<FIELD NAME="introformat" TYPE="int" LENGTH="4" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/> |
|||
<FIELD NAME="emailteachers" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/> |
|||
<FIELD NAME="emailothers" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false"/> |
|||
<FIELD NAME="savecert" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/> |
|||
<FIELD NAME="reportcert" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/> |
|||
<FIELD NAME="delivery" TYPE="int" LENGTH="3" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/> |
|||
<FIELD NAME="requiredtime" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/> |
|||
<FIELD NAME="certificatetype" TYPE="char" LENGTH="50" NOTNULL="true" SEQUENCE="false"/> |
|||
<FIELD NAME="orientation" TYPE="char" LENGTH="10" NOTNULL="true" SEQUENCE="false"/> |
|||
<FIELD NAME="borderstyle" TYPE="char" LENGTH="255" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/> |
|||
<FIELD NAME="bordercolor" TYPE="char" LENGTH="30" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/> |
|||
<FIELD NAME="printwmark" TYPE="char" LENGTH="255" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/> |
|||
<FIELD NAME="printdate" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/> |
|||
<FIELD NAME="datefmt" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/> |
|||
<FIELD NAME="printnumber" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/> |
|||
<FIELD NAME="printgrade" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/> |
|||
<FIELD NAME="gradefmt" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/> |
|||
<FIELD NAME="printoutcome" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/> |
|||
<FIELD NAME="printhours" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false"/> |
|||
<FIELD NAME="printteacher" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/> |
|||
<FIELD NAME="customtext" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false"/> |
|||
<FIELD NAME="printsignature" TYPE="char" LENGTH="255" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/> |
|||
<FIELD NAME="printseal" TYPE="char" LENGTH="255" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/> |
|||
<FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/> |
|||
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/> |
|||
</FIELDS> |
|||
<KEYS> |
|||
<KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="Primary key for certificate"/> |
|||
</KEYS> |
|||
</TABLE> |
|||
<TABLE NAME="certificate_issues" COMMENT="Info about issued certificates" PREVIOUS="certificate"> |
|||
<TABLE NAME="certificate_issues" COMMENT="Info about issued certificates"> |
|||
<FIELDS> |
|||
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" ENUM="false" NEXT="userid"/> |
|||
<FIELD NAME="userid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="id" NEXT="certificateid"/> |
|||
<FIELD NAME="certificateid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="userid" NEXT="code"/> |
|||
<FIELD NAME="code" TYPE="char" LENGTH="40" NOTNULL="false" SEQUENCE="false" ENUM="false" PREVIOUS="certificateid" NEXT="timecreated"/> |
|||
<FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="code"/> |
|||
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/> |
|||
<FIELD NAME="userid" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/> |
|||
<FIELD NAME="certificateid" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/> |
|||
<FIELD NAME="code" TYPE="char" LENGTH="40" NOTNULL="false" SEQUENCE="false"/> |
|||
<FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/> |
|||
</FIELDS> |
|||
<KEYS> |
|||
<KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="Primary key for certificate_issues"/> |
|||
</KEYS> |
|||
</TABLE> |
|||
</TABLES> |
|||
</XMLDB> |
|||
</XMLDB> |
|||
|
@ -0,0 +1,27 @@ |
|||
<?php |
|||
// This file is part of the Certificate 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/>. |
|||
|
|||
/** |
|||
* Certificate module capability definition |
|||
* |
|||
* @package mod_certificate |
|||
* @copyright 2016 Juan Leyva <juan@moodle.com> |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
|
|||
$addons = array( |
|||
"mod_certificate" => array() |
|||
); |
@ -0,0 +1,64 @@ |
|||
<?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/>. |
|||
|
|||
/** |
|||
* Certificate external functions and service definitions. |
|||
* |
|||
* @package mod_certificate |
|||
* @category external |
|||
* @copyright 2016 Juan Leyva <juan@moodle.com> |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
|
|||
$functions = array( |
|||
|
|||
'mod_certificate_get_certificates_by_courses' => array( |
|||
'classname' => 'mod_certificate_external', |
|||
'methodname' => 'get_certificates_by_courses', |
|||
'description' => 'Returns a list of certificate instances in a provided set of courses, if |
|||
no courses are provided then all the certificate instances the user has access to will be returned.', |
|||
'type' => 'read', |
|||
'capabilities' => 'mod/certificate:view', |
|||
'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE, 'local_mobile'), |
|||
), |
|||
|
|||
'mod_certificate_view_certificate' => array( |
|||
'classname' => 'mod_certificate_external', |
|||
'methodname' => 'view_certificate', |
|||
'description' => 'Trigger the course module viewed event and update the module completion status.', |
|||
'type' => 'write', |
|||
'capabilities' => 'mod/certificate:view', |
|||
'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE, 'local_mobile'), |
|||
), |
|||
|
|||
'mod_certificate_issue_certificate' => array( |
|||
'classname' => 'mod_certificate_external', |
|||
'methodname' => 'issue_certificate', |
|||
'description' => 'Create new certificate record, or return existing record for the current user.', |
|||
'type' => 'write', |
|||
'capabilities' => 'mod/certificate:view', |
|||
'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE, 'local_mobile'), |
|||
), |
|||
|
|||
'mod_certificate_get_issued_certificates' => array( |
|||
'classname' => 'mod_certificate_external', |
|||
'methodname' => 'get_issued_certificates', |
|||
'description' => 'Get the list of issued certificates for the current user.', |
|||
'type' => 'read', |
|||
'capabilities' => 'mod/certificate:view', |
|||
'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE, 'local_mobile'), |
|||
), |
|||
); |
@ -0,0 +1,38 @@ |
|||
<?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/>. |
|||
|
|||
/** |
|||
* Definition of Certificate scheduled tasks. |
|||
* |
|||
* @package mod_certificate |
|||
* @category task |
|||
* @copyright 2014 Dan Poltawski <dan@moodle.com> |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
|
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
$tasks = array( |
|||
array( |
|||
'classname' => 'mod_certificate\task\cron_task', |
|||
'blocking' => 0, |
|||
'minute' => '*', |
|||
'hour' => '*', |
|||
'day' => '*', |
|||
'month' => '*', |
|||
'dayofweek' => '*' |
|||
) |
|||
); |
File diff suppressed because it is too large
File diff suppressed because it is too large
Binary file not shown.
@ -0,0 +1,91 @@ |
|||
<?php |
|||
|
|||
// This program 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. |
|||
// |
|||
// This program 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 this program. If not, see <http://www.gnu.org/licenses/>. |
|||
|
|||
/** |
|||
* Certificate module data generator. |
|||
* |
|||
* @package mod_certificate |
|||
* @category test |
|||
* @author Russell England <russell.england@catalyst-eu.net> |
|||
* @copyright Catalyst IT Ltd 2013 <http://catalyst-eu.net> |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL |
|||
*/ |
|||
|
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
class mod_certificate_generator extends testing_module_generator { |
|||
|
|||
/** |
|||
* Create new certificate module instance |
|||
* @param array|stdClass $record data for module being generated. Requires 'course' key |
|||
* (an id or the full object). Also can have any fields from add module form. |
|||
* @param null|array $options general options for course module. Since 2.6 it is |
|||
* possible to omit this argument by merging options into $record |
|||
* @return stdClass record from module-defined table with additional field |
|||
* cmid (corresponding id in course_modules table) |
|||
*/ |
|||
public function create_instance($record = null, array $options = null) { |
|||
global $CFG; |
|||
require_once("$CFG->dirroot/mod/certificate/lib.php"); |
|||
|
|||
$this->instancecount++; |
|||
$i = $this->instancecount; |
|||
|
|||
$record = (object)(array)$record; |
|||
$options = (array)$options; |
|||
|
|||
if (empty($record->course)) { |
|||
throw new coding_exception('module generator requires $record->course'); |
|||
} |
|||
|
|||
$defaults = array(); |
|||
$defaults['name'] = get_string('pluginname', 'certificate').' '.$i; |
|||
$defaults['intro'] = 'Test certificate '.$i; |
|||
$defaults['introformat'] = FORMAT_MOODLE; |
|||
$defaults['emailteachers'] = 0; |
|||
$defaults['savecert'] = 0; |
|||
$defaults['reportcert'] = 0; |
|||
$defaults['delivery'] = 0; |
|||
$defaults['certificatetype'] = 'A4_non_embedded'; |
|||
$defaults['orientation'] = 'L'; |
|||
$defaults['borderstyle'] = '0'; |
|||
$defaults['bordercolor'] = '0'; |
|||
$defaults['printwmark'] = '0'; |
|||
$defaults['printdate'] = 0; |
|||
$defaults['datefmt'] = 0; |
|||
$defaults['printnumber'] = 0; |
|||
$defaults['printgrade'] = 0; |
|||
$defaults['gradefmt'] = 0; |
|||
$defaults['printoutcome'] = 0; |
|||
$defaults['printhours'] = ''; |
|||
$defaults['printteacher'] = 0; |
|||
$defaults['printsignature'] = '0'; |
|||
$defaults['printseal'] = '0'; |
|||
foreach ($defaults as $field => $value) { |
|||
if (!isset($record->$field)) { |
|||
$record->$field = $value; |
|||
} |
|||
} |
|||
|
|||
if (isset($options['idnumber'])) { |
|||
$record->cmidnumber = $options['idnumber']; |
|||
} else { |
|||
$record->cmidnumber = ''; |
|||
} |
|||
|
|||
// Do work to actually add the instance. |
|||
return parent::create_instance($record, (array)$options); |
|||
} |
|||
} |
@ -0,0 +1,56 @@ |
|||
<?php |
|||
|
|||
// This program 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. |
|||
// |
|||
// This program 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 this program. If not, see <http://www.gnu.org/licenses/>. |
|||
|
|||
/** |
|||
* Certificate module data generator. |
|||
* |
|||
* @package mod_certificate |
|||
* @category test |
|||
* @author Russell England <russell.england@catalyst-eu.net> |
|||
* @copyright Catalyst IT Ltd 2013 <http://catalyst-eu.net> |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL |
|||
*/ |
|||
|
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
class mod_certificate_generator_testcase extends advanced_testcase { |
|||
public function test_generator() { |
|||
global $DB; |
|||
|
|||
$this->resetAfterTest(true); |
|||
|
|||
$this->assertEquals(0, $DB->count_records('certificate')); |
|||
|
|||
$course = $this->getDataGenerator()->create_course(); |
|||
|
|||
/** @var mod_certificate_generator $generator */ |
|||
$generator = $this->getDataGenerator()->get_plugin_generator('mod_certificate'); |
|||
$this->assertInstanceOf('mod_certificate_generator', $generator); |
|||
$this->assertEquals('certificate', $generator->get_modulename()); |
|||
|
|||
$generator->create_instance(array('course' => $course->id)); |
|||
$generator->create_instance(array('course' => $course->id)); |
|||
$certificate = $generator->create_instance(array('course' => $course->id)); |
|||
$this->assertEquals(3, $DB->count_records('certificate')); |
|||
|
|||
$cm = get_coursemodule_from_instance('certificate', $certificate->id); |
|||
$this->assertEquals($certificate->id, $cm->instance); |
|||
$this->assertEquals('certificate', $cm->modname); |
|||
$this->assertEquals($course->id, $cm->course); |
|||
|
|||
$context = context_module::instance($cm->id); |
|||
$this->assertEquals($certificate->cmid, $context->instanceid); |
|||
} |
|||
} |
@ -0,0 +1,182 @@ |
|||
<?php |
|||
|
|||
// This file is part of the Certificate 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/>. |
|||
|
|||
/** |
|||
* A4_embedded certificate type |
|||
* |
|||
* @package mod |
|||
* @subpackage certificate |
|||
* @copyright Mark Nelson <markn@moodle.com> |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
|
|||
if (!defined('MOODLE_INTERNAL')) { |
|||
die('Direct access to this script is forbidden.'); // It must be included from view.php |
|||
} |
|||
|
|||
/** |
|||
* Gets the course start date (for ILB start date is the date of enrollment) |
|||
* and completion date from course completion framework. |
|||
* Finally format them to print |
|||
*/ |
|||
require_once("$CFG->dirroot/completion/completion_completion.php"); |
|||
|
|||
$start_date = $course->startdate; |
|||
$end_date = $course->enddate; |
|||
$emissao_date = $course->enddate; |
|||
|
|||
$fmt = '%d/%m/%Y'; // Default format |
|||
if ($certificate->datefmt == 1) { |
|||
$fmt = '%B %d, %Y'; |
|||
} else if ($certificate->datefmt == 2) { |
|||
$suffix = certificate_get_ordinal_number_suffix(userdate($ts, '%d')); |
|||
$fmt = '%B %d' . $suffix . ', %Y'; |
|||
} else if ($certificate->datefmt == 3) { |
|||
$fmt = '%d de %B de %Y'; |
|||
} else if ($certificate->datefmt == 4) { |
|||
$fmt = '%B de %Y'; |
|||
} else if ($certificate->datefmt == 5) { |
|||
$fmt = get_string('strftimedate', 'langconfig'); |
|||
} |
|||
|
|||
$start_date = userdate($start_date, $fmt); |
|||
$end_date = userdate($end_date, $fmt); |
|||
$emissao_date = userdate($emissao_date, $fmt); |
|||
|
|||
//MASK para CPF |
|||
function mask($val, $mask) |
|||
{ |
|||
$maskared = ''; |
|||
$k = 0; |
|||
for($i = 0; $i<=strlen($mask)-1; $i++){ |
|||
|
|||
if($mask[$i] == '#'){ |
|||
if(isset($val[$k])) |
|||
$maskared .= $val[$k++]; |
|||
} |
|||
else |
|||
{ |
|||
if(isset($mask[$i])) |
|||
$maskared .= $mask[$i]; |
|||
} |
|||
} |
|||
return $maskared; |
|||
} |
|||
|
|||
$cpf = mask($USER->username, '###.###.###-##'); |
|||
|
|||
require_once($CFG->dirroot.'/user/profile/field/cpf/field.class.php'); |
|||
|
|||
|
|||
$pdf = new PDF($certificate->orientation, 'mm', 'A4', true, 'UTF-8', false); |
|||
|
|||
$pdf->SetTitle($certificate->name); |
|||
$pdf->SetProtection(array('modify')); |
|||
$pdf->setPrintHeader(false); |
|||
$pdf->setPrintFooter(false); |
|||
$pdf->SetAutoPageBreak(false, 0); |
|||
$pdf->AddPage(); |
|||
|
|||
// Define variables |
|||
// Landscape |
|||
if ($certificate->orientation == 'L') { |
|||
$x = 20; |
|||
$y = 60; |
|||
$sealx = 230; |
|||
$sealy = 150; |
|||
$sigx = 00; |
|||
$sigy = 165; |
|||
$custx = 15; |
|||
$custy = $y+25; |
|||
$wmarkx = 40; |
|||
$wmarky = 31; |
|||
$wmarkw = 212; |
|||
$wmarkh = 148; |
|||
$brdrx = 0; |
|||
$brdry = 0; |
|||
$brdrw = 297; |
|||
$brdrh = 210; |
|||
$codex = $x; |
|||
$codey = 175; |
|||
} else { // Portrait |
|||
$x = 10; |
|||
$y = 90; |
|||
$sealx = 150; |
|||
$sealy = 220; |
|||
$sigx = 10; |
|||
$sigy = 235; |
|||
$custx = 15; |
|||
$custy = $y+25; |
|||
$wmarkx = 26; |
|||
$wmarky = 58; |
|||
$wmarkw = 158; |
|||
$wmarkh = 170; |
|||
$brdrx = 0; |
|||
$brdry = 0; |
|||
$brdrw = 210; |
|||
$brdrh = 297; |
|||
$codex = $x; |
|||
$codey = 245; |
|||
} |
|||
|
|||
// Front page ------------------------------------------------------------------------------------------------------------ |
|||
// Add images and lines |
|||
certificate_print_image($pdf, $certificate, CERT_IMAGE_BORDER, $brdrx, $brdry, $brdrw, $brdrh); |
|||
certificate_draw_frame($pdf, $certificate); |
|||
// Set alpha to semi-transparency |
|||
$pdf->SetAlpha(0.2); |
|||
certificate_print_image($pdf, $certificate, CERT_IMAGE_WATERMARK, $wmarkx, $wmarky, $wmarkw, $wmarkh); |
|||
$pdf->SetAlpha(1); |
|||
certificate_print_image($pdf, $certificate, CERT_IMAGE_SEAL, $sealx, $sealy, '', ''); |
|||
certificate_print_image($pdf, $certificate, CERT_IMAGE_SIGNATURE, $sigx, $sigy, '', ''); |
|||
|
|||
// Add text |
|||
$pdf->SetTextColor(0, 0, 0); |
|||
certificate_print_text($pdf, $x, $y, 'C', 'freesans', '', 20, get_string('title', 'certificate')); |
|||
certificate_print_text($pdf, $x, $y + 15, 'C', 'freesans', '', 18, get_string('certify', 'certificate')); |
|||
certificate_print_text($pdf, $x, $y + 25, 'C', 'freesans', 'B', 18, mb_strtoupper(fullname($USER), 'UTF-8').", CPF nº $cpf"); |
|||
certificate_print_text($pdf, $x, $y + 35, 'C', 'freesans', '', 18, "realizou, na modalidade a distância, o curso com tutoria"); |
|||
certificate_print_text($pdf, $x, $y + 45, 'C', 'freesans', 'B', 18, mb_strtoupper($course->fullname, 'UTF-8')); |
|||
certificate_print_text($pdf, $x, $y + 55, 'C', 'freesans', '', 18, "no período de {$start_date} a {$end_date}"); |
|||
if ($certificate->printhours) { |
|||
certificate_print_text($pdf, $x, $y + 65, 'C', 'freesans', '', 18, "com carga horária de {$certificate->printhours}"); |
|||
} |
|||
certificate_print_text($pdf, $x, $y + 75, 'C', 'freesans', '', 18, certificate_get_grade($certificate, $course)); |
|||
certificate_print_text($pdf, $x, $y + 85, 'R', 'freesans', 'B', 14, "Brasília, {$emissao_date}."); |
|||
|
|||
|
|||
// Verse page ----------------------------------------------------------------------------------------------------------- |
|||
$pdf->AddPage(); |
|||
// Add images and lines |
|||
certificate_print_image($pdf, $certificate, CERT_IMAGE_BORDER, $brdrx, $brdry, $brdrw, $brdrh); |
|||
certificate_draw_frame($pdf, $certificate); |
|||
// Set alpha to semi-transparency |
|||
$pdf->SetAlpha(0.2); |
|||
certificate_print_image($pdf, $certificate, CERT_IMAGE_WATERMARK, $wmarkx, $wmarky, $wmarkw, $wmarkh); |
|||
$pdf->SetAlpha(1); |
|||
certificate_print_image($pdf, $certificate, CERT_IMAGE_SEAL, $sealx, $sealy, '', ''); |
|||
|
|||
// Add text |
|||
$pdf->SetTextColor(0, 0, 0); |
|||
certificate_print_text($pdf, $x, $y, 'C', 'freesans', '', 20, 'PROGRAMA DO CURSO'); |
|||
certificate_print_text($pdf, $x, $y + 10, 'C', 'freesans', '', 20, mb_strtoupper($course->fullname, 'UTF-8')); |
|||
certificate_print_text($pdf, $custx, $custy, 'L', 'freesans', '', 10, $certificate->customtext); |
|||
certificate_print_text($pdf, $codex, $codey, 'C', 'freesans', '', 10, 'CÓDIGO DE VALIDAÇÃO'); |
|||
certificate_print_text($pdf, $codex, $codey + 5, 'C', 'freesans', 'B', 12, certificate_get_code($certificate, $certrecord)); |
|||
certificate_print_text($pdf, $codex, $codey + 10, 'C', 'freesans', '', 10, 'Para verificar a autenticidade deste certificado, acesse http://saberes.senado.leg.br/ e informe o código acima'); |
|||
|
|||
?> |
Loading…
Reference in new issue