@@ -209,13 +209,16 @@ private function mapQuestionType(string $quizType): string
209
209
*/
210
210
private function getAnswersForQuestion (int $ questionId ): array
211
211
{
212
+ static $ globalCounter = 0 ;
212
213
$ answers = [];
213
214
$ quizResources = $ this ->course ->resources [RESOURCE_QUIZQUESTION ] ?? [];
214
215
215
216
foreach ($ quizResources as $ questionData ) {
216
217
if ($ questionData ->source_id == $ questionId ) {
217
218
foreach ($ questionData ->answers as $ answer ) {
219
+ $ globalCounter ++;
218
220
$ answers [] = [
221
+ 'id ' => $ questionId * 1000 + $ globalCounter ,
219
222
'text ' => $ answer ['answer ' ],
220
223
'fraction ' => $ answer ['correct ' ] == '1 ' ? 100 : 0 ,
221
224
'feedback ' => $ answer ['comment ' ],
@@ -316,16 +319,18 @@ private function createQuizXml(array $quizData, string $destinationDir): void
316
319
317
320
// Add question instances
318
321
$ xmlContent .= ' <question_instances> ' .PHP_EOL ;
322
+ $ slotIndex = 1 ;
319
323
foreach ($ quizData ['questions ' ] as $ question ) {
320
324
$ xmlContent .= ' <question_instance id=" ' .$ question ['id ' ].'"> ' .PHP_EOL ;
321
- $ xmlContent .= ' <slot> ' .$ question [ ' id ' ] .'</slot> ' .PHP_EOL ;
325
+ $ xmlContent .= ' <slot> ' .$ slotIndex .'</slot> ' .PHP_EOL ;
322
326
$ xmlContent .= ' <page>1</page> ' .PHP_EOL ;
323
327
$ xmlContent .= ' <requireprevious>0</requireprevious> ' .PHP_EOL ;
324
328
$ xmlContent .= ' <questionid> ' .$ question ['id ' ].'</questionid> ' .PHP_EOL ;
325
329
$ xmlContent .= ' <questioncategoryid> ' .$ question ['questioncategoryid ' ].'</questioncategoryid> ' .PHP_EOL ;
326
330
$ xmlContent .= ' <includingsubcategories>$@NULL@$</includingsubcategories> ' .PHP_EOL ;
327
331
$ xmlContent .= ' <maxmark> ' .$ question ['maxmark ' ].'</maxmark> ' .PHP_EOL ;
328
332
$ xmlContent .= ' </question_instance> ' .PHP_EOL ;
333
+ $ slotIndex ++;
329
334
}
330
335
$ xmlContent .= ' </question_instances> ' .PHP_EOL ;
331
336
@@ -417,8 +422,10 @@ private function exportTrueFalseQuestion(array $question): string
417
422
}
418
423
$ xmlContent .= ' </answers> ' .PHP_EOL ;
419
424
$ xmlContent .= ' <truefalse id=" ' .($ question ['id ' ] ?? '0 ' ).'"> ' .PHP_EOL ;
420
- $ xmlContent .= ' <trueanswer> ' .($ question ['answers ' ][0 ]['id ' ] ?? '0 ' ).'</trueanswer> ' .PHP_EOL ;
421
- $ xmlContent .= ' <falseanswer> ' .($ question ['answers ' ][1 ]['id ' ] ?? '0 ' ).'</falseanswer> ' .PHP_EOL ;
425
+ $ trueId = $ question ['answers ' ][0 ]['id ' ] ?? 0 ;
426
+ $ falseId = $ question ['answers ' ][1 ]['id ' ] ?? 0 ;
427
+ $ xmlContent .= ' <trueanswer> ' .$ trueId .'</trueanswer> ' .PHP_EOL ;
428
+ $ xmlContent .= ' <falseanswer> ' .$ falseId .'</falseanswer> ' .PHP_EOL ;
422
429
$ xmlContent .= ' </truefalse> ' .PHP_EOL ;
423
430
$ xmlContent .= ' </plugin_qtype_truefalse_question> ' .PHP_EOL ;
424
431
0 commit comments