From ae90c7ee4a4498a51e8e795989b64af13e3d8254 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Sat, 19 Aug 2017 20:09:19 +0800 Subject: [PATCH] Moved helper function --- classes/edit_form.php | 2 +- classes/element.php | 39 -------------------------------------- classes/element_helper.php | 39 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 40 deletions(-) diff --git a/classes/edit_form.php b/classes/edit_form.php index 1244a3d..d4289b1 100644 --- a/classes/edit_form.php +++ b/classes/edit_form.php @@ -288,7 +288,7 @@ class edit_form extends \moodleform { } $group = array(); - $group[] = $mform->createElement('select', 'element_' . $page->id, '', element::get_available_types()); + $group[] = $mform->createElement('select', 'element_' . $page->id, '', element_helper::get_available_element_types()); $group[] = $mform->createElement('submit', 'addelement_' . $page->id, get_string('addelement', 'customcert'), array(), false); $mform->addElement('group', 'elementgroup', '', $group, '', false); diff --git a/classes/element.php b/classes/element.php index 0a9ebfa..8c829e0 100644 --- a/classes/element.php +++ b/classes/element.php @@ -253,43 +253,4 @@ abstract class element { return false; } - - /** - * Return the list of possible elements to add. - * - * @return array the list of element types that can be used. - */ - public static function get_available_types() { - global $CFG; - - // Array to store the element types. - $options = array(); - - // Check that the directory exists. - $elementdir = "$CFG->dirroot/mod/customcert/element"; - if (file_exists($elementdir)) { - // Get directory contents. - $elementfolders = new \DirectoryIterator($elementdir); - // Loop through the elements folder. - foreach ($elementfolders as $elementfolder) { - // If it is not a directory or it is '.' or '..', skip it. - if (!$elementfolder->isDir() || $elementfolder->isDot()) { - continue; - } - // 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(); - // 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); - } - } - } - - \core_collator::asort($options); - return $options; - } } diff --git a/classes/element_helper.php b/classes/element_helper.php index b380b3d..2cfb921 100644 --- a/classes/element_helper.php +++ b/classes/element_helper.php @@ -378,4 +378,43 @@ class element_helper { return $SITE->id; } } + + /** + * Return the list of possible elements to add. + * + * @return array the list of element types that can be used. + */ + public static function get_available_element_types() { + global $CFG; + + // Array to store the element types. + $options = array(); + + // Check that the directory exists. + $elementdir = "$CFG->dirroot/mod/customcert/element"; + if (file_exists($elementdir)) { + // Get directory contents. + $elementfolders = new \DirectoryIterator($elementdir); + // Loop through the elements folder. + foreach ($elementfolders as $elementfolder) { + // If it is not a directory or it is '.' or '..', skip it. + if (!$elementfolder->isDir() || $elementfolder->isDot()) { + continue; + } + // 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(); + // 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); + } + } + } + + \core_collator::asort($options); + return $options; + } }