MDL-77328 qtype_truefalse: Refactor for PHP 8.2 compatibility
This commit addresses the following issues and improvements in the qtype_truefalse class: - Added missing class properties: - public $truefeedbackformat - public $falsefeedbackformat - public $showstandardinstruction - Updated qtype_truefalse_question to include type hinting for better IDE support.
This commit is contained in:
@@ -41,6 +41,15 @@ class qtype_truefalse_question extends question_graded_automatically {
|
||||
public $trueanswerid;
|
||||
public $falseanswerid;
|
||||
|
||||
/** @var int the format of the true feedback. */
|
||||
public $truefeedbackformat;
|
||||
|
||||
/** @var int the format of the false feedback. */
|
||||
public $falsefeedbackformat;
|
||||
|
||||
/** @var bool true to show the standard instruction, otherwise hide it. */
|
||||
public $showstandardinstruction;
|
||||
|
||||
public function get_expected_data() {
|
||||
return array('answer' => PARAM_INT);
|
||||
}
|
||||
|
||||
@@ -142,11 +142,9 @@ class qtype_truefalse extends question_type {
|
||||
protected function initialise_question_instance(question_definition $question, $questiondata) {
|
||||
parent::initialise_question_instance($question, $questiondata);
|
||||
$answers = $questiondata->options->answers;
|
||||
if ($answers[$questiondata->options->trueanswer]->fraction > 0.99) {
|
||||
$question->rightanswer = true;
|
||||
} else {
|
||||
$question->rightanswer = false;
|
||||
}
|
||||
|
||||
/** @var qtype_truefalse_question $question */
|
||||
$question->rightanswer = $answers[$questiondata->options->trueanswer]->fraction > 0.99;
|
||||
$question->truefeedback = $answers[$questiondata->options->trueanswer]->feedback;
|
||||
$question->falsefeedback = $answers[$questiondata->options->falseanswer]->feedback;
|
||||
$question->truefeedbackformat =
|
||||
|
||||
@@ -37,6 +37,7 @@ class qtype_truefalse_renderer extends qtype_renderer {
|
||||
public function formulation_and_controls(question_attempt $qa,
|
||||
question_display_options $options) {
|
||||
|
||||
/** @var qtype_truefalse_question $question */
|
||||
$question = $qa->get_question();
|
||||
$response = $qa->get_last_qt_var('answer', '');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user