From 2416e8a3e04eb6ead12ab9e8450781379862a8bd Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Fri, 11 Dec 2015 14:53:45 +0800 Subject: [PATCH] Introduced automatic class loading for elements --- .../element.class.php => classes/element.php | 41 ++++++++++--------- edit.php | 1 - edit_element.php | 1 - .../border/{lib.php => classes/element.php} | 16 ++++---- element/border/version.php | 2 +- .../{lib.php => classes/element.php} | 8 ++-- element/categoryname/version.php | 2 +- element/code/{lib.php => classes/element.php} | 8 ++-- element/code/version.php | 2 +- .../{lib.php => classes/element.php} | 8 ++-- element/coursename/version.php | 2 +- element/date/{lib.php => classes/element.php} | 25 ++++++----- element/date/version.php | 2 +- .../grade/{lib.php => classes/element.php} | 35 ++++++++-------- element/grade/version.php | 2 +- .../{lib.php => classes/element.php} | 17 ++++---- element/gradeitemname/version.php | 2 +- .../image/{lib.php => classes/element.php} | 32 +++++++-------- element/image/version.php | 2 +- .../{lib.php => classes/element.php} | 8 ++-- element/studentname/version.php | 2 +- .../{lib.php => classes/element.php} | 16 ++++---- element/teachername/version.php | 2 +- element/text/{lib.php => classes/element.php} | 14 +++---- element/text/version.php | 2 +- .../{lib.php => classes/element.php} | 16 ++++---- element/userfield/version.php | 2 +- locallib.php | 20 ++++----- version.php | 2 +- 29 files changed, 144 insertions(+), 148 deletions(-) rename element/element.class.php => classes/element.php (93%) rename element/border/{lib.php => classes/element.php} (86%) rename element/categoryname/{lib.php => classes/element.php} (87%) rename element/code/{lib.php => classes/element.php} (88%) rename element/coursename/{lib.php => classes/element.php} (85%) rename element/date/{lib.php => classes/element.php} (90%) rename element/grade/{lib.php => classes/element.php} (90%) rename element/gradeitemname/{lib.php => classes/element.php} (85%) rename element/image/{lib.php => classes/element.php} (87%) rename element/studentname/{lib.php => classes/element.php} (85%) rename element/teachername/{lib.php => classes/element.php} (85%) rename element/text/{lib.php => classes/element.php} (84%) rename element/userfield/{lib.php => classes/element.php} (90%) diff --git a/element/element.class.php b/classes/element.php similarity index 93% rename from element/element.class.php rename to classes/element.php index 5c85f78..afb1750 100644 --- a/element/element.class.php +++ b/classes/element.php @@ -22,14 +22,16 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.'); +namespace mod_customcert; + +defined('MOODLE_INTERNAL') || die(); /** - * Class customcert_element_base + * Class element * * All customercert element plugins are based on this class. */ -abstract class customcert_element_base { +abstract class element { /** * The data for the element we are adding. @@ -39,7 +41,7 @@ abstract class customcert_element_base { /** * Constructor. * - * @param stdClass $element the element data + * @param \stdClass $element the element data */ public function __construct($element) { $this->element = clone($element); @@ -49,7 +51,7 @@ abstract class customcert_element_base { * This function renders the form elements when adding a customcert element. * Can be overridden if more functionality is needed. * - * @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) { // Render the common elements. @@ -62,8 +64,7 @@ abstract class customcert_element_base { * Sets the data on the form when editing an element. * Can be overridden if more functionality is needed. * - * @param mod_customcert_edit_element_form $mform the edit_form instance - * @param array the form elements to set + * @param \mod_customcert_edit_element_form $mform the edit_form instance */ public function definition_after_data($mform) { // Loop through the properties of the element and set the values @@ -99,13 +100,13 @@ abstract class customcert_element_base { * Handles saving the form elements created by this element. * Can be overridden if more functionality is needed. * - * @param stdClass $data the form data + * @param \stdClass $data the form data */ public function save_form_elements($data) { global $DB; // Get the data from the form. - $element = new stdClass(); + $element = new \stdClass(); $element->name = $data->name; $element->data = $this->save_unique_data($data); $element->font = (isset($data->font)) ? $data->font : null; @@ -135,7 +136,7 @@ abstract class customcert_element_base { * customcert column. * Can be overridden if more functionality is needed. * - * @param stdClass $data the form data + * @param \stdClass $data the form data * @return string the unique data to save */ public function save_unique_data($data) { @@ -147,7 +148,7 @@ abstract class customcert_element_base { * to a template to be loaded later. * Can be overridden if more functionality is needed. * - * @param stdClass $data the form data + * @param \stdClass $data the form data * @return bool returns true if the data was saved to the template, false otherwise */ public function save_data_to_template($data) { @@ -159,7 +160,7 @@ abstract class customcert_element_base { * from a template to an existing customcert. * Can be overridden if more functionality is needed. * - * @param stdClass $data the form data + * @param \stdClass $data the form data * @return bool returns true if the data was loaded from the template, false otherwise */ public function load_data_from_template($data) { @@ -170,7 +171,7 @@ abstract class customcert_element_base { * Handles rendering the element on the pdf. * Must be overridden. * - * @param pdf $pdf the pdf object + * @param \pdf $pdf the pdf object * @param bool $preview true if it is a preview, false otherwise */ public abstract function render($pdf, $preview); @@ -178,13 +179,13 @@ abstract class customcert_element_base { /** * Common behaviour for rendering specified content on the pdf. * - * @param pdf $pdf the pdf object + * @param \pdf $pdf the pdf object * @param string $content the content to render */ public function render_content($pdf, $content) { list($font, $attr) = $this->get_font(); $pdf->setFont($font, $attr, $this->element->size); - $fontcolour = TCPDF_COLORS::convertHTMLColorToDec($this->element->colour, $fontcolour); + $fontcolour = \TCPDF_COLORS::convertHTMLColorToDec($this->element->colour, $fontcolour); $pdf->SetTextColor($fontcolour['R'], $fontcolour['G'], $fontcolour['B']); $x = $this->element->posx; @@ -251,7 +252,7 @@ abstract class customcert_element_base { $fontstyle .= ': font-style: italic'; } $style = $fontstyle . '; color: ' . $this->element->colour . '; font-size: ' . $this->element->size . 'pt'; - return html_writer::tag('span', $content, array('style' => $style)); + return \html_writer::tag('span', $content, array('style' => $style)); } /** @@ -293,7 +294,7 @@ abstract class customcert_element_base { /** * Helper function to render the font elements. * - * @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_element_font($mform) { $mform->addElement('select', 'font', get_string('font', 'customcert'), customcert_get_fonts()); @@ -310,7 +311,7 @@ abstract class customcert_element_base { /** * Helper function to render the colour elements. * - * @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_element_colour($mform) { $mform->addElement('customcert_colourpicker', 'colour', get_string('fontcolour', 'customcert')); @@ -322,7 +323,7 @@ abstract class customcert_element_base { /** * Helper function to render the position elements. * - * @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_element_position($mform) { $mform->addElement('text', 'posx', get_string('posx', 'customcert'), array('size' => 10)); @@ -435,7 +436,7 @@ abstract class customcert_element_base { * data will need to be updated if we are restoring the course as the course module id will * be different in the new course. * - * @param restore_customcert_activity_task $restore + * @param \restore_customcert_activity_task $restore */ public function after_restore($restore) { diff --git a/edit.php b/edit.php index 23c5963..a794a51 100644 --- a/edit.php +++ b/edit.php @@ -27,7 +27,6 @@ require_once($CFG->dirroot . '/mod/customcert/locallib.php'); require_once($CFG->dirroot . '/mod/customcert/edit_form.php'); require_once($CFG->dirroot . '/mod/customcert/load_template_form.php'); require_once($CFG->dirroot . '/mod/customcert/save_template_form.php'); -require_once($CFG->dirroot . '/mod/customcert/element/element.class.php'); $cmid = required_param('cmid', PARAM_INT); $moveup = optional_param('moveup', 0, PARAM_INT); diff --git a/edit_element.php b/edit_element.php index e50ff42..ac25515 100644 --- a/edit_element.php +++ b/edit_element.php @@ -24,7 +24,6 @@ require_once('../../config.php'); require_once($CFG->dirroot . '/mod/customcert/edit_element_form.php'); -require_once($CFG->dirroot . '/mod/customcert/element/element.class.php'); $cmid = required_param('cmid', PARAM_INT); $action = required_param('action', PARAM_ALPHA); diff --git a/element/border/lib.php b/element/border/classes/element.php similarity index 86% rename from element/border/lib.php rename to element/border/classes/element.php index 057035d..a61eece 100644 --- a/element/border/lib.php +++ b/element/border/classes/element.php @@ -14,9 +14,9 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.'); +namespace customcertelement_border; -require_once($CFG->dirroot . '/mod/customcert/element/element.class.php'); +defined('MOODLE_INTERNAL') || die(); /** * The customcert element border's core interaction API. @@ -25,12 +25,12 @@ require_once($CFG->dirroot . '/mod/customcert/element/element.class.php'); * @copyright 2013 Mark Nelson * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class customcert_element_border extends customcert_element_base { +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. @@ -45,11 +45,11 @@ class customcert_element_border extends customcert_element_base { /** * Handles rendering the element on the pdf. * - * @param pdf $pdf the pdf object + * @param \pdf $pdf the pdf object * @param bool $preview true if it is a preview, false otherwise */ public function render($pdf, $preview) { - $colour = TCPDF_COLORS::convertHTMLColorToDec($this->element->colour, $colour); + $colour = \TCPDF_COLORS::convertHTMLColorToDec($this->element->colour, $colour); $pdf->SetLineStyle(array('width' => $this->element->data, 'color' => $colour)); $pdf->Line(0, 0, $pdf->getPageWidth(), 0); $pdf->Line($pdf->getPageWidth(), 0, $pdf->getPageWidth(), $pdf->getPageHeight()); @@ -92,7 +92,7 @@ class customcert_element_border extends customcert_element_base { /** * 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)) { @@ -105,7 +105,7 @@ class customcert_element_border extends customcert_element_base { * This will handle how form data will be saved into the data column in the * customcert_elements table. * - * @param stdClass $data the form data + * @param \stdClass $data the form data * @return string the json encoded array */ public function save_unique_data($data) { diff --git a/element/border/version.php b/element/border/version.php index d141088..2a91bfb 100644 --- a/element/border/version.php +++ b/element/border/version.php @@ -24,6 +24,6 @@ defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.'); -$plugin->version = 2015080500; // The current module version (Date: YYYYMMDDXX). +$plugin->version = 2015121400; // The current module version (Date: YYYYMMDDXX). $plugin->requires = 2015051100; // Requires this Moodle version (2.9). $plugin->component = 'customcertelement_border'; diff --git a/element/categoryname/lib.php b/element/categoryname/classes/element.php similarity index 87% rename from element/categoryname/lib.php rename to element/categoryname/classes/element.php index 5cea9d7..15b35d0 100644 --- a/element/categoryname/lib.php +++ b/element/categoryname/classes/element.php @@ -14,9 +14,9 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.'); +namespace customcertelement_categoryname; -require_once($CFG->dirroot . '/mod/customcert/element/element.class.php'); +defined('MOODLE_INTERNAL') || die(); /** * The customcert element categoryname's core interaction API. @@ -25,12 +25,12 @@ require_once($CFG->dirroot . '/mod/customcert/element/element.class.php'); * @copyright 2013 Mark Nelson * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class customcert_element_categoryname extends customcert_element_base { +class element extends \mod_customcert\element { /** * Handles rendering the element on the pdf. * - * @param pdf $pdf the pdf object + * @param \pdf $pdf the pdf object * @param bool $preview true if it is a preview, false otherwise */ public function render($pdf, $preview) { diff --git a/element/categoryname/version.php b/element/categoryname/version.php index 382e387..2cd59f9 100644 --- a/element/categoryname/version.php +++ b/element/categoryname/version.php @@ -24,6 +24,6 @@ defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.'); -$plugin->version = 2015080500; // The current module version (Date: YYYYMMDDXX). +$plugin->version = 2015121400; // The current module version (Date: YYYYMMDDXX). $plugin->requires = 2015051100; // Requires this Moodle version (2.9). $plugin->component = 'customcertelement_categoryname'; diff --git a/element/code/lib.php b/element/code/classes/element.php similarity index 88% rename from element/code/lib.php rename to element/code/classes/element.php index b375e16..7849dda 100644 --- a/element/code/lib.php +++ b/element/code/classes/element.php @@ -14,9 +14,9 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.'); +namespace customcertelement_code; -require_once($CFG->dirroot . '/mod/customcert/element/element.class.php'); +defined('MOODLE_INTERNAL') || die(); /** * The customcert element code's core interaction API. @@ -25,12 +25,12 @@ require_once($CFG->dirroot . '/mod/customcert/element/element.class.php'); * @copyright 2013 Mark Nelson * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class customcert_element_code extends customcert_element_base { +class element extends \mod_customcert\element { /** * Handles rendering the element on the pdf. * - * @param pdf $pdf the pdf object + * @param \pdf $pdf the pdf object * @param bool $preview true if it is a preview, false otherwise */ public function render($pdf, $preview) { diff --git a/element/code/version.php b/element/code/version.php index 8ba2fae..f6dd75f 100644 --- a/element/code/version.php +++ b/element/code/version.php @@ -24,6 +24,6 @@ defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.'); -$plugin->version = 2015080500; // The current module version (Date: YYYYMMDDXX). +$plugin->version = 2015121400; // The current module version (Date: YYYYMMDDXX). $plugin->requires = 2015051100; // Requires this Moodle version (2.9). $plugin->component = 'customcertelement_code'; diff --git a/element/coursename/lib.php b/element/coursename/classes/element.php similarity index 85% rename from element/coursename/lib.php rename to element/coursename/classes/element.php index 39abcf7..8910b49 100644 --- a/element/coursename/lib.php +++ b/element/coursename/classes/element.php @@ -14,9 +14,9 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.'); +namespace customcertelement_coursename; -require_once($CFG->dirroot . '/mod/customcert/element/element.class.php'); +defined('MOODLE_INTERNAL') || die(); /** * The customcert element coursename's core interaction API. @@ -25,12 +25,12 @@ require_once($CFG->dirroot . '/mod/customcert/element/element.class.php'); * @copyright 2013 Mark Nelson * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class customcert_element_coursename extends customcert_element_base { +class element extends \mod_customcert\element { /** * Handles rendering the element on the pdf. * - * @param pdf $pdf the pdf object + * @param \pdf $pdf the pdf object * @param bool $preview true if it is a preview, false otherwise */ public function render($pdf, $preview) { diff --git a/element/coursename/version.php b/element/coursename/version.php index 838d590..c921803 100644 --- a/element/coursename/version.php +++ b/element/coursename/version.php @@ -24,6 +24,6 @@ defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.'); -$plugin->version = 2015080500; // The current module version (Date: YYYYMMDDXX). +$plugin->version = 2015121400; // The current module version (Date: YYYYMMDDXX). $plugin->requires = 2015051100; // Requires this Moodle version (2.9). $plugin->component = 'customcertelement_coursename'; diff --git a/element/date/lib.php b/element/date/classes/element.php similarity index 90% rename from element/date/lib.php rename to element/date/classes/element.php index 046fa47..48633db 100644 --- a/element/date/lib.php +++ b/element/date/classes/element.php @@ -14,10 +14,9 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.'); +namespace customcertelement_date; -require_once($CFG->dirroot . '/mod/customcert/element/element.class.php'); -require_once($CFG->dirroot . '/mod/customcert/element/grade/lib.php'); +defined('MOODLE_INTERNAL') || die(); /** * Date - Issue @@ -36,19 +35,19 @@ define('CUSTOMCERT_DATE_COMPLETION', '2'); * @copyright 2013 Mark Nelson * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class customcert_element_date extends customcert_element_base { +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. $dateoptions = array(); $dateoptions[CUSTOMCERT_DATE_ISSUE] = get_string('issueddate', 'customcertelement_date'); $dateoptions[CUSTOMCERT_DATE_COMPLETION] = get_string('completiondate', 'customcertelement_date'); - $dateoptions = $dateoptions + customcert_element_grade::get_grade_items(); + $dateoptions = $dateoptions + \customcertelement_grade\element::get_grade_items();; $mform->addElement('select', 'dateitem', get_string('dateitem', 'customcertelement_date'), $dateoptions); $mform->addHelpButton('dateitem', 'dateitem', 'customcertelement_date'); @@ -63,7 +62,7 @@ class customcert_element_date extends customcert_element_base { * This will handle how form data will be saved into the data column in the * customcert_elements table. * - * @param stdClass $data the form data + * @param \stdClass $data the form data * @return string the json encoded array */ public function save_unique_data($data) { @@ -80,7 +79,7 @@ class customcert_element_date extends customcert_element_base { /** * Handles rendering the element on the pdf. * - * @param pdf $pdf the pdf object + * @param \pdf $pdf the pdf object * @param bool $preview true if it is a preview, false otherwise */ public function render($pdf, $preview) { @@ -119,10 +118,10 @@ class customcert_element_date extends customcert_element_base { } } } else { - $gradeitem = new stdClass(); + $gradeitem = new \stdClass(); $gradeitem->gradeitem = $dateitem; $gradeitem->gradeformat = GRADE_DISPLAY_TYPE_PERCENTAGE; - if ($modinfo = customcert_element_grade::get_grade($gradeitem, $issue->userid)) { + if ($modinfo = \customcertelement_grade\element::get_grade($gradeitem, $issue->userid)) { $date = $modinfo->dategraded; } } @@ -156,7 +155,7 @@ class customcert_element_date extends customcert_element_base { /** * 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. @@ -175,13 +174,13 @@ class customcert_element_date extends customcert_element_base { * We will want to update the course module the date element is pointing to as it will * have changed in the course restore. * - * @param restore_customcert_activity_task $restore + * @param \restore_customcert_activity_task $restore */ public function after_restore($restore) { global $DB; $dateinfo = json_decode($this->element->data); - if ($newitem = restore_dbops::get_backup_ids_record($restore->get_restoreid(), 'course_module', $dateinfo->dateitem)) { + if ($newitem = \restore_dbops::get_backup_ids_record($restore->get_restoreid(), 'course_module', $dateinfo->dateitem)) { $dateinfo->dateitem = $newitem->newitemid; $DB->set_field('customcert_elements', 'data', self::save_unique_data($dateinfo), array('id' => $this->element->id)); } diff --git a/element/date/version.php b/element/date/version.php index 44f0822..989fce5 100644 --- a/element/date/version.php +++ b/element/date/version.php @@ -24,6 +24,6 @@ defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.'); -$plugin->version = 2015080500; // The current module version (Date: YYYYMMDDXX). +$plugin->version = 2015121400; // The current module version (Date: YYYYMMDDXX). $plugin->requires = 2015051100; // Requires this Moodle version (2.9). $plugin->component = 'customcertelement_date'; diff --git a/element/grade/lib.php b/element/grade/classes/element.php similarity index 90% rename from element/grade/lib.php rename to element/grade/classes/element.php index 137b138..d3a93c9 100644 --- a/element/grade/lib.php +++ b/element/grade/classes/element.php @@ -14,9 +14,10 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.'); +namespace customcertelement_grade; + +defined('MOODLE_INTERNAL') || die(); -require_once($CFG->dirroot . '/mod/customcert/element/element.class.php'); require_once($CFG->libdir . '/grade/constants.php'); require_once($CFG->dirroot . '/grade/lib.php'); require_once($CFG->dirroot . '/grade/querylib.php'); @@ -33,12 +34,12 @@ define('CUSTOMCERT_GRADE_COURSE', '0'); * @copyright 2013 Mark Nelson * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class customcert_element_grade extends customcert_element_base { +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. @@ -63,7 +64,7 @@ class customcert_element_grade extends customcert_element_base { * This will handle how form data will be saved into the data column in the * customcert_elements table. * - * @param stdClass $data the form data. + * @param \stdClass $data the form data. * @return string the json encoded array */ public function save_unique_data($data) { @@ -80,7 +81,7 @@ class customcert_element_grade extends customcert_element_base { /** * Handles rendering the element on the pdf. * - * @param pdf $pdf the pdf object + * @param \pdf $pdf the pdf object * @param bool $preview true if it is a preview, false otherwise */ public function render($pdf, $preview) { @@ -96,7 +97,7 @@ class customcert_element_grade extends customcert_element_base { // If we are previewing this certificate then just show a demonstration grade. if ($preview) { - $courseitem = grade_item::fetch_course_item($COURSE->id); + $courseitem = \grade_item::fetch_course_item($COURSE->id); $grade = grade_format_gradevalue('100', $courseitem, true, $gradeinfo->gradeformat, 2); } else { // Get the grade for the grade item. @@ -123,7 +124,7 @@ class customcert_element_grade extends customcert_element_base { // Decode the information stored in the database. $gradeinfo = json_decode($this->element->data); - $courseitem = grade_item::fetch_course_item($COURSE->id); + $courseitem = \grade_item::fetch_course_item($COURSE->id); // Define how many decimals to display. $decimals = 2; if ($gradeinfo->gradeformat == GRADE_DISPLAY_TYPE_PERCENTAGE) { @@ -137,7 +138,7 @@ class customcert_element_grade extends customcert_element_base { /** * 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. @@ -156,13 +157,13 @@ class customcert_element_grade extends customcert_element_base { * We will want to update the course module the grade element is pointing to as it will * have changed in the course restore. * - * @param restore_customcert_activity_task $restore + * @param \restore_customcert_activity_task $restore */ public function after_restore($restore) { global $DB; $gradeinfo = json_decode($this->element->data); - if ($newitem = restore_dbops::get_backup_ids_record($restore->get_restoreid(), 'course_module', $gradeinfo->gradeitem)) { + if ($newitem = \restore_dbops::get_backup_ids_record($restore->get_restoreid(), 'course_module', $gradeinfo->gradeitem)) { $gradeinfo->gradeitem = $newitem->newitemid; $DB->set_field('customcert_elements', 'data', self::save_unique_data($gradeinfo), array('id' => $this->element->id)); } @@ -245,7 +246,7 @@ class customcert_element_grade extends customcert_element_base { /** * Helper function to return the grade to display. * - * @param stdClass $gradeinfo + * @param \stdClass $gradeinfo * @param int $userid * @return string the grade result */ @@ -258,10 +259,10 @@ class customcert_element_grade extends customcert_element_base { // Check if we are displaying the course grade. if ($gradeitem == CUSTOMCERT_GRADE_COURSE) { - if ($courseitem = grade_item::fetch_course_item($COURSE->id)) { + if ($courseitem = \grade_item::fetch_course_item($COURSE->id)) { // Set the grade type we want. $courseitem->gradetype = GRADE_TYPE_VALUE; - $grade = new grade_grade(array('itemid' => $courseitem->id, 'userid' => $userid)); + $grade = new \grade_grade(array('itemid' => $courseitem->id, 'userid' => $userid)); $coursegrade = grade_format_gradevalue($grade->finalgrade, $courseitem, true, $gradeformat, 2); return $coursegrade; } @@ -281,7 +282,7 @@ class customcert_element_grade extends customcert_element_base { * @param int $moduleid * @param int $gradeformat * @param int $userid - * @return stdClass the grade information + * @return \stdClass the grade information */ public static function get_mod_grade($moduleid, $gradeformat, $userid) { global $DB; @@ -291,7 +292,7 @@ class customcert_element_grade extends customcert_element_base { $gradeitem = grade_get_grades($cm->course, 'mod', $module->name, $cm->instance, $userid); if (!empty($gradeitem)) { - $item = new grade_item(); + $item = new \grade_item(); $item->gradetype = GRADE_TYPE_VALUE; $item->courseid = $cm->course; $itemproperties = reset($gradeitem->items); @@ -307,7 +308,7 @@ class customcert_element_grade extends customcert_element_base { } // Create the object we will be returning. - $modinfo = new stdClass; + $modinfo = new \stdClass; $modinfo->name = $DB->get_field($module->name, 'name', array('id' => $cm->instance)); $modinfo->gradetodisplay = grade_format_gradevalue($grade, $item, true, $gradeformat, $decimals); diff --git a/element/grade/version.php b/element/grade/version.php index 6de34cf..3bd4ff2 100644 --- a/element/grade/version.php +++ b/element/grade/version.php @@ -24,6 +24,6 @@ defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.'); -$plugin->version = 2015080500; // The current module version (Date: YYYYMMDDXX). +$plugin->version = 2015121400; // The current module version (Date: YYYYMMDDXX). $plugin->requires = 2015051100; // Requires this Moodle version (2.9). $plugin->component = 'customcertelement_grade'; diff --git a/element/gradeitemname/lib.php b/element/gradeitemname/classes/element.php similarity index 85% rename from element/gradeitemname/lib.php rename to element/gradeitemname/classes/element.php index d973950..68e8958 100644 --- a/element/gradeitemname/lib.php +++ b/element/gradeitemname/classes/element.php @@ -14,10 +14,9 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.'); +namespace customcertelement_gradeitemname; -require_once($CFG->dirroot . '/mod/customcert/element/element.class.php'); -require_once($CFG->dirroot . '/mod/customcert/element/grade/lib.php'); +defined('MOODLE_INTERNAL') || die(); /** * The customcert element gradeitemname's core interaction API. @@ -26,16 +25,16 @@ require_once($CFG->dirroot . '/mod/customcert/element/grade/lib.php'); * @copyright 2013 Mark Nelson * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class customcert_element_gradeitemname extends customcert_element_base { +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'), - customcert_element_grade::get_grade_items()); + \customcertelement_grade\element::get_grade_items()); $mform->addHelpButton('gradeitem', 'gradeitem', 'customcertelement_gradeitemname'); parent::render_form_elements($mform); @@ -45,7 +44,7 @@ class customcert_element_gradeitemname extends customcert_element_base { * This will handle how form data will be saved into the data column in the * customcert_elements table. * - * @param stdClass $data the form data + * @param \stdClass $data the form data * @return string the text */ public function save_unique_data($data) { @@ -59,7 +58,7 @@ class customcert_element_gradeitemname extends customcert_element_base { /** * Handles rendering the element on the pdf. * - * @param pdf $pdf the pdf object + * @param \pdf $pdf the pdf object * @param bool $preview true if it is a preview, false otherwise */ public function render($pdf, $preview) { @@ -103,7 +102,7 @@ class customcert_element_gradeitemname extends customcert_element_base { /** * 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)) { diff --git a/element/gradeitemname/version.php b/element/gradeitemname/version.php index 72dc9a0..fa61ac6 100644 --- a/element/gradeitemname/version.php +++ b/element/gradeitemname/version.php @@ -24,6 +24,6 @@ defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.'); -$plugin->version = 2015080500; // The current module version (Date: YYYYMMDDXX). +$plugin->version = 2015121400; // The current module version (Date: YYYYMMDDXX). $plugin->requires = 2015051100; // Requires this Moodle version (2.9). $plugin->component = 'customcertelement_gradeitemname'; diff --git a/element/image/lib.php b/element/image/classes/element.php similarity index 87% rename from element/image/lib.php rename to element/image/classes/element.php index 191883d..a9cacfc 100644 --- a/element/image/lib.php +++ b/element/image/classes/element.php @@ -14,9 +14,9 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.'); +namespace customcertelement_image; -require_once($CFG->dirroot . '/mod/customcert/element/element.class.php'); +defined('MOODLE_INTERNAL') || die(); /** * The customcert element image's core interaction API. @@ -25,14 +25,14 @@ require_once($CFG->dirroot . '/mod/customcert/element/element.class.php'); * @copyright 2013 Mark Nelson * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class customcert_element_image extends customcert_element_base { +class element extends \mod_customcert\element { private $filemanageroptions = array(); /** * Constructor. * - * @param stdClass $element the element data + * @param \stdClass $element the element data */ public function __construct($element) { global $COURSE; @@ -49,7 +49,7 @@ class customcert_element_image extends customcert_element_base { /** * 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()); @@ -108,13 +108,13 @@ class customcert_element_image extends customcert_element_base { * Handles saving the form elements created by this element. * Can be overridden if more functionality is needed. * - * @param stdClass $data the form data + * @param \stdClass $data the form data */ public function save_form_elements($data) { global $COURSE; // Handle file uploads. - customcert_upload_imagefiles($data->customcertimage, context_course::instance($COURSE->id)->id); + customcert_upload_imagefiles($data->customcertimage, \context_course::instance($COURSE->id)->id); parent::save_form_elements($data); } @@ -123,7 +123,7 @@ class customcert_element_image extends customcert_element_base { * This will handle how form data will be saved into the data column in the * customcert_elements table. * - * @param stdClass $data the form data + * @param \stdClass $data the form data * @return string the json encoded array */ public function save_unique_data($data) { @@ -140,7 +140,7 @@ class customcert_element_image extends customcert_element_base { /** * Handles rendering the element on the pdf. * - * @param pdf $pdf the pdf object + * @param \pdf $pdf the pdf object * @param bool $preview true if it is a preview, false otherwise */ public function render($pdf, $preview) { @@ -181,7 +181,7 @@ class customcert_element_image extends customcert_element_base { // Get the image. $fs = get_file_storage(); if ($file = $fs->get_file_by_hash($imageinfo->pathnamehash)) { - $url = moodle_url::make_pluginfile_url($file->get_contextid(), 'mod_customcert', 'image', $file->get_itemid(), + $url = \moodle_url::make_pluginfile_url($file->get_contextid(), 'mod_customcert', 'image', $file->get_itemid(), $file->get_filepath(), $file->get_filename()); $fileimageinfo = $file->get_imageinfo(); $whratio = $fileimageinfo['width'] / $fileimageinfo['height']; @@ -203,14 +203,14 @@ class customcert_element_image extends customcert_element_base { $style .= 'height: ' . $imageinfo->height . 'mm'; } - return html_writer::tag('img', '', array('src' => $url, 'style' => $style)); + return \html_writer::tag('img', '', array('src' => $url, 'style' => $style)); } } /** * 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; @@ -225,7 +225,7 @@ class customcert_element_image extends customcert_element_base { // Editing existing instance - copy existing files into draft area. $draftitemid = file_get_submitted_draft_itemid('customcertimage'); - file_prepare_draft_area($draftitemid, context_course::instance($COURSE->id)->id, 'mod_customcert', 'image', 0, $this->filemanageroptions); + file_prepare_draft_area($draftitemid, \context_course::instance($COURSE->id)->id, 'mod_customcert', 'image', 0, $this->filemanageroptions); $element = $mform->getElement('customcertimage'); $element->setValue($draftitemid); @@ -246,19 +246,19 @@ class customcert_element_image extends customcert_element_base { // The array used to store the images. $arrfiles = array(); // Loop through the files uploaded in the system context. - if ($files = $fs->get_area_files(context_system::instance()->id, 'mod_customcert', 'image', false, 'filename', false)) { + if ($files = $fs->get_area_files(\context_system::instance()->id, 'mod_customcert', 'image', false, 'filename', false)) { foreach ($files as $hash => $file) { $arrfiles[$hash] = $file->get_filename(); } } // Loop through the files uploaded in the course context. - if ($files = $fs->get_area_files(context_course::instance($COURSE->id)->id, 'mod_customcert', 'image', false, 'filename', false)) { + if ($files = $fs->get_area_files(\context_course::instance($COURSE->id)->id, 'mod_customcert', 'image', false, 'filename', false)) { foreach ($files as $hash => $file) { $arrfiles[$hash] = $file->get_filename(); } } - core_collator::asort($arrfiles); + \core_collator::asort($arrfiles); $arrfiles = array_merge(array('0' => get_string('noimage', 'customcert')), $arrfiles); return $arrfiles; diff --git a/element/image/version.php b/element/image/version.php index b88e5cb..f4c1b7c 100644 --- a/element/image/version.php +++ b/element/image/version.php @@ -24,6 +24,6 @@ defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.'); -$plugin->version = 2015080500; // The current module version (Date: YYYYMMDDXX). +$plugin->version = 2015121400; // The current module version (Date: YYYYMMDDXX). $plugin->requires = 2015051100; // Requires this Moodle version (2.9). $plugin->component = 'customcertelement_image'; diff --git a/element/studentname/lib.php b/element/studentname/classes/element.php similarity index 85% rename from element/studentname/lib.php rename to element/studentname/classes/element.php index dfbe013..0995021 100644 --- a/element/studentname/lib.php +++ b/element/studentname/classes/element.php @@ -14,9 +14,9 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.'); +namespace customcertelement_studentname; -require_once($CFG->dirroot . '/mod/customcert/element/element.class.php'); +defined('MOODLE_INTERNAL') || die(); /** * The customcert element studentname's core interaction API. @@ -25,12 +25,12 @@ require_once($CFG->dirroot . '/mod/customcert/element/element.class.php'); * @copyright 2013 Mark Nelson * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class customcert_element_studentname extends customcert_element_base { +class element extends \mod_customcert\element { /** * Handles rendering the element on the pdf. * - * @param pdf $pdf the pdf object + * @param \pdf $pdf the pdf object * @param bool $preview true if it is a preview, false otherwise */ public function render($pdf, $preview) { diff --git a/element/studentname/version.php b/element/studentname/version.php index f1e00a6..b3551c0 100644 --- a/element/studentname/version.php +++ b/element/studentname/version.php @@ -24,6 +24,6 @@ defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.'); -$plugin->version = 2015080500; // The current module version (Date: YYYYMMDDXX). +$plugin->version = 2015121400; // The current module version (Date: YYYYMMDDXX). $plugin->requires = 2015051100; // Requires this Moodle version (2.9). $plugin->component = 'customcertelement_studentname'; diff --git a/element/teachername/lib.php b/element/teachername/classes/element.php similarity index 85% rename from element/teachername/lib.php rename to element/teachername/classes/element.php index ea6aa05..bd49027 100644 --- a/element/teachername/lib.php +++ b/element/teachername/classes/element.php @@ -14,9 +14,9 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.'); +namespace customcertelement_teachername; -require_once($CFG->dirroot . '/mod/customcert/element/element.class.php'); +defined('MOODLE_INTERNAL') || die(); /** * The customcert element teachername's core interaction API. @@ -25,12 +25,12 @@ require_once($CFG->dirroot . '/mod/customcert/element/element.class.php'); * @copyright 2013 Mark Nelson * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class customcert_element_teachername extends customcert_element_base { +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'), @@ -44,7 +44,7 @@ class customcert_element_teachername extends customcert_element_base { * This will handle how form data will be saved into the data column in the * customcert_elements table. * - * @param stdClass $data the form data + * @param \stdClass $data the form data * @return string the text */ public function save_unique_data($data) { @@ -54,7 +54,7 @@ class customcert_element_teachername extends customcert_element_base { /** * Handles rendering the element on the pdf. * - * @param pdf $pdf the pdf object + * @param \pdf $pdf the pdf object * @param bool $preview true if it is a preview, false otherwise */ public function render($pdf, $preview) { @@ -94,7 +94,7 @@ class customcert_element_teachername extends customcert_element_base { $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(\context_module::instance($cmid), 'mod/customcert:manage')) { foreach ($users as $user) { $teachers[$user->id] = fullname($user); } @@ -106,7 +106,7 @@ class customcert_element_teachername extends customcert_element_base { /** * 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)) { diff --git a/element/teachername/version.php b/element/teachername/version.php index cd3dcab..8461365 100644 --- a/element/teachername/version.php +++ b/element/teachername/version.php @@ -24,6 +24,6 @@ defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.'); -$plugin->version = 2015080500; // The current module version (Date: YYYYMMDDXX). +$plugin->version = 2015121400; // The current module version (Date: YYYYMMDDXX). $plugin->requires = 2015051100; // Requires this Moodle version (2.9). $plugin->component = 'customcertelement_teachername'; diff --git a/element/text/lib.php b/element/text/classes/element.php similarity index 84% rename from element/text/lib.php rename to element/text/classes/element.php index 97767e6..98bc942 100644 --- a/element/text/lib.php +++ b/element/text/classes/element.php @@ -14,9 +14,9 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.'); +namespace customcertelement_text; -require_once($CFG->dirroot . '/mod/customcert/element/element.class.php'); +defined('MOODLE_INTERNAL') || die(); /** * The customcert element text's core interaction API. @@ -25,12 +25,12 @@ require_once($CFG->dirroot . '/mod/customcert/element/element.class.php'); * @copyright 2013 Mark Nelson * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class customcert_element_text extends customcert_element_base { +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')); @@ -44,7 +44,7 @@ class customcert_element_text extends customcert_element_base { * This will handle how form data will be saved into the data column in the * customcert_elements table. * - * @param stdClass $data the form data + * @param \stdClass $data the form data * @return string the text */ public function save_unique_data($data) { @@ -54,7 +54,7 @@ class customcert_element_text extends customcert_element_base { /** * Handles rendering the element on the pdf. * - * @param pdf $pdf the pdf object + * @param \pdf $pdf the pdf object * @param bool $preview true if it is a preview, false otherwise */ public function render($pdf, $preview) { @@ -74,7 +74,7 @@ class customcert_element_text extends customcert_element_base { /** * 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)) { diff --git a/element/text/version.php b/element/text/version.php index 4d2d5bf..a52ac27 100644 --- a/element/text/version.php +++ b/element/text/version.php @@ -24,6 +24,6 @@ defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.'); -$plugin->version = 2015080500; // The current module version (Date: YYYYMMDDXX). +$plugin->version = 2015121400; // The current module version (Date: YYYYMMDDXX). $plugin->requires = 2015051100; // Requires this Moodle version (2.9). $plugin->component = 'customcertelement_text'; diff --git a/element/userfield/lib.php b/element/userfield/classes/element.php similarity index 90% rename from element/userfield/lib.php rename to element/userfield/classes/element.php index 3d3ca99..4abeee0 100644 --- a/element/userfield/lib.php +++ b/element/userfield/classes/element.php @@ -14,9 +14,9 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.'); +namespace customcertelement_userfield; -require_once($CFG->dirroot . '/mod/customcert/element/element.class.php'); +defined('MOODLE_INTERNAL') || die(); /** * The customcert element userfield's core interaction API. @@ -25,12 +25,12 @@ require_once($CFG->dirroot . '/mod/customcert/element/element.class.php'); * @copyright 2013 Mark Nelson * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class customcert_element_userfield extends customcert_element_base { +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. @@ -61,7 +61,7 @@ class customcert_element_userfield extends customcert_element_base { } // Combine the two. $fields = $userfields + $customfields; - core_collator::asort($fields); + \core_collator::asort($fields); // Create the select box where the user field is selected. $mform->addElement('select', 'userfield', get_string('userfield', 'customcertelement_userfield'), $fields); @@ -75,7 +75,7 @@ class customcert_element_userfield extends customcert_element_base { * This will handle how form data will be saved into the data column in the * customcert_elements table. * - * @param stdClass $data the form data + * @param \stdClass $data the form data * @return string the text */ public function save_unique_data($data) { @@ -85,7 +85,7 @@ class customcert_element_userfield extends customcert_element_base { /** * Handles rendering the element on the pdf. * - * @param pdf $pdf the pdf object + * @param \pdf $pdf the pdf object * @param bool $preview true if it is a preview, false otherwise */ public function render($pdf, $preview) { @@ -133,7 +133,7 @@ class customcert_element_userfield extends customcert_element_base { /** * 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)) { diff --git a/element/userfield/version.php b/element/userfield/version.php index 2c4dd66..e339838 100644 --- a/element/userfield/version.php +++ b/element/userfield/version.php @@ -24,6 +24,6 @@ defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.'); -$plugin->version = 2015080500; // The current module version (Date: YYYYMMDDXX). +$plugin->version = 2015121400; // The current module version (Date: YYYYMMDDXX). $plugin->requires = 2015051100; // Requires this Moodle version (2.9). $plugin->component = 'customcertelement_userfield'; diff --git a/locallib.php b/locallib.php index 1d1ce4e..6693b16 100644 --- a/locallib.php +++ b/locallib.php @@ -121,13 +121,13 @@ function customcert_get_elements() { if (!$elementfolder->isDir() || $elementfolder->isDot()) { continue; } - // Check that the standard class file exists, if not we do + // Check that the standard class exists, if not we do // not want to display it as an option as it will not work. $foldername = $elementfolder->getFilename(); - $classfile = "$elementdir/$foldername/lib.php"; - if (file_exists($classfile)) { - // Need to require this file in case if we choose to add this element. - require_once($classfile); + // Get the class name. + $classname = '\\customcertelement_' . $foldername . '\\element'; + // Ensure the necessary class exists. + if (class_exists($classname)) { $component = "customcertelement_{$foldername}"; $options[$foldername] = get_string('pluginname', $component); } @@ -246,13 +246,11 @@ function customcert_save_page_data($data) { * class does not exists. */ function customcert_get_element_instance($element) { - global $CFG; + // Get the class name. + $classname = '\\customcertelement_' . $element->element . '\\element'; - $classfile = "$CFG->dirroot/mod/customcert/element/{$element->element}/lib.php"; - // Ensure this necessary file exists. - if (file_exists($classfile)) { - require_once($classfile); - $classname = "customcert_element_{$element->element}"; + // Ensure the necessary class exists. + if (class_exists($classname)) { return new $classname($element); } diff --git a/version.php b/version.php index c94ea2b..492c888 100644 --- a/version.php +++ b/version.php @@ -24,7 +24,7 @@ defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.'); -$plugin->version = 2015120801; // The current module version (Date: YYYYMMDDXX). +$plugin->version = 2015121400; // The current module version (Date: YYYYMMDDXX). $plugin->requires = 2015051100; // Requires this Moodle version (2.9). $plugin->cron = 0; // Period for cron to check this module (secs). $plugin->component = 'mod_customcert';