Browse Source

Quiz: Fix export/import QTI questions #2890

Angel Fernando Quiroz Campos 5 years ago
parent
commit
a4e9dbbb5d
2 changed files with 50 additions and 12 deletions
  1. 41 12
      main/exercise/export/qti2/qti2_classes.php
  2. 9 0
      main/exercise/export/qti2/qti2_export.php

+ 41 - 12
main/exercise/export/qti2/qti2_classes.php

@@ -1,6 +1,28 @@
 <?php
 /* For licensing terms, see /license.txt */
 
+/**
+ * Interface ImsAnswerInterface
+ */
+interface ImsAnswerInterface
+{
+    /**
+     * @param $questionIdent
+     * @param $questionStatment
+     *
+     * @return mixed
+     */
+    public function imsExportResponses($questionIdent, $questionStatment);
+
+    /**
+     * @param               $questionIdent
+     * @param Question|null $question
+     *
+     * @return mixed
+     */
+    public function imsExportResponsesDeclaration($questionIdent, Question $question = null);
+}
+
 /**
  * @author Claro Team <cvs@claroline.net>
  * @author Yannick Warnier <yannick.warnier@beeznest.com> -
@@ -74,7 +96,7 @@ class Ims2Question extends Question
  *
  * @package chamilo.exercise
  */
-class ImsAnswerMultipleChoice extends Answer
+class ImsAnswerMultipleChoice extends Answer implements ImsAnswerInterface
 {
     /**
      * Return the XML flow for the possible answers.
@@ -105,7 +127,7 @@ class ImsAnswerMultipleChoice extends Answer
     /**
      * Return the XML flow of answer ResponsesDeclaration.
      */
-    public function imsExportResponsesDeclaration($questionIdent)
+    public function imsExportResponsesDeclaration($questionIdent, Question $question = null)
     {
         $this->answerList = $this->getAnswersList(true);
         $type = $this->getQuestionType();
@@ -150,8 +172,11 @@ class ImsAnswerMultipleChoice extends Answer
  *
  * @package chamilo.exercise
  */
-class ImsAnswerFillInBlanks extends Answer
+class ImsAnswerFillInBlanks extends Answer implements ImsAnswerInterface
 {
+    private $answerList = [];
+    private $gradeList = [];
+
     /**
      * Export the text with missing words.
      */
@@ -171,7 +196,7 @@ class ImsAnswerFillInBlanks extends Answer
         return $text;
     }
 
-    public function imsExportResponsesDeclaration($questionIdent)
+    public function imsExportResponsesDeclaration($questionIdent, Question $question = null)
     {
         $this->answerList = $this->getAnswersList(true);
         $this->gradeList = $this->getGradesList();
@@ -203,10 +228,11 @@ class ImsAnswerFillInBlanks extends Answer
  *
  * @package chamilo.exercise
  */
-class ImsAnswerMatching extends Answer
+class ImsAnswerMatching extends Answer implements ImsAnswerInterface
 {
-    public $leftList;
-    public $rightList;
+    public $leftList = [];
+    public $rightList = [];
+    private $answerList = [];
 
     /**
      * Export the question part as a matrix-choice, with only one possible answer per line.
@@ -250,7 +276,7 @@ class ImsAnswerMatching extends Answer
         return $out;
     }
 
-    public function imsExportResponsesDeclaration($questionIdent)
+    public function imsExportResponsesDeclaration($questionIdent, Question $question = null)
     {
         $this->answerList = $this->getAnswersList(true);
         $out = '  <responseDeclaration identifier="'.$questionIdent.'" cardinality="single" baseType="identifier">'."\n";
@@ -290,8 +316,11 @@ class ImsAnswerMatching extends Answer
  *
  * @package chamilo.exercise
  */
-class ImsAnswerHotspot extends Answer
+class ImsAnswerHotspot extends Answer implements ImsAnswerInterface
 {
+    private $answerList = [];
+    private $gradeList = [];
+
     /**
      * TODO update this to match hot spots instead of copying matching
      * Export the question part as a matrix-choice, with only one possible answer per line.
@@ -347,7 +376,7 @@ class ImsAnswerHotspot extends Answer
         return $text;
     }
 
-    public function imsExportResponsesDeclaration($questionIdent)
+    public function imsExportResponsesDeclaration($questionIdent, Question $question = null)
     {
         $this->answerList = $this->getAnswersList(true);
         $this->gradeList = $this->getGradesList();
@@ -372,7 +401,7 @@ class ImsAnswerHotspot extends Answer
  *
  * @package chamilo.exercise
  */
-class ImsAnswerFree extends Answer
+class ImsAnswerFree extends Answer implements ImsAnswerInterface
 {
     /**
      * TODO implement
@@ -393,7 +422,7 @@ class ImsAnswerFree extends Answer
             </extendedTextInteraction>';
     }
 
-    public function imsExportResponsesDeclaration($questionIdent, $question)
+    public function imsExportResponsesDeclaration($questionIdent, Question $question = null)
     {
         $out = '  <responseDeclaration identifier="'.$questionIdent.'" cardinality="single" baseType="string">';
         $out .= '<outcomeDeclaration identifier="SCORE" cardinality="single" baseType="float">

+ 9 - 0
main/exercise/export/qti2/qti2_export.php

@@ -22,8 +22,17 @@ require __DIR__.'/qti2_classes.php';
  */
 class ImsAssessmentItem
 {
+    /**
+     * @var Ims2Question
+     */
     public $question;
+    /**
+     * @var string
+     */
     public $questionIdent;
+    /**
+     * @var ImsAnswerInterface
+     */
     public $answer;
 
     /**