Minor code changes (#415)

This commit is contained in:
Mark Nelson 2021-08-03 19:21:07 +08:00
parent a1f0e6dec7
commit 8b8a358790
3 changed files with 35 additions and 25 deletions

View file

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

View file

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

View file

@ -101,6 +101,7 @@ Feature: Being able to manage elements in a certificate template
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 |
| Type | Short name |
| Size | 20 |
| Colour | #045ECD |
| Width | 20 |
@ -110,6 +111,7 @@ Feature: Being able to manage elements in a certificate template
And I click on ".edit-icon" "css_element" in the "Course name" "table_row"
And the following fields match these values:
| Font | Helvetica |
| Type | Short name |
| Size | 20 |
| Colour | #045ECD |
| Width | 20 |