mirror of
https://github.com/moodle/moodle.git
synced 2025-04-09 02:12:22 +02:00
MDL-70823 qtype_ddwtos: new method for safer feedback unserializing.
This commit is contained in:
parent
b0cb1b8cea
commit
faddd24a13
@ -41,9 +41,9 @@ class qtype_ddwtos_edit_form extends qtype_gapselect_edit_form_base {
|
||||
|
||||
protected function data_preprocessing_choice($question, $answer, $key) {
|
||||
$question = parent::data_preprocessing_choice($question, $answer, $key);
|
||||
$options = unserialize($answer->feedback);
|
||||
$question->choices[$key]['choicegroup'] = $options->draggroup;
|
||||
$question->choices[$key]['infinite'] = $options->infinite;
|
||||
$options = unserialize_object($answer->feedback);
|
||||
$question->choices[$key]['choicegroup'] = $options->draggroup ?? 1;
|
||||
$question->choices[$key]['infinite'] = !empty($options->infinite);
|
||||
return $question;
|
||||
}
|
||||
|
||||
|
@ -49,13 +49,27 @@ class qtype_ddwtos extends qtype_gapselect_base {
|
||||
return serialize($output);
|
||||
}
|
||||
|
||||
/**
|
||||
* Safely convert given serialized feedback string into valid feedback object
|
||||
*
|
||||
* @param string $feedback
|
||||
* @return stdClass
|
||||
*/
|
||||
protected function unserialize_feedback(string $feedback): stdClass {
|
||||
$feedbackobject = unserialize_object($feedback);
|
||||
|
||||
return (object) [
|
||||
'draggroup' => $feedbackobject->draggroup ?? 1,
|
||||
'infinite' => !empty($feedbackobject->infinite),
|
||||
];
|
||||
}
|
||||
|
||||
protected function feedback_to_choice_options($feedback) {
|
||||
$feedbackobj = unserialize($feedback);
|
||||
return array('draggroup' => $feedbackobj->draggroup, 'infinite' => $feedbackobj->infinite);
|
||||
return (array) $this->unserialize_feedback($feedback);
|
||||
}
|
||||
|
||||
protected function make_choice($choicedata) {
|
||||
$options = unserialize($choicedata->feedback);
|
||||
$options = $this->unserialize_feedback($choicedata->feedback);
|
||||
return new qtype_ddwtos_choice(
|
||||
$choicedata->answer, $options->draggroup, $options->infinite);
|
||||
}
|
||||
@ -102,7 +116,7 @@ class qtype_ddwtos extends qtype_gapselect_base {
|
||||
$question->contextid);
|
||||
|
||||
foreach ($question->options->answers as $answer) {
|
||||
$options = unserialize($answer->feedback);
|
||||
$options = $this->unserialize_feedback($answer->feedback);
|
||||
|
||||
$output .= " <dragbox>\n";
|
||||
$output .= $format->writetext($answer->answer, 3);
|
||||
|
Loading…
x
Reference in New Issue
Block a user