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. 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"; 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. 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; 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;