diff --git a/edit_multianswerwiris_form.php b/edit_multianswerwiris_form.php index d43e66f..5b90889 100644 --- a/edit_multianswerwiris_form.php +++ b/edit_multianswerwiris_form.php @@ -21,7 +21,6 @@ class qtype_multianswerwiris_edit_form extends qtype_wq_edit_form { - protected function definition_inner($mform) { global $CFG; parent::definition_inner($mform); @@ -47,3 +46,18 @@ public function qtype() { return 'multianswerwiris'; } } + +class qtype_multianswer_edit_form_helper extends qtype_multianswer_edit_form { + protected function definition_inner($mform) { + // Remove wiris particle from subquestion qtypes so the multianswer form does not think + // we are changing the qtypes when we are not actually doing it. + foreach ($this->savedquestiondisplay->options->questions as $subq) { + $qtype = $subq->qtype; + if (substr($qtype, -5) == 'wiris') { + $subq->qtype = substr($qtype, 0, strlen($qtype) - 5); + } + } + + parent::definition_inner($mform); + } +} diff --git a/question.php b/question.php index 95c62ae..bb8fd29 100644 --- a/question.php +++ b/question.php @@ -392,4 +392,25 @@ public function summarise_response(array $response) { // data. return get_string('contentnotviewable', 'qtype_multianswerwiris'); } + + + public function update_attempt_state_data_for_new_version( + question_attempt_step $oldstep, + question_definition $oldquestion + ) { + // Save global state data to prevent it from being overwritten. + $qi = $oldstep->get_qt_var('_qi'); + $gc = $oldstep->get_qt_var('_gc'); + + $result = parent::update_attempt_state_data_for_new_version($oldstep, $oldquestion); + + if (isset($qi)) { + $result['_qi'] = $qi; + } + if (isset($gc)) { + $result['_gc'] = $gc; + } + + return $result; + } } diff --git a/questiontype.php b/questiontype.php index 2fe94ae..9f64335 100644 --- a/questiontype.php +++ b/questiontype.php @@ -148,7 +148,13 @@ public function save_question($authorizedquestion, $form) { $question->id = $authorizedquestion->id; } - $question->category = $authorizedquestion->category; + global $CFG; + if ($CFG->version >= 2022041900 /* Moodle 4.0.0 */) { + $question->category = $form->category; + } else { + $question->category = $authorizedquestion->category; + } + $form->defaultmark = $question->defaultmark; $form->questiontext = $question->questiontext; $form->questiontextformat = 0; @@ -160,7 +166,7 @@ public function save_question($authorizedquestion, $form) { public function create_editing_form($submiturl, $question, $category, $contexts, $formeditable) { global $CFG; require_once($CFG->dirroot . '/question/type/multianswerwiris/edit_multianswerwiris_form.php'); - $wform = $this->base->create_editing_form($submiturl, $question, $category, $contexts, $formeditable); + $wform = new qtype_multianswer_edit_form_helper($submiturl, $question, $category, $contexts, $formeditable); return new qtype_multianswerwiris_edit_form($wform, $submiturl, $question, $category, $contexts, $formeditable); } diff --git a/version.php b/version.php index 7e72dfd..0cf8a02 100644 --- a/version.php +++ b/version.php @@ -16,11 +16,11 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2024032203; +$plugin->version = 2024032204; $plugin->requires = 2015111600; // Moodle 3.0. -$plugin->release = '4.11.3'; +$plugin->release = '4.11.4'; $plugin->maturity = MATURITY_STABLE; $plugin->component = 'qtype_multianswerwiris'; $plugin->dependencies = array( - 'qtype_wq' => 2024032203 + 'qtype_wq' => 2024032204 );