From 164bca54d6ecb9336ec91cdd2841efb1e14f23ab Mon Sep 17 00:00:00 2001 From: Gordon Bateson Date: Sun, 13 Jun 2021 09:58:21 +0900 Subject: [PATCH] MDL-79863 qtype_ordering: qtype_ordering fix Issue #63. Restore missing method 'set_default_value()' --- question/type/ordering/CHANGES.txt | 3 ++ question/type/ordering/edit_ordering_form.php | 34 +++++++++++++++++-- question/type/ordering/version.php | 4 +-- 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/question/type/ordering/CHANGES.txt b/question/type/ordering/CHANGES.txt index c59b4711a50..18ea9d74708 100644 --- a/question/type/ordering/CHANGES.txt +++ b/question/type/ordering/CHANGES.txt @@ -2,6 +2,9 @@ Change log for qtype_ordering ======================================== +2021-06-13 (03) + - fix Issue #63. Restore missing method 'set_default_value()' + 2021-06-09 (02) - add message to CHANGES.txt diff --git a/question/type/ordering/edit_ordering_form.php b/question/type/ordering/edit_ordering_form.php index 183c73605ed..36895da0311 100644 --- a/question/type/ordering/edit_ordering_form.php +++ b/question/type/ordering/edit_ordering_form.php @@ -403,7 +403,7 @@ class qtype_ordering_edit_form extends question_edit_form { 'gradingtype', 'showgrading', 'numberingstyle'); foreach ($fields as $field) { if (array_key_exists($field, $data)) { - $this->set_default_value($field, $data[$field]); + $this->set_my_default_value($field, $data[$field]); } } } @@ -411,6 +411,35 @@ class qtype_ordering_edit_form extends question_edit_form { return $errors; } + /** + * Given a preference item name, returns the full + * preference name of that item for this plugin + * + * @param string $name Item name + * @return string full preference name + */ + protected function get_my_preference_name($name) { + return $this->plugin_name()."_$name"; + } + + /** + * Saves default value for item + * + * @param string $name Item name + * @param string|mixed|null $value + * @return boolean (usually TRUE, unless there is an error) + */ + protected function set_my_default_value($name, $value) { + if (method_exists($this, 'set_default_value')) { + // This method doesn't exist yet, but it might one day ;-) + return $this->set_default_value($name, $value); + } else { + // Until at least Moodle <= 4.0, we expect to come this way + $name = $this->get_my_preference_name($name); + return set_user_preferences(array($name => $value)); + } + } + /** * Returns default value for item * @@ -424,7 +453,8 @@ class qtype_ordering_edit_form extends question_edit_form { return $this->get_default_value($name, $default); } else { // Moodle <= 3.9 - return get_user_preferences($this->plugin_name().'_'.$name, $default); + $name = $this->get_my_preference_name($name); + return get_user_preferences($name, $default); } } diff --git a/question/type/ordering/version.php b/question/type/ordering/version.php index 7cc452c41d2..b68f6c00531 100644 --- a/question/type/ordering/version.php +++ b/question/type/ordering/version.php @@ -29,5 +29,5 @@ $plugin->cron = 0; $plugin->component = 'qtype_ordering'; $plugin->maturity = MATURITY_STABLE; $plugin->requires = 2015051100; // Moodle 2.9. -$plugin->version = 2021060902; -$plugin->release = '2021-06-09 (02)'; +$plugin->version = 2021061303; +$plugin->release = '2021-06-13 (03)';