From 6ec75e40e0d2d82debdc4812db649163a1617d86 Mon Sep 17 00:00:00 2001 From: Jun Pataleta Date: Wed, 19 Jul 2023 12:19:39 +0800 Subject: [PATCH 1/5] MDL-77328 qtype_calculated: Add upgrade.txt notes * Question type plugins that extend qtype_calculated should be made aware of the changes about the new question_answer type \qtype_calculated\qtype_calculated_answer. --- question/type/calculated/upgrade.txt | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 question/type/calculated/upgrade.txt diff --git a/question/type/calculated/upgrade.txt b/question/type/calculated/upgrade.txt new file mode 100644 index 00000000000..00ebecaf389 --- /dev/null +++ b/question/type/calculated/upgrade.txt @@ -0,0 +1,6 @@ +This file describes API changes in /question/type/calculated/*. + +=== 4.3 === +* \qtype_calculated answers are now of the type \qtype_calculated\qtype_calculated_answer which extends \qtype_numerical_answer. + Plugins extending \qtype_calculated and still reference \qtype_numerical_answer in their code (e.g. in test helper functions) + should update their code to reference \qtype_calculated\qtype_calculated_answer instead. From 9119d4513f935359d7d1abc2ee2f36f2da63c757 Mon Sep 17 00:00:00 2001 From: Jun Pataleta Date: Wed, 19 Jul 2023 12:07:52 +0800 Subject: [PATCH 2/5] MDL-77328 qtype_caclulatedsimple: Use qtype_calculated_answer The question answers for question type plugins extending \qtype_calculated now have the type \qtype_calculated\qtype_calculated_answer. So the answers for make_calculatedsimple_question_sum() should be changed accordingly. --- question/type/calculatedsimple/tests/helper.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/question/type/calculatedsimple/tests/helper.php b/question/type/calculatedsimple/tests/helper.php index c3bca397d58..eaa3d6af1fe 100644 --- a/question/type/calculatedsimple/tests/helper.php +++ b/question/type/calculatedsimple/tests/helper.php @@ -54,10 +54,10 @@ class qtype_calculatedsimple_test_helper extends question_test_helper { $q->generalfeedback = 'Generalfeedback: {={a} + {b}} is the right answer.'; $q->answers = array( - 13 => new qtype_numerical_answer(13, '{a} + {b}', 1.0, 'Very good.', FORMAT_HTML, 0), - 14 => new qtype_numerical_answer(14, '{a} - {b}', 0.0, 'Add. not subtract!.', + 13 => new \qtype_calculated\qtype_calculated_answer(13, '{a} + {b}', 1.0, 'Very good.', FORMAT_HTML, 0), + 14 => new \qtype_calculated\qtype_calculated_answer(14, '{a} - {b}', 0.0, 'Add. not subtract!.', FORMAT_HTML, 0), - 17 => new qtype_numerical_answer(17, '*', 0.0, 'Completely wrong.', FORMAT_HTML, 0), + 17 => new \qtype_calculated\qtype_calculated_answer(17, '*', 0.0, 'Completely wrong.', FORMAT_HTML, 0), ); foreach ($q->answers as $answer) { $answer->correctanswerlength = 2; From 185c14ad1ac37e28e9052b9e274c15657f4085e8 Mon Sep 17 00:00:00 2001 From: Jun Pataleta Date: Wed, 19 Jul 2023 12:09:11 +0800 Subject: [PATCH 3/5] MDL-77328 qtype_caclulatedmulti: Use qtype_calculated_answer The question answers for question type plugins extending \qtype_calculated now have the type \qtype_calculated\qtype_calculated_answer. So the answers for test helper functions make_calculatedmulti_question_singleresponse() and make_calculatedmulti_question_multiresponse() should also be changed accordingly. --- question/type/calculatedmulti/tests/helper.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/question/type/calculatedmulti/tests/helper.php b/question/type/calculatedmulti/tests/helper.php index 25dddb1916a..92330cf2a92 100644 --- a/question/type/calculatedmulti/tests/helper.php +++ b/question/type/calculatedmulti/tests/helper.php @@ -64,9 +64,9 @@ class qtype_calculatedmulti_test_helper extends question_test_helper { $q->incorrectfeedbackformat = FORMAT_HTML; $q->shownumcorrect = 1; $q->answers = array( - 13 => new question_answer(13, '{={a} + {b}}', 1.0, 'Very good.', FORMAT_HTML), - 14 => new question_answer(14, '{={a} - {b}}', 0.0, 'Add. not subtract!', FORMAT_HTML), - 17 => new question_answer(17, '{={a} + 2 * {b}}', 0.0, 'Just add.', FORMAT_HTML), + 13 => new \qtype_calculated\qtype_calculated_answer(13, '{={a} + {b}}', 1.0, 'Very good.', FORMAT_HTML, 0), + 14 => new \qtype_calculated\qtype_calculated_answer(14, '{={a} - {b}}', 0.0, 'Add. not subtract!', FORMAT_HTML, 0), + 17 => new \qtype_calculated\qtype_calculated_answer(17, '{={a} + 2 * {b}}', 0.0, 'Just add.', FORMAT_HTML, 0), ); $q->answers[13]->correctanswerlength = 2; $q->answers[13]->correctanswerformat = 1; @@ -107,10 +107,10 @@ class qtype_calculatedmulti_test_helper extends question_test_helper { $q->incorrectfeedbackformat = FORMAT_HTML; $q->shownumcorrect = 1; $q->answers = array( - 13 => new qtype_numerical_answer(13, '{a} + {b}!', 0.5, 'Good', FORMAT_HTML, 0), - 14 => new qtype_numerical_answer(14, '{={a} + {b}}', 0.5, 'Good', + 13 => new \qtype_calculated\qtype_calculated_answer(13, '{a} + {b}!', 0.5, 'Good', FORMAT_HTML, 0), + 14 => new \qtype_calculated\qtype_calculated_answer(14, '{={a} + {b}}', 0.5, 'Good', FORMAT_HTML, 0), - 17 => new qtype_numerical_answer(17, '{={a} - {b}}', -0.5, 'Wrong.', FORMAT_HTML, 0), + 17 => new \qtype_calculated\qtype_calculated_answer(17, '{={a} - {b}}', -0.5, 'Wrong.', FORMAT_HTML, 0), ); $q->answers[13]->correctanswerlength = 2; $q->answers[13]->correctanswerformat = 1; From 73259066c4b23fc496c76513b38c395777028320 Mon Sep 17 00:00:00 2001 From: Jun Pataleta Date: Wed, 19 Jul 2023 14:23:40 +0800 Subject: [PATCH 4/5] MDL-77328 qformat_xml: Avoid dynamic declaration for question_answer Declare qformat_xml::answerfiles and qformat_xml::feedbackfiles instead of dynamically declaring answerfiles and feedbackfiles for the question_answer instance when exporting questions and answers to XML format. --- question/format/xml/format.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/question/format/xml/format.php b/question/format/xml/format.php index b50dae39b1a..52d91796841 100644 --- a/question/format/xml/format.php +++ b/question/format/xml/format.php @@ -46,6 +46,12 @@ if (!class_exists('qformat_default')) { */ class qformat_xml extends qformat_default { + /** @var array Array of files for question answers. */ + protected $answerfiles = []; + + /** @var array Array of files for feedback to question answers. */ + protected $feedbackfiles = []; + public function provide_import() { return true; } @@ -1203,9 +1209,9 @@ class qformat_xml extends qformat_default { $contextid, 'question', 'generalfeedback', $question->id); if (!empty($question->options->answers)) { foreach ($question->options->answers as $answer) { - $answer->answerfiles = $fs->get_area_files( + $this->answerfiles[$answer->id] = $fs->get_area_files( $contextid, 'question', 'answer', $answer->id); - $answer->feedbackfiles = $fs->get_area_files( + $this->feedbackfiles[$answer->id] = $fs->get_area_files( $contextid, 'question', 'answerfeedback', $answer->id); } } @@ -1593,10 +1599,10 @@ class qformat_xml extends qformat_default { $output = ''; $output .= " format($answer->answerformat)}>\n"; $output .= $this->writetext($answer->answer, 3); - $output .= $this->write_files($answer->answerfiles); + $output .= $this->write_files($this->answerfiles[$answer->id]); $output .= " format($answer->feedbackformat)}>\n"; $output .= $this->writetext($answer->feedback, 4); - $output .= $this->write_files($answer->feedbackfiles); + $output .= $this->write_files($this->feedbackfiles[$answer->id]); $output .= " \n"; $output .= $extra; $output .= " \n"; From 26905eeb93bca4a1ab6932218d72e6883cf86a8e Mon Sep 17 00:00:00 2001 From: Jun Pataleta Date: Wed, 19 Jul 2023 12:10:10 +0800 Subject: [PATCH 5/5] MDL-77328 question: Declare $qbank as a proper view_component property --- question/classes/local/bank/view_component.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/question/classes/local/bank/view_component.php b/question/classes/local/bank/view_component.php index 3932e9647a4..a50397921e3 100644 --- a/question/classes/local/bank/view_component.php +++ b/question/classes/local/bank/view_component.php @@ -26,6 +26,9 @@ namespace core_question\local\bank; */ abstract class view_component { + /** @var view Question bank view. */ + protected $qbank; + /** * Constructor. * @param view $qbank the question bank view we are helping to render.