| Línea 108... |
Línea 108... |
| 108 |
public function get_question_options($question) {
|
108 |
public function get_question_options($question) {
|
| 109 |
global $DB;
|
109 |
global $DB;
|
| Línea 110... |
Línea 110... |
| 110 |
|
110 |
|
| 111 |
parent::get_question_options($question);
|
111 |
parent::get_question_options($question);
|
| 112 |
// Get relevant data indexed by positionkey from the multianswers table.
|
112 |
// Get relevant data indexed by positionkey from the multianswers table.
|
| 113 |
$sequence = $DB->get_field('question_multianswer', 'sequence',
|
- |
|
| Línea 114... |
Línea 113... |
| 114 |
array('question' => $question->id), MUST_EXIST);
|
113 |
$sequence = $DB->get_field('question_multianswer', 'sequence', ['question' => $question->id]);
|
| 115 |
|
114 |
|
| 116 |
if (empty($sequence)) {
|
115 |
if (empty($sequence)) {
|
| 117 |
$question->options->questions = [];
|
116 |
$question->options->questions = [];
|
| Línea 160... |
Línea 159... |
| 160 |
$result = new stdClass();
|
159 |
$result = new stdClass();
|
| Línea 161... |
Línea 160... |
| 161 |
|
160 |
|
| 162 |
// This function needs to be able to handle the case where the existing set of wrapped
|
161 |
// This function needs to be able to handle the case where the existing set of wrapped
|
| 163 |
// questions does not match the new set of wrapped questions so that some need to be
|
162 |
// questions does not match the new set of wrapped questions so that some need to be
|
| 164 |
// created, some modified and some deleted.
|
163 |
// created, some modified and some deleted.
|
| 165 |
// Unfortunately the code currently simply overwrites existing ones in sequence. This
|
164 |
// Thanks to versioning, we no longer overwrite existing questions in the sequence
|
| 166 |
// will make re-marking after a re-ordering of wrapped questions impossible and
|
165 |
// by re-using IDs, but instead create a new version of each wrapped question for
|
| Línea 167... |
Línea 166... |
| 167 |
// will also create difficulties if questiontype specific tables reference the id.
|
166 |
// the new version of the parent.
|
| 168 |
|
167 |
|
| 169 |
// First we get all the existing wrapped questions.
|
168 |
// First we get all the existing wrapped questions.
|
| 170 |
$oldwrappedquestions = [];
|
169 |
$oldwrappedquestions = [];
|
| Línea 184... |
Línea 183... |
| 184 |
}
|
183 |
}
|
| Línea 185... |
Línea 184... |
| 185 |
|
184 |
|
| 186 |
$sequence = array();
|
185 |
$sequence = array();
|
| 187 |
foreach ($question->options->questions as $wrapped) {
|
186 |
foreach ($question->options->questions as $wrapped) {
|
| 188 |
if (!empty($wrapped)) {
|
187 |
if (!empty($wrapped)) {
|
| - |
|
188 |
// If we still have some old wrapped question ids, reuse the next of them to save
|
| 189 |
// If we still have some old wrapped question ids, reuse the next of them.
|
189 |
// the new version against its question bank entry.
|
| 190 |
$wrapped->id = 0;
|
190 |
$wrapped->id = 0;
|
| 191 |
if (is_array($oldwrappedquestions) &&
|
191 |
if (is_array($oldwrappedquestions) &&
|
| 192 |
$oldwrappedquestion = array_shift($oldwrappedquestions)) {
|
192 |
$oldwrappedquestion = array_shift($oldwrappedquestions)) {
|
| 193 |
$wrapped->oldid = $oldwrappedquestion->id;
|
- |
|
| 194 |
if ($oldwrappedquestion->qtype != $wrapped->qtype) {
|
- |
|
| 195 |
switch ($oldwrappedquestion->qtype) {
|
- |
|
| 196 |
case 'multichoice':
|
- |
|
| 197 |
$DB->delete_records('qtype_multichoice_options',
|
- |
|
| 198 |
array('questionid' => $oldwrappedquestion->id));
|
- |
|
| 199 |
break;
|
- |
|
| 200 |
case 'shortanswer':
|
- |
|
| 201 |
$DB->delete_records('qtype_shortanswer_options',
|
- |
|
| 202 |
array('questionid' => $oldwrappedquestion->id));
|
- |
|
| 203 |
break;
|
- |
|
| 204 |
case 'numerical':
|
- |
|
| 205 |
$DB->delete_records('question_numerical',
|
- |
|
| 206 |
array('question' => $oldwrappedquestion->id));
|
- |
|
| 207 |
break;
|
- |
|
| 208 |
default:
|
- |
|
| 209 |
throw new moodle_exception('qtypenotrecognized',
|
- |
|
| 210 |
'qtype_multianswer', '', $oldwrappedquestion->qtype);
|
- |
|
| 211 |
}
|
- |
|
| 212 |
}
|
193 |
$wrapped->oldid = $oldwrappedquestion->id;
|
| 213 |
}
|
194 |
}
|
| 214 |
}
|
195 |
}
|
| 215 |
$wrapped->name = $question->name;
|
196 |
$wrapped->name = $question->name;
|
| 216 |
$wrapped->parent = $question->id;
|
197 |
$wrapped->parent = $question->id;
|