64
64
$questioncreated = $this->get_mappingid('question_created', $oldquestionid) ? true : false;
66
66
// If the question has been created by restore, we need to create its
67
// question_randomsamatch too.
67
// qtype_randomsamatch_options too.
68
68
if ($questioncreated) {
69
// Fill in some field that were added in 2.1, and so which may be missing
70
// from backups made in older versions of Moodle.
71
if (!isset($data->subcats)) {
74
if (!isset($data->correctfeedback)) {
75
$data->correctfeedback = '';
76
$data->correctfeedbackformat = FORMAT_HTML;
78
if (!isset($data->partiallycorrectfeedback)) {
79
$data->partiallycorrectfeedback = '';
80
$data->partiallycorrectfeedbackformat = FORMAT_HTML;
82
if (!isset($data->incorrectfeedback)) {
83
$data->incorrectfeedback = '';
84
$data->incorrectfeedbackformat = FORMAT_HTML;
86
if (!isset($data->shownumcorrect)) {
87
$data->shownumcorrect = 0;
69
89
// Adjust some columns.
70
$data->question = $newquestionid;
90
$data->questionid = $newquestionid;
72
$newitemid = $DB->insert_record('question_randomsamatch', $data);
92
$newitemid = $DB->insert_record('qtype_randomsamatch_options', $data);
74
$this->set_mapping('question_randomsamatch', $oldid, $newitemid);
94
$this->set_mapping('qtype_randomsamatch_options', $oldid, $newitemid);
82
102
* answer is one comma separated list of hypen separated pairs
83
103
* containing question->id and question_answers->id
85
public function recode_state_answer($state) {
105
public function recode_legacy_state_answer($state) {
86
106
$answer = $state->answer;
87
107
$resultarr = array();
88
108
foreach (explode(',', $answer) as $pair) {
96
116
return implode(',', $resultarr);
120
* Return the contents of this qtype to be processed by the links decoder.
122
public static function define_decode_contents() {
126
$fields = array('correctfeedback', 'partiallycorrectfeedback', 'incorrectfeedback');
127
$contents[] = new restore_decode_content('qtype_randomsamatch_options', $fields, 'qtype_randomsamatch_options');