MDL-79863 qtype_ordering: qtype_ordering in edit form, rename 'get_default_value()' method to 'get_my_default_value()' for compatability with Moodle >= 3.10

This commit is contained in:
Gordon Bateson
2024-04-04 10:59:30 +08:00
committed by Mathew May
parent c74e93c23c
commit 8973b055d3
3 changed files with 19 additions and 22 deletions
+3
View File
@@ -2,6 +2,9 @@
Change log for qtype_ordering
========================================
2021-06-09 (02)
- in edit form, rename 'get_default_value()' method to 'get_my_default_value()' for compatability with Moodle >= 3.10
2021-06-08 (01)
- modify declaration of parameters accepted by get_default_value method in the edit form
+14 -20
View File
@@ -81,7 +81,7 @@ class qtype_ordering_edit_form extends question_edit_form {
$options = qtype_ordering_question::get_layout_types();
$mform->addElement('select', $name, $label, $options);
$mform->addHelpButton($name, $name, $plugin);
$mform->setDefault($name, $this->get_default_value($name, qtype_ordering_question::LAYOUT_VERTICAL));
$mform->setDefault($name, $this->get_my_default_value($name, qtype_ordering_question::LAYOUT_VERTICAL));
// Field for selecttype.
$name = 'selecttype';
@@ -89,7 +89,7 @@ class qtype_ordering_edit_form extends question_edit_form {
$options = qtype_ordering_question::get_select_types();
$mform->addElement('select', $name, $label, $options);
$mform->addHelpButton($name, $name, $plugin);
$mform->setDefault($name, $this->get_default_value($name, qtype_ordering_question::SELECT_ALL));
$mform->setDefault($name, $this->get_my_default_value($name, qtype_ordering_question::SELECT_ALL));
// Field for selectcount.
$name = 'selectcount';
@@ -109,7 +109,7 @@ class qtype_ordering_edit_form extends question_edit_form {
$options = qtype_ordering_question::get_grading_types();
$mform->addElement('select', $name, $label, $options);
$mform->addHelpButton($name, $name, $plugin);
$mform->setDefault($name, $this->get_default_value($name, qtype_ordering_question::GRADING_ABSOLUTE_POSITION));
$mform->setDefault($name, $this->get_my_default_value($name, qtype_ordering_question::GRADING_ABSOLUTE_POSITION));
// Field for showgrading.
$name = 'showgrading';
@@ -118,14 +118,14 @@ class qtype_ordering_edit_form extends question_edit_form {
1 => get_string('show'));
$mform->addElement('select', $name, $label, $options);
$mform->addHelpButton($name, $name, $plugin);
$mform->setDefault($name, $this->get_default_value($name, 1));
$mform->setDefault($name, $this->get_my_default_value($name, 1));
$name = 'numberingstyle';
$label = get_string($name, $plugin);
$options = qtype_ordering_question::get_numbering_styles();
$mform->addElement('select', $name, $label, $options);
$mform->addHelpButton($name, $name, $plugin);
$mform->setDefault($name, $this->get_default_value($name, qtype_ordering_question::NUMBERING_STYLE_DEFAULT));
$mform->setDefault($name, $this->get_my_default_value($name, qtype_ordering_question::NUMBERING_STYLE_DEFAULT));
$elements = array();
$options = array();
@@ -351,7 +351,7 @@ class qtype_ordering_edit_form extends question_edit_form {
if (isset($question->options->$name)) {
$question->$name = $question->options->$name;
} else {
$question->$name = $this->get_default_value($name, $default);
$question->$name = $this->get_my_default_value($name, $default);
}
}
@@ -418,22 +418,16 @@ class qtype_ordering_edit_form extends question_edit_form {
* @param string|mixed|null $default Default value (optional, default = null)
* @return string|mixed|null Default value for field with this $name
*/
protected function get_default_value(string $name, $default) {
return get_user_preferences("qtype_ordering_$name", $default);
protected function get_my_default_value($name, $default) {
if (method_exists($this, 'get_default_value')) {
// Moodle >= 3.10
return $this->get_default_value($name, $default);
} else {
// Moodle <= 3.9
return get_user_preferences($this->plugin_name().'_'.$name, $default);
}
}
/**
* Saves default value for item
*
* @param string $name Item name
* @param string|mixed|null $value
* @return bool Always true or exception
*/
protected function set_default_value($name, $value) {
return set_user_preferences(array("qtype_ordering_$name" => $value));
}
/**
* Get array of countable item types
*
+2 -2
View File
@@ -29,5 +29,5 @@ $plugin->cron = 0;
$plugin->component = 'qtype_ordering';
$plugin->maturity = MATURITY_STABLE;
$plugin->requires = 2015051100; // Moodle 2.9.
$plugin->version = 2021060801;
$plugin->release = '2021-06-08 (01)';
$plugin->version = 2021060902;
$plugin->release = '2021-06-09 (02)';