Huge refactor

1) Every certificate is a template. Before a user would create a certificate then had
the option to save it as a template. This could potentially be chaotic with numerous
users creating templates, making the template system a mess. Now, rather than creating
a certificate first, then saving it as a template, you are always creating a template.
Each template is associated with a context, so depending on where you are creating it
the context is different. This means users in the CONTEXT_MODULE context are creating
a template specific to that module, where as a user creating a template in the
CONTEXT_SYSTEM context would be creating a general template that can be used by others.
This meant we can remove the 'customcert_template_*' db tables. Yay - no duplicated
tables.
2) Created new helper classes and moved functionality there.
3) Moved files to classes/ for autoloading.
4) General tidy up.
This commit is contained in:
Mark Nelson 2016-02-16 17:03:34 +08:00
parent 54584a113c
commit 43d20c0d1b
59 changed files with 2028 additions and 1815 deletions

View file

@ -30,7 +30,7 @@ class element extends \mod_customcert\element {
/**
* This function renders the form elements when adding a customcert element.
*
* @param \mod_customcert_edit_element_form $mform the edit_form instance
* @param \mod_customcert\edit_element_form $mform the edit_form instance
*/
public function render_form_elements($mform) {
// We want to define the width of the border.
@ -39,7 +39,7 @@ class element extends \mod_customcert\element {
$mform->addHelpButton('width', 'width', 'customcertelement_border');
// The only other thing to define is the colour we want the border to be.
parent::render_form_element_colour($mform);
\mod_customcert\element_helper::render_form_element_colour($mform);
}
/**
@ -62,6 +62,8 @@ class element extends \mod_customcert\element {
*
* This function is used to render the element when we are using the
* drag and drop interface to position it.
*
* @return string the html
*/
public function render_html() {
return '';
@ -84,7 +86,7 @@ class element extends \mod_customcert\element {
}
// Validate the colour.
$errors += $this->validate_form_element_colour($data);
$errors += \mod_customcert\element_helper::validate_form_element_colour($data);
return $errors;
}
@ -92,7 +94,7 @@ class element extends \mod_customcert\element {
/**
* Sets the data on the form when editing an element.
*
* @param \mod_customcert_edit_element_form $mform the edit_form instance
* @param \mod_customcert\edit_element_form $mform the edit_form instance
*/
public function definition_after_data($mform) {
if (!empty($this->element->data)) {

View file

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

View file

@ -38,7 +38,7 @@ class element extends \mod_customcert\element {
$categoryname = $DB->get_field('course_categories', 'name', array('id' => $COURSE->category), MUST_EXIST);
parent::render_content($pdf, $categoryname);
\mod_customcert\element_helper::render_content($pdf, $this, $categoryname);
}
/**
@ -46,12 +46,14 @@ class element extends \mod_customcert\element {
*
* This function is used to render the element when we are using the
* drag and drop interface to position it.
*
* @return string the html
*/
public function render_html() {
global $DB, $COURSE;
$categoryname = $DB->get_field('course_categories', 'name', array('id' => $COURSE->category), MUST_EXIST);
return parent::render_html_content($categoryname);
return \mod_customcert\element_helper::render_html_content($this, $categoryname);
}
}

View file

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

View file

@ -37,7 +37,7 @@ class element extends \mod_customcert\element {
global $DB, $USER;
if ($preview) {
$code = customcert_generate_code();
$code = \mod_customcert\certificate::generate_code();
} else {
// Get the page.
$page = $DB->get_record('customcert_pages', array('id' => $this->element->pageid), '*', MUST_EXIST);
@ -46,7 +46,7 @@ class element extends \mod_customcert\element {
$code = $issue->code;
}
parent::render_content($pdf, $code);
\mod_customcert\element_helper::render_content($pdf, $this, $code);
}
/**
@ -54,10 +54,12 @@ class element extends \mod_customcert\element {
*
* This function is used to render the element when we are using the
* drag and drop interface to position it.
*
* @return string the html
*/
public function render_html() {
$code = customcert_generate_code();
$code = \mod_customcert\certificate::generate_code();
return parent::render_html_content($code);
return \mod_customcert\element_helper::render_html_content($this, $code);
}
}

View file

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

View file

@ -36,7 +36,7 @@ class element extends \mod_customcert\element {
public function render($pdf, $preview) {
global $COURSE;
parent::render_content($pdf, $COURSE->fullname);
\mod_customcert\element_helper::render_content($pdf, $this, $COURSE->fullname);
}
/**
@ -44,10 +44,12 @@ class element extends \mod_customcert\element {
*
* This function is used to render the element when we are using the
* drag and drop interface to position it.
*
* @return string the html
*/
public function render_html() {
global $COURSE;
return parent::render_html_content($COURSE->fullname);
return \mod_customcert\element_helper::render_html_content($this, $COURSE->fullname);
}
}

View file

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

View file

@ -40,7 +40,7 @@ class element extends \mod_customcert\element {
/**
* This function renders the form elements when adding a customcert element.
*
* @param \mod_customcert_edit_element_form $mform the edit_form instance
* @param \mod_customcert\edit_element_form $mform the edit_form instance
*/
public function render_form_elements($mform) {
// Get the possible date options.
@ -129,7 +129,7 @@ class element extends \mod_customcert\element {
// Ensure that a date has been set.
if (!empty($date)) {
parent::render_content($pdf, $this->get_date_format_string($date, $dateformat));
\mod_customcert\element_helper::render_content($pdf, $this, $this->get_date_format_string($date, $dateformat));
}
}
@ -138,6 +138,8 @@ class element extends \mod_customcert\element {
*
* This function is used to render the element when we are using the
* drag and drop interface to position it.
*
* @return string the html
*/
public function render_html() {
// If there is no element data, we have nothing to display.
@ -149,13 +151,13 @@ class element extends \mod_customcert\element {
$dateinfo = json_decode($this->element->data);
$dateformat = $dateinfo->dateformat;
return parent::render_html_content($this->get_date_format_string(time(), $dateformat));
return \mod_customcert\element_helper::render_html_content($this, $this->get_date_format_string(time(), $dateformat));
}
/**
* Sets the data on the form when editing an element.
*
* @param \mod_customcert_edit_element_form $mform the edit_form instance
* @param \mod_customcert\edit_element_form $mform the edit_form instance
*/
public function definition_after_data($mform) {
// Set the item and format for this element.
@ -209,7 +211,7 @@ class element extends \mod_customcert\element {
* @param string $dateformat
* @return string
*/
private function get_date_format_string($date, $dateformat) {
protected function get_date_format_string($date, $dateformat) {
switch ($dateformat) {
case 1:
$certificatedate = userdate($date, '%B %d, %Y');
@ -238,7 +240,7 @@ class element extends \mod_customcert\element {
* @param int $day the day of the month
* @return string the suffix.
*/
private function get_ordinal_number_suffix($day) {
protected function get_ordinal_number_suffix($day) {
if (!in_array(($day % 100), array(11, 12, 13))) {
switch ($day % 10) {
// Handle 1st, 2nd, 3rd.

View file

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

View file

@ -39,7 +39,7 @@ class element extends \mod_customcert\element {
/**
* This function renders the form elements when adding a customcert element.
*
* @param \mod_customcert_edit_element_form $mform the edit_form instance
* @param \mod_customcert\edit_element_form $mform the edit_form instance
*/
public function render_form_elements($mform) {
// Get the grade items we can display.
@ -104,7 +104,7 @@ class element extends \mod_customcert\element {
$grade = self::get_grade($gradeinfo, $USER->id);
}
parent::render_content($pdf, $grade);
\mod_customcert\element_helper::render_content($pdf, $this, $grade);
}
/**
@ -112,6 +112,8 @@ class element extends \mod_customcert\element {
*
* This function is used to render the element when we are using the
* drag and drop interface to position it.
*
* @return string the html
*/
public function render_html() {
global $COURSE;
@ -132,13 +134,13 @@ class element extends \mod_customcert\element {
}
$grade = grade_format_gradevalue('100', $courseitem, true, $gradeinfo->gradeformat, $decimals);
return parent::render_html_content($grade);
return \mod_customcert\element_helper::render_html_content($this, $grade);
}
/**
* Sets the data on the form when editing an element.
*
* @param \mod_customcert_edit_element_form $mform the edit_form instance
* @param \mod_customcert\edit_element_form $mform the edit_form instance
*/
public function definition_after_data($mform) {
// Set the item and format for this element.

View file

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

View file

@ -30,7 +30,7 @@ class element extends \mod_customcert\element {
/**
* This function renders the form elements when adding a customcert element.
*
* @param \mod_customcert_edit_element_form $mform the edit_form instance
* @param \mod_customcert\edit_element_form $mform the edit_form instance
*/
public function render_form_elements($mform) {
$mform->addElement('select', 'gradeitem', get_string('gradeitem', 'customcertelement_gradeitemname'),
@ -73,7 +73,7 @@ class element extends \mod_customcert\element {
// Get the name of the item.
$itemname = $DB->get_field($module->name, 'name', array('id' => $cm->instance), MUST_EXIST);
parent::render_content($pdf, $itemname);
\mod_customcert\element_helper::render_content($pdf, $this, $itemname);
}
}
@ -82,6 +82,8 @@ class element extends \mod_customcert\element {
*
* This function is used to render the element when we are using the
* drag and drop interface to position it.
*
* @return string the html
*/
public function render_html() {
global $DB;
@ -95,14 +97,16 @@ class element extends \mod_customcert\element {
// Get the name of the item.
$itemname = $DB->get_field($module->name, 'name', array('id' => $cm->instance), MUST_EXIST);
return parent::render_html_content($itemname);
return \mod_customcert\element_helper::render_html_content($this, $itemname);
}
return '';
}
/**
* Sets the data on the form when editing an element.
*
* @param \mod_customcert_edit_element_form $mform the edit_form instance
* @param \mod_customcert\edit_element_form $mform the edit_form instance
*/
public function definition_after_data($mform) {
if (!empty($this->element->data)) {

View file

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

View file

@ -27,7 +27,7 @@ defined('MOODLE_INTERNAL') || die();
*/
class element extends \mod_customcert\element {
private $filemanageroptions = array();
protected $filemanageroptions = array();
/**
* Constructor.
@ -49,7 +49,7 @@ class element extends \mod_customcert\element {
/**
* This function renders the form elements when adding a customcert element.
*
* @param \mod_customcert_edit_element_form $mform the edit_form instance
* @param \mod_customcert\edit_element_form $mform the edit_form instance
*/
public function render_form_elements($mform) {
$mform->addElement('select', 'image', get_string('image', 'customcertelement_image'), self::get_images());
@ -99,7 +99,7 @@ class element extends \mod_customcert\element {
}
// Validate the position.
$errors += $this->validate_form_element_position($data);
$errors += \mod_customcert\element_helper::validate_form_element_position($data);
return $errors;
}
@ -114,7 +114,7 @@ class element extends \mod_customcert\element {
global $COURSE;
// Handle file uploads.
customcert_upload_imagefiles($data->customcertimage, \context_course::instance($COURSE->id)->id);
\mod_customcert\certificate::upload_imagefiles($data->customcertimage, \context_course::instance($COURSE->id)->id);
parent::save_form_elements($data);
}
@ -169,11 +169,13 @@ class element extends \mod_customcert\element {
*
* This function is used to render the element when we are using the
* drag and drop interface to position it.
*
* @return string the html
*/
public function render_html() {
// If there is no element data, we have nothing to display.
if (empty($this->element->data)) {
return;
return '';
}
$imageinfo = json_decode($this->element->data);
@ -210,7 +212,7 @@ class element extends \mod_customcert\element {
/**
* Sets the data on the form when editing an element.
*
* @param \mod_customcert_edit_element_form $mform the edit_form instance
* @param \mod_customcert\edit_element_form $mform the edit_form instance
*/
public function definition_after_data($mform) {
global $COURSE;

View file

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

View file

@ -36,7 +36,7 @@ class element extends \mod_customcert\element {
public function render($pdf, $preview) {
global $USER;
parent::render_content($pdf, fullname($USER));
\mod_customcert\element_helper::render_content($pdf, $this, fullname($USER));
}
/**
@ -44,10 +44,12 @@ class element extends \mod_customcert\element {
*
* This function is used to render the element when we are using the
* drag and drop interface to position it.
*
* @return string the html
*/
public function render_html() {
global $USER;
return parent::render_html_content(fullname($USER));
return \mod_customcert\element_helper::render_html_content($this, fullname($USER));
}
}

View file

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

View file

@ -30,7 +30,7 @@ class element extends \mod_customcert\element {
/**
* This function renders the form elements when adding a customcert element.
*
* @param \mod_customcert_edit_element_form $mform the edit_form instance
* @param \mod_customcert\edit_element_form $mform the edit_form instance
*/
public function render_form_elements($mform) {
$mform->addElement('select', 'teacher', get_string('teacher', 'customcertelement_teachername'),
@ -65,7 +65,7 @@ class element extends \mod_customcert\element {
$teacher = $DB->get_record('user', array('id' => $this->element->data));
$teachername = fullname($teacher);
parent::render_content($pdf, $teachername);
\mod_customcert\element_helper::render_content($pdf, $this, $teachername);
}
/**
@ -73,6 +73,8 @@ class element extends \mod_customcert\element {
*
* This function is used to render the element when we are using the
* drag and drop interface to position it.
*
* @return string the html
*/
public function render_html() {
global $DB;
@ -80,7 +82,7 @@ class element extends \mod_customcert\element {
$teacher = $DB->get_record('user', array('id' => $this->element->data));
$teachername = fullname($teacher);
return parent::render_html_content($teachername);
return \mod_customcert\element_helper::render_html_content($this, $teachername);
}
/**
@ -88,15 +90,14 @@ class element extends \mod_customcert\element {
*
* @return array the list of teachers
*/
private function get_list_of_teachers() {
// When editing this element the cmid will be present in the URL.
$cmid = required_param('cmid', PARAM_INT);
protected function get_list_of_teachers() {
global $PAGE;
// The list of teachers to return.
$teachers = array();
// Now return all users who can manage the customcert in this context.
if ($users = get_users_by_capability(\context_module::instance($cmid), 'mod/customcert:manage')) {
if ($users = get_users_by_capability($PAGE->context, 'mod/customcert:manage')) {
foreach ($users as $user) {
$teachers[$user->id] = fullname($user);
}
@ -108,7 +109,7 @@ class element extends \mod_customcert\element {
/**
* Sets the data on the form when editing an element.
*
* @param \mod_customcert_edit_element_form $mform the edit_form instance
* @param \mod_customcert\edit_element_form $mform the edit_form instance
*/
public function definition_after_data($mform) {
if (!empty($this->element->data)) {

View file

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

View file

@ -30,7 +30,7 @@ class element extends \mod_customcert\element {
/**
* This function renders the form elements when adding a customcert element.
*
* @param \mod_customcert_edit_element_form $mform the edit_form instance
* @param \mod_customcert\edit_element_form $mform the edit_form instance
*/
public function render_form_elements($mform) {
$mform->addElement('textarea', 'text', get_string('text', 'customcertelement_text'));
@ -58,7 +58,7 @@ class element extends \mod_customcert\element {
* @param bool $preview true if it is a preview, false otherwise
*/
public function render($pdf, $preview) {
parent::render_content($pdf, $this->element->data);
\mod_customcert\element_helper::render_content($pdf, $this, $this->element->data);
}
/**
@ -66,15 +66,17 @@ class element extends \mod_customcert\element {
*
* This function is used to render the element when we are using the
* drag and drop interface to position it.
*
* @return string the html
*/
public function render_html() {
return parent::render_html_content($this->element->data);
return \mod_customcert\element_helper::render_html_content($this, $this->element->data);
}
/**
* Sets the data on the form when editing an element.
*
* @param \mod_customcert_edit_element_form $mform the edit_form instance
* @param \mod_customcert\edit_element_form $mform the edit_form instance
*/
public function definition_after_data($mform) {
if (!empty($this->element->data)) {

View file

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

View file

@ -30,7 +30,7 @@ class element extends \mod_customcert\element {
/**
* This function renders the form elements when adding a customcert element.
*
* @param \mod_customcert_edit_element_form $mform the edit_form instance
* @param \mod_customcert\edit_element_form $mform the edit_form instance
*/
public function render_form_elements($mform) {
// Get the user profile fields.
@ -103,7 +103,7 @@ class element extends \mod_customcert\element {
$value = $USER->$field;
}
parent::render_content($pdf, $value);
\mod_customcert\element_helper::render_content($pdf, $this, $value);
}
/**
@ -127,13 +127,13 @@ class element extends \mod_customcert\element {
$value = $USER->$field;
}
return parent::render_html_content($value);
return \mod_customcert\element_helper::render_html_content($this, $value);
}
/**
* Sets the data on the form when editing an element.
*
* @param \mod_customcert_edit_element_form $mform the edit_form instance
* @param \mod_customcert\edit_element_form $mform the edit_form instance
*/
public function definition_after_data($mform) {
if (!empty($this->element->data)) {

View file

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