Browse Source

Adaptações para MOODLE 3.4

MOODLE_34_STABLE
Matheus Garcia 7 years ago
parent
commit
89d31cef87
  1. 2
      backup/moodle2/backup_certificate_activity_task.class.php
  2. 2
      backup/moodle2/backup_certificate_settingslib.php
  3. 2
      backup/moodle2/backup_certificate_stepslib.php
  4. 2
      backup/moodle2/restore_certificate_activity_task.class.php
  5. 5
      backup/moodle2/restore_certificate_stepslib.php
  6. 72
      classes/admin_setting_font.php
  7. 46
      classes/admin_setting_upload.php
  8. 32
      classes/event/course_module_instance_list_viewed.php
  9. 36
      classes/event/course_module_viewed.php
  10. 455
      classes/external.php
  11. 16
      classes/task/cron_task.php
  12. 6
      db/access.php
  13. 74
      db/install.xml
  14. 3
      db/log.php
  15. 27
      db/mobile.php
  16. 64
      db/services.php
  17. 38
      db/tasks.php
  18. 89
      db/upgrade.php
  19. 3
      deprecatedlib.php
  20. 13
      index.php
  21. 19
      lang/en/certificate.php
  22. 1
      lang/pt_br/certificate.php
  23. 1353
      lib.php
  24. 1293
      locallib.php
  25. BIN
      mobile/mod_certificate.zip
  26. 9
      mod_form.php
  27. 109
      report.php
  28. 25
      review.php
  29. 17
      settings.php
  30. 91
      tests/generator/lib.php
  31. 56
      tests/generator_test.php
  32. 34
      type/A4_embedded/certificate.php
  33. 10
      type/A4_non_embedded/certificate.php
  34. 182
      type/ILB_Com_tutoria/certificate.php
  35. 26
      type/ILB_Com_tutoria_2014/certificate.php
  36. 26
      type/ILB_Sem_tutoria_2014/certificate.php
  37. 27
      type/ILB_presencial_2016/certificate.php
  38. 28
      type/Oficinas_Interlegis/certificate.php
  39. 9
      type/PFG_FC2/certificate.php
  40. 7
      type/PFG_FC2_2016/certificate.php
  41. 7
      type/PFG_FC3/certificate.php
  42. 31
      type/cert_comtutoria/certificate.php
  43. 42
      type/cert_presencial/certificate.php
  44. 28
      type/cert_presencial_rasf/certificate.php
  45. 36
      type/letter_embedded/certificate.php
  46. 12
      type/letter_non_embedded/certificate.php
  47. 6
      upload_image.php
  48. 5
      upload_image_form.php
  49. 17
      version.php
  50. 62
      view.php

2
backup/moodle2/backup_certificate_activity_task.class.php

@ -16,7 +16,7 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* @package moodlecore
* @package mod_certificate
* @subpackage backup-moodle2
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later

2
backup/moodle2/backup_certificate_settingslib.php

@ -16,7 +16,7 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* @package moodlecore
* @package mod_certificate
* @subpackage backup-moodle2
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later

2
backup/moodle2/backup_certificate_stepslib.php

@ -16,7 +16,7 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* @package moodlecore
* @package mod_certificate
* @subpackage backup-moodle2
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later

2
backup/moodle2/restore_certificate_activity_task.class.php

@ -16,7 +16,7 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* @package moodlecore
* @package mod_certificate
* @subpackage backup-moodle2
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later

5
backup/moodle2/restore_certificate_stepslib.php

@ -16,7 +16,7 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* @package moodlecore
* @package mod_certificate
* @subpackage backup-moodle2
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
@ -69,6 +69,9 @@ class restore_certificate_activity_structure_step extends restore_activity_struc
$data->certificateid = $this->get_new_parentid('certificate');
$data->timecreated = $this->apply_date_offset($data->timecreated);
if ($data->userid > 0) {
$data->userid = $this->get_mappingid('user', $data->userid);
}
$newitemid = $DB->insert_record('certificate_issues', $data);
$this->set_mapping('certificate_issue', $oldid, $newitemid);

72
classes/admin_setting_font.php

@ -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;
}
}

46
classes/admin_setting_upload.php

@ -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);
}
}

32
classes/event/course_module_instance_list_viewed.php

@ -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 {
}

36
classes/event/course_module_viewed.php

@ -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();
}
}

455
classes/external.php

@ -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()
)
);
}
}

16
classes/task/cron_task.php

@ -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();
}
}
?>

6
db/access.php

@ -18,8 +18,7 @@
/**
* Certificate module capability definition
*
* @package mod
* @subpackage certificate
* @package mod_certificate
* @copyright Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
@ -66,8 +65,7 @@ $capabilities = array(
'contextlevel' => CONTEXT_MODULE,
'archetypes' => array(
'teacher' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
'manager' => CAP_ALLOW
'editingteacher' => CAP_ALLOW
)
),

74
db/install.xml

@ -1,52 +1,52 @@
<?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"/>

3
db/log.php

@ -18,8 +18,7 @@
/**
* Definition of log events
*
* @package mod
* @subpackage lesson
* @package mod_certificate
* @copyright 2010 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

27
db/mobile.php

@ -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()
);

64
db/services.php

@ -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'),
),
);

38
db/tasks.php

@ -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' => '*'
)
);

89
db/upgrade.php

@ -18,8 +18,7 @@
/**
* This file keeps track of upgrades to the certificate module
*
* @package mod
* @subpackage certificate
* @package mod_certificate
* @copyright Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
@ -48,14 +47,14 @@ function xmldb_certificate_upgrade($oldversion=0) {
$table = new xmldb_table('certificate');
$field = new xmldb_field('lockgrade');
$field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'printhours');
$field->set_attributes(XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'printhours');
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
$table = new xmldb_table('certificate');
$field = new xmldb_field('requiredgrade');
$field->set_attributes(XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'lockgrade');
$field->set_attributes(XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, '0', 'lockgrade');
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
@ -63,12 +62,12 @@ function xmldb_certificate_upgrade($oldversion=0) {
// Rename field save to savecert
$field = new xmldb_field('save');
if ($dbman->field_exists($table, $field)) {
$field->set_attributes(XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'emailothers');
$field->set_attributes(XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0', 'emailothers');
// Launch rename field savecert
$dbman->rename_field($table, $field, 'savecert');
} else {
$field = new xmldb_field('savecert');
$field->set_attributes(XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'emailothers');
$field->set_attributes(XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0', 'emailothers');
$dbman->add_field($table, $field);
}
@ -79,11 +78,11 @@ function xmldb_certificate_upgrade($oldversion=0) {
if ($oldversion < 2007061301) {
$table = new xmldb_table('certificate_linked_modules');
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null);
$table->add_field('certificate_id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'id');
$table->add_field('linkid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'certificate_id');
$table->add_field('linkgrade', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'linkid');
$table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'linkgrade');
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null);
$table->add_field('certificate_id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'id');
$table->add_field('linkid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'certificate_id');
$table->add_field('linkgrade', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'linkid');
$table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'linkgrade');
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'), null, null);
$table->add_index('certificate_id', XMLDB_INDEX_NOTUNIQUE, array('certificate_id'));
$table->add_index('linkid', XMLDB_INDEX_NOTUNIQUE, array('linkid'));
@ -95,21 +94,11 @@ function xmldb_certificate_upgrade($oldversion=0) {
upgrade_mod_savepoint(true, 2007061301, 'certificate');
}
if ($oldversion < 2007061302) {
$table = new xmldb_table('certificate_linked_modules');
$field = new xmldb_field('linkid');
$field->set_attributes(XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'certificate_id');
$dbman->change_field_unsigned($table, $field);
// Certificate savepoint reached
upgrade_mod_savepoint(true, 2007061302, 'certificate');
}
if ($oldversion < 2007102800) {
// Add new fields to certificate table
$table = new xmldb_table('certificate');
$field = new xmldb_field('reportcert');
$field->set_attributes(XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'savecert');
$field->set_attributes(XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0', 'savecert');
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
@ -129,7 +118,7 @@ function xmldb_certificate_upgrade($oldversion=0) {
// Add new fields to certificate table
$table = new xmldb_table('certificate');
$field = new xmldb_field('printoutcome');
$field->set_attributes(XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'gradefmt');
$field->set_attributes(XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0', 'gradefmt');
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
@ -157,7 +146,7 @@ function xmldb_certificate_upgrade($oldversion=0) {
if ($oldversion < 2009062900) {
// Add new field to certificate table
$table = new xmldb_table('certificate');
$field = new xmldb_field('introformat', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'intro');
$field = new xmldb_field('introformat', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, '0', 'intro');
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
@ -167,7 +156,7 @@ function xmldb_certificate_upgrade($oldversion=0) {
$dbman->add_field($table, $field);
}
$field = new xmldb_field('reissuecert', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'reportcert');
$field = new xmldb_field('reissuecert', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0', 'reportcert');
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
@ -196,7 +185,7 @@ function xmldb_certificate_upgrade($oldversion=0) {
// Define field id to be added to certificate
$table = new xmldb_table('certificate');
$field = new xmldb_field('introformat', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, 0, 'intro');
$field = new xmldb_field('introformat', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, 0, 'intro');
// Conditionally launch add field id
if (!$dbman->field_exists($table, $field)) {
@ -217,7 +206,7 @@ function xmldb_certificate_upgrade($oldversion=0) {
// It is possible for these fields not to be added, ever, it is included in the upgrade
// process but fresh certificate 1.9 install from CVS MOODLE_19_STABLE set the Moodle version
// to 2009080900, which means it missed all the earlier code written for upgrading to 2.0.
$reissuefield = new xmldb_field('reissuecert', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'reportcert');
$reissuefield = new xmldb_field('reissuecert', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0', 'reportcert');
$orientationfield = new xmldb_field('orientation', XMLDB_TYPE_CHAR, '10', null, XMLDB_NOTNULL, null, ' ', 'certificatetype');
// Have to check, may be added during earlier upgrade, or may be missing due to not being included in install.xml
@ -399,7 +388,7 @@ function xmldb_certificate_upgrade($oldversion=0) {
if ($oldversion < 2012072501) {
// Add a column to store the required grade
$table = new xmldb_table('certificate');
$requiredtimefield = new xmldb_field('requiredtime', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
$requiredtimefield = new xmldb_field('requiredtime', XMLDB_TYPE_INTEGER, '10', null,
XMLDB_NOTNULL, null, '0', 'delivery');
if (!$dbman->field_exists($table, $requiredtimefield)) {
@ -435,32 +424,32 @@ function xmldb_certificate_upgrade($oldversion=0) {
$table = new xmldb_table('certificate');
// Change length of the fields that store images, so longer image names can be stored
$field = new xmldb_field('borderstyle', XMLDB_TYPE_CHAR, '255', XMLDB_UNSIGNED, XMLDB_NOTNULL, 0);
$field = new xmldb_field('borderstyle', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, 0);
$dbman->change_field_precision($table, $field);
$field = new xmldb_field('printwmark', XMLDB_TYPE_CHAR, '255', XMLDB_UNSIGNED, XMLDB_NOTNULL, 0);
$field = new xmldb_field('printwmark', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, 0);
$dbman->change_field_precision($table, $field);
$field = new xmldb_field('printsignature', XMLDB_TYPE_CHAR, '255', XMLDB_UNSIGNED, XMLDB_NOTNULL, 0);
$field = new xmldb_field('printsignature', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, 0);
$dbman->change_field_precision($table, $field);
$field = new xmldb_field('printseal', XMLDB_TYPE_CHAR, '255', XMLDB_UNSIGNED, XMLDB_NOTNULL, 0);
$field = new xmldb_field('printseal', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, 0);
$dbman->change_field_precision($table, $field);
// Change length of fields that are unnecessarily large
$field = new xmldb_field('printnumber', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, 0, 0);
$field = new xmldb_field('printnumber', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, 0, 0);
$dbman->change_field_precision($table, $field);
$field = new xmldb_field('printhours', XMLDB_TYPE_CHAR, '255', XMLDB_UNSIGNED, false, 0, 0);
$field = new xmldb_field('printhours', XMLDB_TYPE_CHAR, '255', null, false, 0, 0);
$dbman->change_field_precision($table, $field);
$field = new xmldb_field('emailteachers', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, 0, 0);
$field = new xmldb_field('emailteachers', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, 0, 0);
$dbman->change_field_precision($table, $field);
$field = new xmldb_field('savecert', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, 0, 0);
$field = new xmldb_field('savecert', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, 0, 0);
$dbman->change_field_precision($table, $field);
$field = new xmldb_field('reportcert', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, 0, 0);
$field = new xmldb_field('reportcert', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, 0, 0);
$dbman->change_field_precision($table, $field);
// Certificate savepoint reached
@ -470,7 +459,7 @@ function xmldb_certificate_upgrade($oldversion=0) {
if ($oldversion < 2012090901) {
$table = new xmldb_table('certificate');
$field = new xmldb_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, 0, 0, 'printseal');
$field = new xmldb_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, 0, 0, 'printseal');
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
@ -484,5 +473,29 @@ function xmldb_certificate_upgrade($oldversion=0) {
upgrade_mod_savepoint(true, 2012090901, 'certificate');
}
if ($oldversion < 2014081901) {
// Fix previous upgrades.
$table = new xmldb_table('certificate');
$field = new xmldb_field('borderstyle', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, 0, '0');
$dbman->change_field_default($table, $field);
$field = new xmldb_field('printwmark', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, 0, '0');
$dbman->change_field_default($table, $field);
$field = new xmldb_field('printhours', XMLDB_TYPE_CHAR, '255', null, false, 0, null);
$dbman->change_field_default($table, $field);
$field = new xmldb_field('printsignature', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, 0, '0');
$dbman->change_field_default($table, $field);
$field = new xmldb_field('printseal', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, 0, '0');
$dbman->change_field_default($table, $field);
// Certificate savepoint reached.
upgrade_mod_savepoint(true, 2014081901, 'certificate');
}
return true;
}

3
deprecatedlib.php

@ -18,8 +18,7 @@
/**
* Deprecated certificate functions.
*
* @package mod
* @subpackage certificate
* @package mod_certificate
* @copyright Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

13
index.php

@ -18,14 +18,13 @@
/**
* This page lists all the instances of certificate in a particular course
*
* @package mod
* @subpackage certificate
* @package mod_certificate
* @copyright Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once('../../config.php');
require_once('lib.php');
require_once('locallib.php');
$id = required_param('id', PARAM_INT); // Course Module ID
@ -35,7 +34,7 @@ if (!$course = $DB->get_record('course', array('id'=> $id))) {
}
// Requires a login
require_course_login($course);
require_login($course);
// Declare variables
$currentsection = "";
@ -56,7 +55,11 @@ $PAGE->set_title($strcertificates);
$PAGE->set_heading($course->fullname);
// Add the page view to the Moodle log
add_to_log($course->id, 'certificate', 'view all', 'index.php?id='.$course->id, '');
$event = \mod_certificate\event\course_module_instance_list_viewed::create(array(
'context' => context_course::instance($course->id)
));
$event->add_record_snapshot('course', $course);
$event->trigger();
// Get the certificates, if there are none display a notice
if (!$certificates = get_all_instances_in_course('certificate', $course)) {

19
lang/en/certificate.php

@ -18,8 +18,7 @@
/**
* Language strings for the certificate module
*
* @package mod
* @subpackage certificate
* @package mod_certificate
* @copyright Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
@ -63,12 +62,14 @@ $string['certify'] = 'This is to certify that';
$string['certifyilb'] = 'This is to certify that';
$string['code'] = 'Code';
$string['completiondate'] = 'Course Completion';
$string['completionrequired'] = '<p><strong>You have not completed the course.</strong></p><br/>/n<p>While the criteria for course completion are not met, the certificate can not be issued.</p>';
$string['course'] = 'For';
$string['coursegrade'] = 'Course Grade';
$string['coursename'] = 'Course';
$string['coursetimereq'] = 'Required minutes in course';
$string['coursetimereq_help'] = 'Enter here the minimum amount of time, in minutes, that a student must be logged into the course before they will be able to receive the certificate.';
$string['credithours'] = 'Credit Hours';
$string['crontask'] = 'Update users to generate certificates';
$string['customtext'] = 'Custom Text';
$string['customtext_help'] = 'If you want the certificate to print different names for the teacher than those who are assigned
the role of teacher, do not select Print Teacher or any signature image except for the line image. Enter the teacher names in this text box as you would like them to appear. By default, this text is placed in the lower left of the certificate. The following html tags are available: &lt;br&gt;, &lt;p&gt;, &lt;b&gt;, &lt;i&gt;, &lt;u&gt;, &lt;img&gt; (src and width (or height) are mandatory), &lt;a&gt; (href is mandatory), &lt;font&gt; (possible attributes are: color, (hex color code), face, (arial, times, courier, helvetica, symbol)).';
@ -85,7 +86,7 @@ Email Certificate: Choosing this option sends the certificate to the student as
After a user receives their certificate, if they click on the certificate link from the course homepage, they will see the date they received their certificate and will be able to review their received certificate.';
$string['designoptions'] = 'Design Options';
$string['download'] = 'Force download';
$string['emailcertificate'] = 'Email (Must also choose save!)';
$string['emailcertificate'] = 'Email';
$string['emailothers'] = 'Email Others';
$string['emailothers_help'] = 'Enter the email addresses here, separated by a comma, of those who should be alerted with an email whenever students receive a certificate.';
$string['emailstudenttext'] = 'Attached is your certificate for {$a->course}.';
@ -106,6 +107,10 @@ You can review it here:
<a href="{$a->url}">Certificate Report</a>.';
$string['entercode'] = 'Enter certificate code to verify:';
$string['fontsans'] = 'Sans-serif font family';
$string['fontsans_desc'] = 'Sans-serif font family for certificates with embedded fonts';
$string['fontserif'] = 'Serif font family';
$string['fontserif_desc'] = 'Serif font family for certificates with embedded fonts';
$string['getcertificate'] = 'Get your certificate';
$string['grade'] = 'Grade';
$string['gradedate'] = 'Grade Date';
@ -119,7 +124,7 @@ $string['gradeletter'] = 'Letter Grade';
$string['gradepercent'] = 'Percentage Grade';
$string['gradepoints'] = 'Points Grade';
$string['imagetype'] = 'Image Type';
$string['incompletemessage'] = 'In order to download your certificate, you must first complete all required '.'activities. Please return to the course to complete your coursework.';
$string['incompletemessage'] = 'In order to download your certificate, you must first complete all required activities. Please return to the course to complete your coursework.';
$string['intro'] = 'Introduction';
$string['issueoptions'] = 'Issue Options';
$string['issued'] = 'Issued';
@ -129,6 +134,8 @@ $string['lastviewed'] = 'You last received this certificate on:';
$string['letter'] = 'Letter';
$string['lockingoptions'] = 'Locking Options';
$string['modulename'] = 'Certificate';
$string['modulename_help'] = 'This module allows for the dynamic generation of certificates based on predefined conditions set by the teacher.';
$string['modulename_link'] = 'Certificate_module';
$string['modulenameplural'] = 'Certificates';
$string['mycertificates'] = 'My Certificates';
$string['nocertificates'] = 'There are no certificates';
@ -185,7 +192,7 @@ $string['seal'] = 'Seal';
$string['sigline'] = 'line';
$string['signature'] = 'Signature';
$string['statement'] = 'has completed the course';
$string['summaryofattempts'] = 'Summary of Previously Received Certificates';
$string['summaryofattempts'] = 'Summary of previously received certificates';
$string['textoptions'] = 'Text Options';
$string['title'] = 'CERTIFICATE of ACHIEVEMENT';
$string['to'] = 'Awarded to';
@ -203,5 +210,3 @@ $string['viewcertificateviews'] = 'View {$a} issued certificates';
$string['viewed'] = 'You received this certificate on:';
$string['viewtranscript'] = 'View Certificates';
$string['watermark'] = 'Watermark';
$string['completionrequired'] = "<p><strong>You have not completed the course.</strong></p><br/>
<p>While the criteria for course completion are not met, the certificate can not be issued.</p>";

1
lang/pt_br/certificate.php

@ -69,6 +69,7 @@ $string['coursename'] = 'Course';
$string['coursetimereq'] = 'Required minutes in course';
$string['coursetimereq_help'] = 'Enter here the minimum amount of time, in minutes, that a student must be logged into the course before they will be able to receive the certificate.';
$string['credithours'] = 'Credit Hours';
$string['crontask'] = 'Atualizar usuários para gerar certificados';
$string['customtext'] = 'Custom Text';
$string['customtext_help'] = 'If you want the certificate to print different names for the teacher than those who are assigned
the role of teacher, do not select Print Teacher or any signature image except for the line image. Enter the teacher names in this text box as you would like them to appear. By default, this text is placed in the lower left of the certificate. The following html tags are available: &lt;br&gt;, &lt;p&gt;, &lt;b&gt;, &lt;i&gt;, &lt;u&gt;, &lt;img&gt; (src and width (or height) are mandatory), &lt;a&gt; (href is mandatory), &lt;font&gt; (possible attributes are: color, (hex color code), face, (arial, times, courier, helvetica, symbol)).';

1353
lib.php

File diff suppressed because it is too large

1293
locallib.php

File diff suppressed because it is too large

BIN
mobile/mod_certificate.zip

Binary file not shown.

9
mod_form.php

@ -18,8 +18,7 @@
/**
* Instance add/edit form
*
* @package mod
* @subpackage certificate
* @package mod_certificate
* @copyright Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
@ -29,7 +28,7 @@ if (!defined('MOODLE_INTERNAL')) {
}
require_once ($CFG->dirroot.'/course/moodleform_mod.php');
require_once($CFG->dirroot.'/mod/certificate/lib.php');
require_once($CFG->dirroot.'/mod/certificate/locallib.php');
class mod_certificate_mod_form extends moodleform_mod {
@ -48,7 +47,7 @@ class mod_certificate_mod_form extends moodleform_mod {
}
$mform->addRule('name', null, 'required', null, 'client');
$this->add_intro_editor(false, get_string('intro', 'certificate'));
$this->standard_intro_elements(get_string('intro', 'certificate'));
// Issue options
$mform->addElement('header', 'issueoptions', get_string('issueoptions', 'certificate'));
@ -136,7 +135,7 @@ class mod_certificate_mod_form extends moodleform_mod {
$orientation = array( 'L' => get_string('landscape', 'certificate'), 'P' => get_string('portrait', 'certificate'));
$mform->addElement('select', 'orientation', get_string('orientation', 'certificate'), $orientation);
$mform->setDefault('orientation', 'landscape');
$mform->setDefault('orientation', 'L');
$mform->addHelpButton('orientation', 'orientation', 'certificate');
$mform->addElement('select', 'borderstyle', get_string('borderstyle', 'certificate'), certificate_get_images(CERT_IMAGE_BORDER));

109
report.php

@ -18,14 +18,13 @@
/**
* Handles viewing the report
*
* @package mod
* @subpackage certificate
* @package mod_certificate
* @copyright Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once('../../config.php');
require_once('lib.php');
require_once('locallib.php');
$id = required_param('id', PARAM_INT); // Course module ID
$sort = optional_param('sort', '', PARAM_RAW);
@ -67,7 +66,7 @@ if (!$certificate = $DB->get_record('certificate', array('id'=> $cm->instance)))
}
// Requires a course login
require_course_login($course->id, false, $cm);
require_login($course, false, $cm);
// Check capabilities
$context = context_module::instance($cm->id);
@ -96,22 +95,23 @@ if (!$download) {
$page = $perpage = 0;
}
add_to_log($course->id, 'certificate', 'view', "report.php?id=$cm->id", '$certificate->id', $cm->id);
// Ensure there are issues to display, if not display notice
if (!$users = certificate_get_issues($certificate->id, $DB->sql_fullname(), $groupmode, $cm, $page, $perpage)) {
echo $OUTPUT->header();
groups_print_activity_menu($cm, $CFG->wwwroot . '/mod/certificate/report.php?id='.$id);
notify(get_string('nocertificatesissued', 'certificate'));
echo $OUTPUT->notification(get_string('nocertificatesissued', 'certificate'));
echo $OUTPUT->footer($course);
exit();
}
// Get extra fields to show the user.
$extrafields = get_extra_user_fields($context);
if ($download == "ods") {
require_once("$CFG->libdir/odslib.class.php");
// Calculate file name
$filename = clean_filename("$course->shortname " . rtrim($certificate->name, '.') . '.ods');
$filename = certificate_get_certificate_filename($certificate, $cm, $course) . '.ods';
// Creating a workbook
$workbook = new MoodleODSWorkbook("-");
// Send HTTP headers
@ -122,11 +122,15 @@ if ($download == "ods") {
// 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, $strdate);
$myxls->write_string(0, 5, $strgrade);
$myxls->write_string(0, 6, $strcode);
$nextposition = 2;
foreach ($extrafields as $field) {
$myxls->write_string(0, $nextposition, get_user_field_name($field));
$nextposition++;
}
$myxls->write_string(0, $nextposition, get_string("group"));
$myxls->write_string(0, $nextposition + 1, $strdate);
$myxls->write_string(0, $nextposition + 2, $strgrade);
$myxls->write_string(0, $nextposition + 3, $strcode);
// Generate the data for the body of the spreadsheet
$i = 0;
@ -135,18 +139,21 @@ if ($download == "ods") {
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);
$nextposition = 2;
foreach ($extrafields as $field) {
$myxls->write_string($row, $nextposition, $user->$field);
$nextposition++;
}
$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, certificate_get_grade($certificate, $course, $user->id));
$myxls->write_string($row, 6, $user->code);
$myxls->write_string($row, $nextposition, $ug2);
$myxls->write_string($row, $nextposition + 1, userdate($user->timecreated));
$myxls->write_string($row, $nextposition + 2, certificate_get_grade($certificate, $course, $user->id));
$myxls->write_string($row, $nextposition + 3, $user->code);
$row++;
}
$pos = 6;
@ -160,7 +167,7 @@ if ($download == "xls") {
require_once("$CFG->libdir/excellib.class.php");
// Calculate file name
$filename = clean_filename("$course->shortname " . rtrim($certificate->name, '.') . '.xls');
$filename = certificate_get_certificate_filename($certificate, $cm, $course) . '.xls';
// Creating a workbook
$workbook = new MoodleExcelWorkbook("-");
// Send HTTP headers
@ -171,11 +178,15 @@ if ($download == "xls") {
// 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, $strdate);
$myxls->write_string(0, 5, $strgrade);
$myxls->write_string(0, 6, $strcode);
$nextposition = 2;
foreach ($extrafields as $field) {
$myxls->write_string(0, $nextposition, get_user_field_name($field));
$nextposition++;
}
$myxls->write_string(0, $nextposition, get_string("group"));
$myxls->write_string(0, $nextposition + 1, $strdate);
$myxls->write_string(0, $nextposition + 2, $strgrade);
$myxls->write_string(0, $nextposition + 3, $strcode);
// Generate the data for the body of the spreadsheet
$i = 0;
@ -184,18 +195,21 @@ if ($download == "xls") {
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);
$nextposition = 2;
foreach ($extrafields as $field) {
$myxls->write_string($row, $nextposition, $user->$field);
$nextposition++;
}
$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, certificate_get_grade($certificate, $course, $user->id));
$myxls->write_string($row, 6, $user->code);
$myxls->write_string($row, $nextposition, $ug2);
$myxls->write_string($row, $nextposition + 1, userdate($user->timecreated));
$myxls->write_string($row, $nextposition + 2, certificate_get_grade($certificate, $course, $user->id));
$myxls->write_string($row, $nextposition + 3, $user->code);
$row++;
}
$pos = 6;
@ -206,7 +220,7 @@ if ($download == "xls") {
}
if ($download == "txt") {
$filename = clean_filename("$course->shortname " . rtrim($certificate->name, '.') . '.txt');
$filename = certificate_get_certificate_filename($certificate, $cm, $course) . '.txt';
header("Content-Type: application/download\n");
header("Content-Disposition: attachment; filename=\"$filename\"");
@ -215,7 +229,10 @@ if ($download == "txt") {
header("Pragma: public");
// Print names of all the fields
echo get_string("lastname"). "\t" .get_string("firstname") . "\t". get_string("idnumber") . "\t";
echo get_string("lastname"). "\t" .get_string("firstname") . "\t";
foreach ($extrafields as $field) {
echo get_user_field_name($field) . "\t";
}
echo get_string("group"). "\t";
echo $strdate. "\t";
echo $strgrade. "\t";
@ -226,12 +243,10 @@ if ($download == "txt") {
$row=1;
if ($users) foreach ($users as $user) {
echo $user->lastname;
echo "\t" . $user->firstname;
$studentid = " ";
if (!empty($user->idnumber)) {
$studentid = $user->idnumber;
echo "\t" . $user->firstname . "\t";
foreach ($extrafields as $field) {
echo $user->$field . "\t";
}
echo "\t" . $studentid . "\t";
$ug2 = '';
if ($usergrps = groups_get_all_groups($course->id, $user->id)) {
foreach ($usergrps as $ug) {
@ -253,13 +268,25 @@ $usercount = count(certificate_get_issues($certificate->id, $DB->sql_fullname(),
$table = new html_table();
$table->width = "95%";
$table->tablealign = "center";
$table->head = array($strto, $strdate, $strgrade, $strcode);
$table->align = array("left", "left", "center", "center");
$table->head = array($strto);
$table->align = array('left');
foreach ($extrafields as $field) {
$table->head[] = get_user_field_name($field);
$table->align[] = 'left';
}
$table->head = array_merge($table->head, array($strdate, $strgrade, $strcode));
$table->align = array_merge($table->align, array('left', 'center', 'center'));
foreach ($users as $user) {
$name = $OUTPUT->user_picture($user) . fullname($user);
$date = userdate($user->timecreated) . certificate_print_user_files($certificate, $user->id, $context->id);
$code = $user->code;
$table->data[] = array ($name, $date, certificate_get_grade($certificate, $course, $user->id), $code);
$data = array();
$data[] = $name;
foreach ($extrafields as $field) {
$data[] = $user->$field;
}
$data = array_merge($data, array($date, certificate_get_grade($certificate, $course, $user->id), $code));
$table->data[] = $data;
}
// Create table to store buttons

25
review.php

@ -18,14 +18,13 @@
/**
* This page reviews a certificate
*
* @package mod
* @subpackage certificate
* @package mod_certificate
* @copyright Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once('../../config.php');
require_once('lib.php');
require_once('locallib.php');
require_once("$CFG->libdir/pdflib.php");
// Retrieve any variables that are passed
@ -44,11 +43,12 @@ if (!$certificate = $DB->get_record('certificate', array('id'=> $cm->instance)))
print_error('course module is incorrect');
}
// Requires login
require_login();
// Requires a course login
require_login($course, true, $cm);
// Check the capabilities
$context = context_module::instance($cm->id);
//require_capability('mod/certificate:view', $context);
// Initialize $PAGE, compute blocks
$PAGE->set_url('/mod/certificate/review.php', array('id' => $cm->id));
@ -67,17 +67,22 @@ if (!$certrecord = $DB->get_record('certificate_issues', array('userid' => $USER
require ("$CFG->dirroot/mod/certificate/type/$certificate->certificatetype/certificate.php");
if ($action) {
// Remove full-stop at the end if it exists, to avoid "..pdf" being created and being filtered by clean_filename
$certname = rtrim($certificate->name, '.');
$filename = clean_filename("$certname.pdf");
$pdf->Output($filename, 'I'); // open in browser
$filename = certificate_get_certificate_filename($certificate, $cm, $course) . '.pdf';
$filecontents = $pdf->Output('', 'S');
// Open in browser.
send_file($filecontents, $filename, 0, 0, true, false, 'application/pdf');
exit();
}
echo $OUTPUT->header();
$reviewurl = new moodle_url('/mod/certificate/review.php', array('id' => $cm->id));
groups_print_activity_menu($cm, $reviewurl);
$currentgroup = groups_get_activity_group($cm);
$groupmode = groups_get_activity_groupmode($cm);
if (has_capability('mod/certificate:manage', $context)) {
$numusers = count(certificate_get_issues($certificate->id, 'ci.timecreated ASC', '', $cm));
$numusers = count(certificate_get_issues($certificate->id, 'ci.timecreated ASC', $groupmode, $cm));
$url = html_writer::tag('a', get_string('viewcertificateviews', 'certificate', $numusers),
array('href' => $CFG->wwwroot . '/mod/certificate/report.php?id=' . $cm->id));
echo html_writer::tag('div', $url, array('class' => 'reportlink'));

17
settings.php

@ -18,17 +18,22 @@
/**
* Provides some custom settings for the certificate module
*
* @package mod
* @subpackage certificate
* @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->dirroot.'/mod/certificate/adminsetting.class.php');
if ($ADMIN->fulltree) {
$settings->add(new mod_certificate_admin_setting_upload('certificate/uploadimage',
get_string('uploadimage', 'certificate'), get_string('uploadimagedesc', 'certificate'), ''));
$settings->add(new mod_certificate_admin_setting_upload('certificate/uploadimage',
get_string('uploadimage', 'mod_certificate'), get_string('uploadimagedesc', 'certificate'), ''));
?>
$settings->add(new mod_certificate_admin_setting_font('certificate/fontsans',
get_string('fontsans', 'mod_certificate'), get_string('fontsans_desc', 'mod_certificate'), 'freesans'));
$settings->add(new mod_certificate_admin_setting_font('certificate/fontserif',
get_string('fontserif', 'mod_certificate'), get_string('fontserif_desc', 'mod_certificate'), 'freeserif'));
}

91
tests/generator/lib.php

@ -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);
}
}

56
tests/generator_test.php

@ -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);
}
}

34
type/A4_embedded/certificate.php

@ -18,15 +18,12 @@
/**
* A4_embedded certificate type
*
* @package mod
* @subpackage certificate
* @package mod_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
}
defined('MOODLE_INTERNAL') || die();
$pdf = new PDF($certificate->orientation, 'mm', 'A4', true, 'UTF-8', false);
@ -77,6 +74,10 @@ if ($certificate->orientation == 'L') {
$codey = 250;
}
// Get font families.
$fontsans = get_config('certificate', 'fontsans');
$fontserif = get_config('certificate', 'fontserif');
// Add images and lines
certificate_print_image($pdf, $certificate, CERT_IMAGE_BORDER, $brdrx, $brdry, $brdrw, $brdrh);
certificate_draw_frame($pdf, $certificate);
@ -89,29 +90,28 @@ certificate_print_image($pdf, $certificate, CERT_IMAGE_SIGNATURE, $sigx, $sigy,
// Add text
$pdf->SetTextColor(0, 0, 120);
certificate_print_text($pdf, $x, $y, 'C', 'freesans', '', 30, get_string('title', 'certificate'));
certificate_print_text($pdf, $x, $y, 'C', $fontsans, '', 30, get_string('title', 'certificate'));
$pdf->SetTextColor(0, 0, 0);
certificate_print_text($pdf, $x, $y + 20, 'C', 'freeserif', '', 20, get_string('certify', 'certificate'));
certificate_print_text($pdf, $x, $y + 36, 'C', 'freesans', '', 30, fullname($USER));
certificate_print_text($pdf, $x, $y + 55, 'C', 'freesans', '', 20, get_string('statement', 'certificate'));
certificate_print_text($pdf, $x, $y + 72, 'C', 'freesans', '', 20, $course->fullname);
certificate_print_text($pdf, $x, $y + 92, 'C', 'freesans', '', 14, certificate_get_date($certificate, $certrecord, $course));
certificate_print_text($pdf, $x, $y + 102, 'C', 'freeserif', '', 10, certificate_get_grade($certificate, $course));
certificate_print_text($pdf, $x, $y + 112, 'C', 'freeserif', '', 10, certificate_get_outcome($certificate, $course));
certificate_print_text($pdf, $x, $y + 20, 'C', $fontserif, '', 20, get_string('certify', 'certificate'));
certificate_print_text($pdf, $x, $y + 36, 'C', $fontsans, '', 30, fullname($USER));
certificate_print_text($pdf, $x, $y + 55, 'C', $fontsans, '', 20, get_string('statement', 'certificate'));
certificate_print_text($pdf, $x, $y + 72, 'C', $fontsans, '', 20, format_string($course->fullname));
certificate_print_text($pdf, $x, $y + 92, 'C', $fontsans, '', 14, certificate_get_date($certificate, $certrecord, $course));
certificate_print_text($pdf, $x, $y + 102, 'C', $fontserif, '', 10, certificate_get_grade($certificate, $course));
certificate_print_text($pdf, $x, $y + 112, 'C', $fontserif, '', 10, certificate_get_outcome($certificate, $course));
if ($certificate->printhours) {
certificate_print_text($pdf, $x, $y + 122, 'C', 'freeserif', '', 10, get_string('credithours', 'certificate') . ': ' . $certificate->printhours);
certificate_print_text($pdf, $x, $y + 122, 'C', $fontserif, '', 10, get_string('credithours', 'certificate') . ': ' . $certificate->printhours);
}
certificate_print_text($pdf, $x, $codey, 'C', 'freeserif', '', 10, certificate_get_code($certificate, $certrecord));
certificate_print_text($pdf, $x, $codey, 'C', $fontserif, '', 10, certificate_get_code($certificate, $certrecord));
$i = 0;
if ($certificate->printteacher) {
$context = context_module::instance($cm->id);
if ($teachers = get_users_by_capability($context, 'mod/certificate:printteacher', '', $sort = 'u.lastname ASC', '', '', '', '', false)) {
foreach ($teachers as $teacher) {
$i++;
certificate_print_text($pdf, $sigx, $sigy + ($i * 4), 'L', 'freeserif', '', 12, fullname($teacher));
certificate_print_text($pdf, $sigx, $sigy + ($i * 4), 'L', $fontserif, '', 12, fullname($teacher));
}
}
}
certificate_print_text($pdf, $custx, $custy, 'L', null, null, null, $certificate->customtext);
?>

10
type/A4_non_embedded/certificate.php

@ -18,15 +18,12 @@
/**
* A4_non_embedded certificate type
*
* @package mod
* @subpackage certificate
* @package mod_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
}
defined('MOODLE_INTERNAL') || die();
$pdf = new PDF($certificate->orientation, 'mm', 'A4', true, 'UTF-8', false);
@ -94,7 +91,7 @@ $pdf->SetTextColor(0, 0, 0);
certificate_print_text($pdf, $x, $y + 20, 'C', 'Times', '', 20, get_string('certify', 'certificate'));
certificate_print_text($pdf, $x, $y + 36, 'C', 'Helvetica', '', 30, fullname($USER));
certificate_print_text($pdf, $x, $y + 55, 'C', 'Helvetica', '', 20, get_string('statement', 'certificate'));
certificate_print_text($pdf, $x, $y + 72, 'C', 'Helvetica', '', 20, $course->fullname);
certificate_print_text($pdf, $x, $y + 72, 'C', 'Helvetica', '', 20, format_string($course->fullname));
certificate_print_text($pdf, $x, $y + 92, 'C', 'Helvetica', '', 14, certificate_get_date($certificate, $certrecord, $course));
certificate_print_text($pdf, $x, $y + 102, 'C', 'Times', '', 10, certificate_get_grade($certificate, $course));
certificate_print_text($pdf, $x, $y + 112, 'C', 'Times', '', 10, certificate_get_outcome($certificate, $course));
@ -114,4 +111,3 @@ if ($certificate->printteacher) {
}
certificate_print_text($pdf, $custx, $custy, 'L', null, null, null, $certificate->customtext);
?>

182
type/ILB_Com_tutoria/certificate.php

@ -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');
?>

26
type/ILB_Com_tutoria_2014/certificate.php

@ -57,6 +57,30 @@ $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);
@ -124,7 +148,7 @@ certificate_print_image($pdf, $certificate, CERT_IMAGE_SIGNATURE, $sigx, $sigy,
$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º {$USER->profile['cpf']},");
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}");

26
type/ILB_Sem_tutoria_2014/certificate.php

@ -59,6 +59,30 @@ if ($certificate->datefmt == 1) {
$start_date = userdate($start_date, $fmt);
$end_date = userdate($end_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);
@ -125,7 +149,7 @@ certificate_print_image($pdf, $certificate, CERT_IMAGE_SIGNATURE, $sigx, $sigy,
$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º {$USER->profile['cpf']}");
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 sem 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}");

27
type/ILB_presencial_2016/certificate.php

@ -55,6 +55,31 @@ if ($certificate->datefmt == 1) {
$start_date = userdate($start_date, $fmt);
$end_date = userdate($end_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);
@ -121,7 +146,7 @@ certificate_print_image($pdf, $certificate, CERT_IMAGE_SIGNATURE, $sigx, $sigy,
$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º {$USER->profile['cpf']}");
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 presencial, o curso");
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}");

28
type/Oficinas_Interlegis/certificate.php

@ -41,6 +41,32 @@ $style = <<<EOT
</style>
EOT
*/
//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);
@ -107,7 +133,7 @@ certificate_print_image($pdf, $certificate, CERT_IMAGE_SIGNATURE, $sigx, $sigy,
$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º {$USER->profile['cpf']}");
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, "participou, na modalidade presencial, da oficina");
certificate_print_text($pdf, $x, $y + 45, 'C', 'freesans', 'B', 18, mb_strtoupper($course->fullname, 'UTF-8'));
$tagvs = array('p' => array(0 => array('h' => 0, 'n' => 0), 1 => array('h' => 0, 'n'=> 0)));

9
type/PFG_FC2/certificate.php

@ -54,6 +54,13 @@ if ($certificate->datefmt == 1) {
$start_date = userdate($start_date, $fmt);
$end_date = userdate($end_date, $fmt);
require_once($CFG->dirroot.'/user/profile/field/cpf/field.class.php');
$formfield = new profile_field_cpf('8', $USER->id);
$cpf = $formfield->display_data();
$pdf = new PDF($certificate->orientation, 'mm', 'A4', true, 'UTF-8', false);
$pdf->SetTitle($certificate->name);
@ -120,7 +127,7 @@ certificate_print_image($pdf, $certificate, CERT_IMAGE_SIGNATURE, $sigx, $sigy,
$pdf->SetTextColor(0, 0, 0);
certificate_print_text($pdf, $x, $y, 'C', 'freesans', '', 20, get_string('title', 'certificate'));
certificate_print_text($pdf, $x, $y + 25, 'C', 'freesans', '', 18, get_string('certify', 'certificate'));
certificate_print_text($pdf, $x, $y + 35, 'C', 'freesans', 'B', 18, mb_strtoupper(fullname($USER), 'UTF-8').", CPF nº {$USER->profile['cpf']},");
certificate_print_text($pdf, $x, $y + 35, 'C', 'freesans', 'B', 18, mb_strtoupper(fullname($USER), 'UTF-8').", CPF nº $cpf");
certificate_print_text($pdf, $x, $y + 45, 'C', 'freesans', '', 18, "concluiu com aproveitamento o");
certificate_print_text($pdf, $x, $y + 55, 'C', 'freesans', 'B', 18, mb_strtoupper($course->fullname, 'UTF-8'));
certificate_print_text($pdf, $x, $y + 65, 'C', 'freesans', '', 18, "com carga horária de 129 horas/aula.");

7
type/PFG_FC2_2016/certificate.php

@ -54,6 +54,11 @@ if ($certificate->datefmt == 1) {
$start_date = userdate($start_date, $fmt);
$end_date = userdate($end_date, $fmt);
require_once($CFG->dirroot.'/user/profile/field/cpf/field.class.php');
$formfield = new profile_field_cpf('8', $USER->id);
$cpf = $formfield->display_data();
$pdf = new PDF($certificate->orientation, 'mm', 'A4', true, 'UTF-8', false);
$pdf->SetTitle($certificate->name);
@ -120,7 +125,7 @@ certificate_print_image($pdf, $certificate, CERT_IMAGE_SIGNATURE, $sigx, $sigy,
$pdf->SetTextColor(0, 0, 0);
certificate_print_text($pdf, $x, $y, 'C', 'freesans', '', 20, get_string('title', 'certificate'));
certificate_print_text($pdf, $x, $y + 25, 'C', 'freesans', '', 18, get_string('certify', 'certificate'));
certificate_print_text($pdf, $x, $y + 35, 'C', 'freesans', 'B', 18, mb_strtoupper(fullname($USER), 'UTF-8').", CPF nº {$USER->profile['cpf']},");
certificate_print_text($pdf, $x, $y + 35, 'C', 'freesans', 'B', 18, mb_strtoupper(fullname($USER), 'UTF-8').", CPF nº $cpf");
certificate_print_text($pdf, $x, $y + 45, 'C', 'freesans', '', 18, "concluiu com aproveitamento o");
certificate_print_text($pdf, $x, $y + 55, 'C', 'freesans', 'B', 18, mb_strtoupper($course->fullname, 'UTF-8'));
certificate_print_text($pdf, $x, $y + 65, 'C', 'freesans', '', 18, "com carga horária de {$certificate->printhours}.");

7
type/PFG_FC3/certificate.php

@ -54,6 +54,11 @@ if ($certificate->datefmt == 1) {
$start_date = userdate($start_date, $fmt);
$end_date = userdate($end_date, $fmt);
require_once($CFG->dirroot.'/user/profile/field/cpf/field.class.php');
$formfield = new profile_field_cpf('8', $USER->id);
$cpf = $formfield->display_data();
$pdf = new PDF($certificate->orientation, 'mm', 'A4', true, 'UTF-8', false);
$pdf->SetTitle($certificate->name);
@ -120,7 +125,7 @@ certificate_print_image($pdf, $certificate, CERT_IMAGE_SIGNATURE, $sigx, $sigy,
$pdf->SetTextColor(0, 0, 0);
certificate_print_text($pdf, $x, $y, 'C', 'freesans', '', 20, get_string('title', 'certificate'));
certificate_print_text($pdf, $x, $y + 25, 'C', 'freesans', '', 18, get_string('certify', 'certificate'));
certificate_print_text($pdf, $x, $y + 35, 'C', 'freesans', 'B', 18, mb_strtoupper(fullname($USER), 'UTF-8').", CPF nº {$USER->profile['cpf']},");
certificate_print_text($pdf, $x, $y + 35, 'C', 'freesans', 'B', 18, mb_strtoupper(fullname($USER), 'UTF-8').", CPF nº $cpf");
certificate_print_text($pdf, $x, $y + 45, 'C', 'freesans', '', 18, "concluiu com aproveitamento o");
certificate_print_text($pdf, $x, $y + 55, 'C', 'freesans', 'B', 18, mb_strtoupper($course->fullname, 'UTF-8'));
certificate_print_text($pdf, $x, $y + 65, 'C', 'freesans', '', 18, "com carga horária de 86 horas/aula.");

31
type/cert_comtutoria/certificate.php

@ -41,6 +41,35 @@ $style = <<<EOT
</style>
EOT
*/
//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);
@ -107,7 +136,7 @@ certificate_print_image($pdf, $certificate, CERT_IMAGE_SIGNATURE, $sigx, $sigy,
$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º {$USER->profile['cpf']}");
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, ".certificate_get_grade($certificate, $course).',');
certificate_print_text($pdf, $x, $y + 45, 'C', 'freesans', 'B', 18, 'o curso com tutoria '.mb_strtoupper($course->fullname, 'UTF-8'));
$tagvs = array('p' => array(0 => array('h' => 0, 'n' => 0), 1 => array('h' => 0, 'n'=> 0)));

42
type/cert_presencial/certificate.php

@ -32,14 +32,29 @@ $group = end(groups_get_all_groups($course->id, $USER->id));
$group_name = format_string($group->name);
$group_description = format_text($group->description, $group->descriptiontext);
#Obtem a nota do aluno, se o curso estiver configurado para gerar
#certificado com nota. Do contrário, o campo virá sempre em branco.
$grade=certificate_get_grade($certificate, $course);
if( $grade != '' ) {
#Se houver nota, acrescenta vírgulas antes e depois
$grade = $grade . ', ';
//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');
/*
$style = <<<EOT
@ -51,6 +66,16 @@ $style = <<<EOT
</style>
EOT
*/
#Obtem a nota do aluno, se o curso estiver configurado para gerar
#certificado com nota. Do contrário, o campo virá sempre em branco.
$grade=certificate_get_grade($certificate, $course);
if( $grade != '' ) {
#Se houver nota, acrescenta vírgulas antes e depois
$grade = $grade . ', ';
}
$pdf = new PDF($certificate->orientation, 'mm', 'A4', true, 'UTF-8', false);
$pdf->SetTitle($certificate->name);
@ -117,8 +142,9 @@ certificate_print_image($pdf, $certificate, CERT_IMAGE_SIGNATURE, $sigx, $sigy,
$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º {$USER->profile['cpf']}");
certificate_print_text($pdf, $x, $y + 35, 'C', 'freesans', '', 18, "realizou, na modalidade presencial, " . $grade . "o curso");
//certificate_print_text($pdf, $x, $y + 25, 'C', 'freesans', 'B', 18, mb_strtoupper(fullname($USER), 'UTF-8').", CPF nº {$USER->profile['cpf']}");
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 presencial, ". $grade ."o curso");
certificate_print_text($pdf, $x, $y + 45, 'C', 'freesans', 'B', 18, mb_strtoupper($course->fullname, 'UTF-8'));
$tagvs = array('p' => array(0 => array('h' => 0, 'n' => 0), 1 => array('h' => 0, 'n'=> 0)));
$pdf->setHtmlVSpace($tagvs);

28
type/cert_presencial_rasf/certificate.php

@ -41,6 +41,32 @@ $style = <<<EOT
</style>
EOT
*/
//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);
@ -107,7 +133,7 @@ certificate_print_image($pdf, $certificate, CERT_IMAGE_SIGNATURE, $sigx, $sigy,
$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('certifyilb', 'certificate'));
certificate_print_text($pdf, $x, $y + 45, 'C', 'freesans', 'B', 18, mb_strtoupper(fullname($USER), 'UTF-8').", CPF nº {$USER->profile['cpf']}");
certificate_print_text($pdf, $x, $y + 45, 'C', 'freesans', 'B', 18, mb_strtoupper(fullname($USER), 'UTF-8').", CPF nº $cpf");
certificate_print_text($pdf, $x, $y + 55, 'C', 'freesans', '', 18, "realizou, na modalidade presencial, ".certificate_get_grade($certificate, $course).", o curso");
certificate_print_text($pdf, $x, $y + 65, 'C', 'freesans', 'B', 18, mb_strtoupper($course->fullname, 'UTF-8'));
$tagvs = array('p' => array(0 => array('h' => 0, 'n' => 0), 1 => array('h' => 0, 'n'=> 0)));

36
type/letter_embedded/certificate.php

@ -18,17 +18,14 @@
/**
* letter_embedded certificate type
*
* @package mod
* @subpackage certificate
* @package mod_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
}
defined('MOODLE_INTERNAL') || die();
$pdf = new PDF($certificate->orientation, 'pt', 'Letter', true, 'UTF-8', false);
$pdf = new PDF($certificate->orientation, 'pt', 'LETTER', true, 'UTF-8', false);
$pdf->SetTitle($certificate->name);
$pdf->SetProtection(array('modify'));
@ -77,6 +74,10 @@ if ($certificate->orientation == 'L') {
$codey = 660;
}
// Get font families.
$fontsans = get_config('certificate', 'fontsans');
$fontserif = get_config('certificate', 'fontserif');
// Add images and lines
certificate_print_image($pdf, $certificate, CERT_IMAGE_BORDER, $brdrx, $brdry, $brdrw, $brdrh);
certificate_draw_frame_letter($pdf, $certificate);
@ -89,29 +90,28 @@ certificate_print_image($pdf, $certificate, CERT_IMAGE_SIGNATURE, $sigx, $sigy,
// Add text
$pdf->SetTextColor(0, 0, 120);
certificate_print_text($pdf, $x, $y, 'C', 'freesans', '', 30, get_string('title', 'certificate'));
certificate_print_text($pdf, $x, $y, 'C', $fontsans, '', 30, get_string('title', 'certificate'));
$pdf->SetTextColor(0, 0, 0);
certificate_print_text($pdf, $x, $y + 55, 'C', 'freeserif', '', 20, get_string('certify', 'certificate'));
certificate_print_text($pdf, $x, $y + 105, 'C', 'freeserif', '', 30, fullname($USER));
certificate_print_text($pdf, $x, $y + 155, 'C', 'freeserif', '', 20, get_string('statement', 'certificate'));
certificate_print_text($pdf, $x, $y + 205, 'C', 'freeserif', '', 20, $course->fullname);
certificate_print_text($pdf, $x, $y + 255, 'C', 'freeserif', '', 14, certificate_get_date($certificate, $certrecord, $course));
certificate_print_text($pdf, $x, $y + 283, 'C', 'freeserif', '', 10, certificate_get_grade($certificate, $course));
certificate_print_text($pdf, $x, $y + 311, 'C', 'freeserif', '', 10, certificate_get_outcome($certificate, $course));
certificate_print_text($pdf, $x, $y + 55, 'C', $fontserif, '', 20, get_string('certify', 'certificate'));
certificate_print_text($pdf, $x, $y + 105, 'C', $fontserif, '', 30, fullname($USER));
certificate_print_text($pdf, $x, $y + 155, 'C', $fontserif, '', 20, get_string('statement', 'certificate'));
certificate_print_text($pdf, $x, $y + 205, 'C', $fontserif, '', 20, format_string($course->fullname));
certificate_print_text($pdf, $x, $y + 255, 'C', $fontserif, '', 14, certificate_get_date($certificate, $certrecord, $course));
certificate_print_text($pdf, $x, $y + 283, 'C', $fontserif, '', 10, certificate_get_grade($certificate, $course));
certificate_print_text($pdf, $x, $y + 311, 'C', $fontserif, '', 10, certificate_get_outcome($certificate, $course));
if ($certificate->printhours) {
certificate_print_text($pdf, $x, $y + 339, 'C', 'freeserif', '', 10, get_string('credithours', 'certificate') . ': ' . $certificate->printhours);
certificate_print_text($pdf, $x, $y + 339, 'C', $fontserif, '', 10, get_string('credithours', 'certificate') . ': ' . $certificate->printhours);
}
certificate_print_text($pdf, $x, $codey, 'C', 'freeserif', '', 10, certificate_get_code($certificate, $certrecord));
certificate_print_text($pdf, $x, $codey, 'C', $fontserif, '', 10, certificate_get_code($certificate, $certrecord));
$i = 0;
if ($certificate->printteacher) {
$context = context_module::instance($cm->id);
if ($teachers = get_users_by_capability($context, 'mod/certificate:printteacher', '', $sort = 'u.lastname ASC', '', '', '', '', false)) {
foreach ($teachers as $teacher) {
$i++;
certificate_print_text($pdf, $sigx, $sigy + ($i * 12), 'L', 'freeserif', '', 12, fullname($teacher));
certificate_print_text($pdf, $sigx, $sigy + ($i * 12), 'L', $fontserif, '', 12, fullname($teacher));
}
}
}
certificate_print_text($pdf, $custx, $custy, 'L', null, null, null, $certificate->customtext);
?>

12
type/letter_non_embedded/certificate.php

@ -18,17 +18,14 @@
/**
* letter_non_embedded certificate type
*
* @package mod
* @subpackage certificate
* @package mod_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
}
defined('MOODLE_INTERNAL') || die();
$pdf = new PDF($certificate->orientation, 'pt', 'Letter', true, 'UTF-8', false);
$pdf = new PDF($certificate->orientation, 'pt', 'LETTER', true, 'UTF-8', false);
$pdf->SetTitle($certificate->name);
$pdf->SetProtection(array('modify'));
@ -94,7 +91,7 @@ $pdf->SetTextColor(0, 0, 0);
certificate_print_text($pdf, $x, $y + 55, 'C', 'Times', '', 20, get_string('certify', 'certificate'));
certificate_print_text($pdf, $x, $y + 105, 'C', 'Helvetica', '', 30, fullname($USER));
certificate_print_text($pdf, $x, $y + 155, 'C', 'Helvetica', '', 20, get_string('statement', 'certificate'));
certificate_print_text($pdf, $x, $y + 205, 'C', 'Helvetica', '', 20, $course->fullname);
certificate_print_text($pdf, $x, $y + 205, 'C', 'Helvetica', '', 20, format_string($course->fullname));
certificate_print_text($pdf, $x, $y + 255, 'C', 'Helvetica', '', 14, certificate_get_date($certificate, $certrecord, $course));
certificate_print_text($pdf, $x, $y + 283, 'C', 'Times', '', 10, certificate_get_grade($certificate, $course));
certificate_print_text($pdf, $x, $y + 311, 'C', 'Times', '', 10, certificate_get_outcome($certificate, $course));
@ -114,4 +111,3 @@ if ($certificate->printteacher) {
}
certificate_print_text($pdf, $custx, $custy, 'L', null, null, null, $certificate->customtext);
?>

6
upload_image.php

@ -18,14 +18,13 @@
/**
* Handles uploading files
*
* @package mod
* @subpackage certificate
* @package mod_certificate
* @copyright Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require('../../config.php');
require_once($CFG->dirroot.'/mod/certificate/lib.php');
require_once($CFG->dirroot.'/mod/certificate/locallib.php');
require_once($CFG->dirroot.'/mod/certificate/upload_image_form.php');
require_login();
@ -63,4 +62,3 @@ if ($upload_form->is_cancelled()) {
echo $OUTPUT->header();
echo $upload_form->display();
echo $OUTPUT->footer();
?>

5
upload_image_form.php

@ -18,8 +18,7 @@
/**
* Handles uploading files
*
* @package mod
* @subpackage certificate
* @package mod_certificate
* @copyright Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
@ -29,7 +28,7 @@ if (!defined('MOODLE_INTERNAL')) {
}
require_once($CFG->libdir.'/formslib.php');
require_once($CFG->dirroot.'/mod/certificate/lib.php');
require_once($CFG->dirroot.'/mod/certificate/locallib.php');
class mod_certificate_upload_image_form extends moodleform {

17
version.php

@ -18,16 +18,17 @@
/**
* Code fragment to define the version of the certificate module
*
* @package mod
* @subpackage certificate
* @package mod_certificate
* @copyright Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or late
*/
$module->version = 2013102300; // The current module version (Date: YYYYMMDDXX)
$module->requires = 2012120300; // Requires this Moodle version
$module->cron = 12 * 60 * 60; // Period for cron to check this module (secs) 12 hours
$module->component = 'mod_certificate';
defined('MOODLE_INTERNAL') || die();
$module->maturity = MATURITY_STABLE;
$module->release = "Stable"; // User-friendly version number
$plugin->version = 2018040201; // The current module version (Date: YYYYMMDDXX)
$plugin->requires = 2016052300; // Requires this Moodle version (3.1)
$plugin->cron = 12*60*20; // Period for cron to check this module (secs)
$plugin->component = 'mod_certificate';
$plugin->maturity = MATURITY_STABLE;
$plugin->release = "Master (Build: 2018040201)"; // User-friendly version number

62
view.php

@ -18,15 +18,14 @@
/**
* Handles viewing a certificate
*
* @package mod
* @subpackage certificate
* @package mod_certificate
* @copyright Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once("../../config.php");
require_once("$CFG->dirroot/mod/certificate/locallib.php");
require_once("$CFG->dirroot/mod/certificate/deprecatedlib.php");
require_once("$CFG->dirroot/mod/certificate/lib.php");
require_once("$CFG->libdir/pdflib.php");
$id = required_param('id', PARAM_INT); // Course Module ID
@ -43,12 +42,18 @@ if (!$certificate = $DB->get_record('certificate', array('id'=> $cm->instance)))
print_error('course module is incorrect');
}
require_login($course->id, false, $cm);
require_login($course, false, $cm);
$context = context_module::instance($cm->id);
require_capability('mod/certificate:view', $context);
// log update
add_to_log($course->id, 'certificate', 'view', "view.php?id=$cm->id", $certificate->id, $cm->id);
$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);
@ -59,9 +64,6 @@ $PAGE->set_cm($cm);
$PAGE->set_title(format_string($certificate->name));
$PAGE->set_heading(format_string($course->fullname));
// Set the context
$context = context_module::instance($cm->id);
if (($edit != -1) and $PAGE->user_allowed_editing()) {
$USER->editing = $edit;
}
@ -90,6 +92,7 @@ if (!$completion->is_course_complete($USER->id) && !has_capability('mod/certific
die;
}
// Create new certificate record, or return existing record
$certrecord = certificate_get_issue($course, $USER, $certificate, $cm);
@ -101,8 +104,8 @@ require("$CFG->dirroot/mod/certificate/type/$certificate->certificatetype/certif
if (empty($action)) { // Not displaying PDF
echo $OUTPUT->header();
/// find out current groups mode
groups_print_activity_menu($cm, $CFG->wwwroot . '/mod/certificate/view.php?id=' . $cm->id);
$viewurl = new moodle_url('/mod/certificate/view.php', array('id' => $cm->id));
groups_print_activity_menu($cm, $viewurl);
$currentgroup = groups_get_activity_group($cm);
$groupmode = groups_get_activity_groupmode($cm);
@ -129,32 +132,41 @@ if (empty($action)) { // Not displaying PDF
}
echo html_writer::tag('p', $str, array('style' => 'text-align:center'));
$linkname = get_string('getcertificate', 'certificate');
// Add to log, only if we are reissuing
add_to_log($course->id, 'certificate', 'view', "view.php?id=$cm->id", $certificate->id, $cm->id);
$link = new moodle_url('/mod/certificate/view.php?id='.$cm->id.'&action=get');
$button = new single_button($link, $linkname);
$button->add_action(new popup_action('click', $link, 'view'.$cm->id, array('height' => 600, 'width' => 800)));
if ($certificate->delivery != 1) {
$button->add_action(new popup_action('click', $link, 'view' . $cm->id, array('height' => 600, 'width' => 800)));
}
echo html_writer::tag('div', $OUTPUT->render($button), array('style' => 'text-align:center'));
echo $OUTPUT->footer($course);
exit;
} else { // Output to pdf
// Remove full-stop at the end if it exists, to avoid "..pdf" being created and being filtered by clean_filename
$certname = rtrim($certificate->name, '.');
$filename = clean_filename("$certname.pdf");
// No debugging here, sorry.
$CFG->debugdisplay = 0;
@ini_set('display_errors', '0');
@ini_set('log_errors', '1');
$filename = certificate_get_certificate_filename($certificate, $cm, $course) . '.pdf';
// PDF contents are now in $file_contents as a string.
$filecontents = $pdf->Output('', 'S');
if ($certificate->savecert == 1) {
// PDF contents are now in $file_contents as a string
$file_contents = $pdf->Output('', 'S');
certificate_save_pdf($file_contents, $certrecord->id, $filename, $context->id);
certificate_save_pdf($filecontents, $certrecord->id, $filename, $context->id);
}
if ($certificate->delivery == 0) {
$pdf->Output($filename, 'I'); // open in browser
// Open in browser.
send_file($filecontents, $filename, 0, 0, true, false, 'application/pdf');
} elseif ($certificate->delivery == 1) {
$pdf->Output($filename, 'D'); // force download when create
// Force download.
send_file($filecontents, $filename, 0, 0, true, true, 'application/pdf');
} elseif ($certificate->delivery == 2) {
certificate_email_student($course, $certificate, $certrecord, $context);
$pdf->Output($filename, 'I'); // open in browser
$pdf->Output('', 'S'); // send
certificate_email_student($course, $certificate, $certrecord, $context, $filecontents, $filename);
// Open in browser after sending email.
send_file($filecontents, $filename, 0, 0, true, false, 'application/pdf');
}
}

Loading…
Cancel
Save