@@ -209,13 +209,16 @@ private function mapQuestionType(string $quizType): string
209209 */
210210 private function getAnswersForQuestion (int $ questionId ): array
211211 {
212+ static $ globalCounter = 0 ;
212213 $ answers = [];
213214 $ quizResources = $ this ->course ->resources [RESOURCE_QUIZQUESTION ] ?? [];
214215
215216 foreach ($ quizResources as $ questionData ) {
216217 if ($ questionData ->source_id == $ questionId ) {
217218 foreach ($ questionData ->answers as $ answer ) {
219+ $ globalCounter ++;
218220 $ answers [] = [
221+ 'id ' => $ questionId * 1000 + $ globalCounter ,
219222 'text ' => $ answer ['answer ' ],
220223 'fraction ' => $ answer ['correct ' ] == '1 ' ? 100 : 0 ,
221224 'feedback ' => $ answer ['comment ' ],
@@ -316,16 +319,18 @@ private function createQuizXml(array $quizData, string $destinationDir): void
316319
317320 // Add question instances
318321 $ xmlContent .= ' <question_instances> ' .PHP_EOL ;
322+ $ slotIndex = 1 ;
319323 foreach ($ quizData ['questions ' ] as $ question ) {
320324 $ xmlContent .= ' <question_instance id=" ' .$ question ['id ' ].'"> ' .PHP_EOL ;
321- $ xmlContent .= ' <slot> ' .$ question [ ' id ' ] .'</slot> ' .PHP_EOL ;
325+ $ xmlContent .= ' <slot> ' .$ slotIndex .'</slot> ' .PHP_EOL ;
322326 $ xmlContent .= ' <page>1</page> ' .PHP_EOL ;
323327 $ xmlContent .= ' <requireprevious>0</requireprevious> ' .PHP_EOL ;
324328 $ xmlContent .= ' <questionid> ' .$ question ['id ' ].'</questionid> ' .PHP_EOL ;
325329 $ xmlContent .= ' <questioncategoryid> ' .$ question ['questioncategoryid ' ].'</questioncategoryid> ' .PHP_EOL ;
326330 $ xmlContent .= ' <includingsubcategories>$@NULL@$</includingsubcategories> ' .PHP_EOL ;
327331 $ xmlContent .= ' <maxmark> ' .$ question ['maxmark ' ].'</maxmark> ' .PHP_EOL ;
328332 $ xmlContent .= ' </question_instance> ' .PHP_EOL ;
333+ $ slotIndex ++;
329334 }
330335 $ xmlContent .= ' </question_instances> ' .PHP_EOL ;
331336
@@ -417,8 +422,10 @@ private function exportTrueFalseQuestion(array $question): string
417422 }
418423 $ xmlContent .= ' </answers> ' .PHP_EOL ;
419424 $ 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 ;
422429 $ xmlContent .= ' </truefalse> ' .PHP_EOL ;
423430 $ xmlContent .= ' </plugin_qtype_truefalse_question> ' .PHP_EOL ;
424431
0 commit comments