From ce0746ea70a52c7faa7c3731894f4cdc376f7b88 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Tue, 3 Aug 2021 19:21:07 +0800 Subject: [PATCH] Minor code changes (#415) --- element/coursename/classes/element.php | 29 ++++++++++++------- .../lang/en/customcertelement_coursename.php | 9 +++--- tests/behat/managing_elements.feature | 22 +++++++------- 3 files changed, 35 insertions(+), 25 deletions(-) diff --git a/element/coursename/classes/element.php b/element/coursename/classes/element.php index c88c242..a5b274d 100644 --- a/element/coursename/classes/element.php +++ b/element/coursename/classes/element.php @@ -35,17 +35,26 @@ defined('MOODLE_INTERNAL') || die(); */ class element extends \mod_customcert\element { + /** + * The course short name. + */ + const COURSE_SHORT_NAME = 1; + + /** + * The course fullname. + */ + const COURSE_FULL_NAME = 2; + /** * This function renders the form elements when adding a customcert element. * * @param \MoodleQuickForm $mform the edit_form instance */ public function render_form_elements($mform) { - // The course name display options. $mform->addElement('select', 'coursenamedisplay', get_string('coursenamedisplay', 'customcertelement_coursename'), self::get_course_name_display_options()); - $mform->setType('coursenamedisplay', PARAM_ALPHA); + $mform->setType('coursenamedisplay', PARAM_INT); $mform->addHelpButton('coursenamedisplay', 'coursenamedisplay', 'customcertelement_coursename'); parent::render_form_elements($mform); @@ -103,7 +112,7 @@ class element extends \mod_customcert\element { * * @return string */ - protected function get_course_name_detail() : string { + protected function get_course_name_detail(): string { $courseid = \mod_customcert\element_helper::get_courseid($this->get_id()); $course = get_course($courseid); $context = \mod_customcert\element_helper::get_context($this->get_id()); @@ -112,7 +121,7 @@ class element extends \mod_customcert\element { $field = $this->get_data(); // The name value to display. $value = $course->fullname; - if ($field == 'courseshortdescription') { + if ($field == self::COURSE_SHORT_NAME) { $value = $course->shortname; } @@ -124,12 +133,10 @@ class element extends \mod_customcert\element { * * @return array returns an array of name options */ - public static function get_course_name_display_options() { - $coursenamedisplayoptions = array( - 'coursename' => get_string('coursename', 'customcertelement_coursename'), - 'courseshortdescription' => get_string('courseshortdescription', 'customcertelement_coursename') - ); - - return $coursenamedisplayoptions; + public static function get_course_name_display_options(): array { + return [ + self::COURSE_FULL_NAME => get_string('coursefullname', 'customcertelement_coursename'), + self::COURSE_SHORT_NAME => get_string('courseshortname', 'customcertelement_coursename') + ]; } } diff --git a/element/coursename/lang/en/customcertelement_coursename.php b/element/coursename/lang/en/customcertelement_coursename.php index df10703..d6b80d3 100644 --- a/element/coursename/lang/en/customcertelement_coursename.php +++ b/element/coursename/lang/en/customcertelement_coursename.php @@ -22,9 +22,10 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +$string['coursenamedisplay'] = 'Type'; +$string['coursenamedisplay_help'] = 'Display the course full name or short name?'; +$string['coursefullname'] = 'Full name'; +$string['courseshortname'] = 'Short name'; $string['pluginname'] = 'Course name'; $string['privacy:metadata'] = 'The Course name plugin does not store any personal data.'; -$string['coursenamedisplay'] = 'Course name / short description'; -$string['coursenamedisplay_help'] = 'Course name or short description you wish to display on certificate.'; -$string['coursename'] = 'Course name'; -$string['courseshortdescription'] = 'Course short description'; + diff --git a/tests/behat/managing_elements.feature b/tests/behat/managing_elements.feature index 54bd0b6..f734eb3 100644 --- a/tests/behat/managing_elements.feature +++ b/tests/behat/managing_elements.feature @@ -100,20 +100,22 @@ Feature: Being able to manage elements in a certificate template # Course name. And I add the element "Course name" to page "1" of the "Custom certificate 1" certificate template And I set the following fields to these values: - | Font | Helvetica | - | Size | 20 | - | Colour | #045ECD | - | Width | 20 | - | Reference point location | Top left | + | Font | Helvetica | + | Type | Short name | + | Size | 20 | + | Colour | #045ECD | + | Width | 20 | + | Reference point location | Top left | And I press "Save changes" And I should see "Course name" in the "elementstable" "table" And I click on ".edit-icon" "css_element" in the "Course name" "table_row" And the following fields match these values: - | Font | Helvetica | - | Size | 20 | - | Colour | #045ECD | - | Width | 20 | - | Reference point location | Top left | + | Font | Helvetica | + | Type | Short name | + | Size | 20 | + | Colour | #045ECD | + | Width | 20 | + | Reference point location | Top left | And I press "Save changes" # Date. And I add the element "Date" to page "1" of the "Custom certificate 1" certificate template