MDL-77328 qtype_multianswer: Refactor for PHP 8.2 compatibility
This commit addresses compatibility issues in the qtype_multianswer question type. The following changes were made: - The usage of the undeclared property $maxmark on subquestions in qtype_multianswer was identified as problematic. To resolve this, the existing declared property $defaultmark is now being used for the same purpose. By switching to the declared property $defaultmark, compatibility with PHP 8.2 is ensured and the issue with the undeclared property is resolved.
This commit is contained in:
@@ -146,7 +146,6 @@ class qtype_multianswer extends question_type {
|
||||
question_bank::get_qtype($wrapped->qtype)->get_question_options($wrapped);
|
||||
// For wrapped questions the maxgrade is always equal to the defaultmark,
|
||||
// there is no entry in the question_instances table for them.
|
||||
$wrapped->maxmark = $wrapped->defaultmark;
|
||||
$wrapped->category = $question->categoryobject->id;
|
||||
$question->options->questions[$sequence[$wrapped->id]] = $wrapped;
|
||||
}
|
||||
@@ -303,7 +302,7 @@ class qtype_multianswer extends question_type {
|
||||
}
|
||||
}
|
||||
$question->subquestions[$key] = question_bank::make_question($subqdata);
|
||||
$question->subquestions[$key]->maxmark = $subqdata->defaultmark;
|
||||
$question->subquestions[$key]->defaultmark = $subqdata->defaultmark;
|
||||
if (isset($subqdata->options->layout)) {
|
||||
$question->subquestions[$key]->layout = $subqdata->options->layout;
|
||||
}
|
||||
|
||||
@@ -183,11 +183,11 @@ abstract class qtype_multianswer_subq_renderer_base extends qtype_renderer {
|
||||
}
|
||||
|
||||
$subfraction = '';
|
||||
if ($options->marks >= question_display_options::MARK_AND_MAX && $subq->maxmark > 0
|
||||
if ($options->marks >= question_display_options::MARK_AND_MAX && $subq->defaultmark > 0
|
||||
&& (!is_null($fraction) || $feedback)) {
|
||||
$a = new stdClass();
|
||||
$a->mark = format_float($fraction * $subq->maxmark, $options->markdp);
|
||||
$a->max = format_float($subq->maxmark, $options->markdp);
|
||||
$a->mark = format_float($fraction * $subq->defaultmark, $options->markdp);
|
||||
$a->max = format_float($subq->defaultmark, $options->markdp);
|
||||
$feedback[] = get_string('markoutofmax', 'question', $a);
|
||||
}
|
||||
|
||||
@@ -483,10 +483,10 @@ class qtype_multianswer_multichoice_vertical_renderer extends qtype_multianswer_
|
||||
|
||||
$feedback = array();
|
||||
if ($options->feedback && $options->marks >= question_display_options::MARK_AND_MAX &&
|
||||
$subq->maxmark > 0) {
|
||||
$subq->defaultmark > 0) {
|
||||
$a = new stdClass();
|
||||
$a->mark = format_float($fraction * $subq->maxmark, $options->markdp);
|
||||
$a->max = format_float($subq->maxmark, $options->markdp);
|
||||
$a->mark = format_float($fraction * $subq->defaultmark, $options->markdp);
|
||||
$a->max = format_float($subq->defaultmark, $options->markdp);
|
||||
|
||||
$feedback[] = html_writer::tag('div', get_string('markoutofmax', 'question', $a));
|
||||
}
|
||||
@@ -675,10 +675,10 @@ class qtype_multianswer_multiresponse_vertical_renderer extends qtype_multianswe
|
||||
|
||||
$feedback = array();
|
||||
if ($options->feedback && $options->marks >= question_display_options::MARK_AND_MAX &&
|
||||
$subq->maxmark > 0) {
|
||||
$subq->defaultmark > 0) {
|
||||
$a = new stdClass();
|
||||
$a->mark = format_float($fraction * $subq->maxmark, $options->markdp);
|
||||
$a->max = format_float($subq->maxmark, $options->markdp);
|
||||
$a->mark = format_float($fraction * $subq->defaultmark, $options->markdp);
|
||||
$a->max = format_float($subq->defaultmark, $options->markdp);
|
||||
|
||||
$feedback[] = html_writer::tag('div', get_string('markoutofmax', 'question', $a));
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ class qtype_multianswer_test_helper extends question_test_helper {
|
||||
15 => new question_answer(15, '*', 0.0, 'Wrong answer', FORMAT_HTML),
|
||||
);
|
||||
$sa->qtype = question_bank::get_qtype('shortanswer');
|
||||
$sa->maxmark = 1;
|
||||
$sa->defaultmark = 1;
|
||||
|
||||
// Multiple-choice subquestion.
|
||||
question_bank::load_question_definition_classes('multichoice');
|
||||
@@ -104,7 +104,7 @@ class qtype_multianswer_test_helper extends question_test_helper {
|
||||
'Well done!', FORMAT_HTML),
|
||||
);
|
||||
$mc->qtype = question_bank::get_qtype('multichoice');
|
||||
$mc->maxmark = 1;
|
||||
$mc->defaultmark = 1;
|
||||
|
||||
$q->subquestions = array(
|
||||
1 => $sa,
|
||||
@@ -342,7 +342,7 @@ class qtype_multianswer_test_helper extends question_test_helper {
|
||||
$data['Arizona'], FORMAT_HTML),
|
||||
);
|
||||
$mc->qtype = question_bank::get_qtype('multichoice');
|
||||
$mc->maxmark = 1;
|
||||
$mc->defaultmark = 1;
|
||||
|
||||
$q->subquestions[$i] = $mc;
|
||||
}
|
||||
@@ -385,7 +385,7 @@ class qtype_multianswer_test_helper extends question_test_helper {
|
||||
);
|
||||
$sub->qtype = question_bank::get_qtype('numerical');
|
||||
$sub->ap = new qtype_numerical_answer_processor(array());
|
||||
$sub->maxmark = 1;
|
||||
$sub->defaultmark = 1;
|
||||
|
||||
$q->subquestions = array(
|
||||
1 => $sub,
|
||||
@@ -444,7 +444,7 @@ class qtype_multianswer_test_helper extends question_test_helper {
|
||||
'', FORMAT_HTML),
|
||||
);
|
||||
$mc->qtype = question_bank::get_qtype('multichoice');
|
||||
$mc->maxmark = 1;
|
||||
$mc->defaultmark = 1;
|
||||
|
||||
// Multiple-choice subquestion.
|
||||
question_bank::load_question_definition_classes('multichoice');
|
||||
@@ -474,7 +474,7 @@ class qtype_multianswer_test_helper extends question_test_helper {
|
||||
'Correct', FORMAT_HTML),
|
||||
);
|
||||
$mc2->qtype = question_bank::get_qtype('multichoice');
|
||||
$mc2->maxmark = 1;
|
||||
$mc2->defaultmark = 1;
|
||||
|
||||
$q->subquestions = array(
|
||||
1 => $mc,
|
||||
|
||||
@@ -88,7 +88,7 @@ abstract class question_definition {
|
||||
/** @var integer question test format. */
|
||||
public $generalfeedbackformat;
|
||||
|
||||
/** @var number what this quetsion is marked out of, by default. */
|
||||
/** @var float what this quetsion is marked out of, by default. */
|
||||
public $defaultmark = 1;
|
||||
|
||||
/** @var integer How many question numbers this question consumes. */
|
||||
|
||||
Reference in New Issue
Block a user