Browse Source

no-session-on-cli: Let questions be instanciated with a passed course id.

Marco Villegas 11 years ago
parent
commit
3516865f7a

+ 3 - 3
main/exercice/exercise.class.php

@@ -5323,12 +5323,12 @@ class Exercise
      *  </code>
      * @return array
      */
-    private function setMediaList($questionList)
+    private function setMediaList($questionList, $course_id)
     {
         $mediaList= array();
         if (!empty($questionList)) {
             foreach ($questionList as $questionId) {
-                $objQuestionTmp = Question::read($questionId);
+                $objQuestionTmp = Question::read($questionId, $course_id);
 
                 // If a media question exists
                 if (isset($objQuestionTmp->parent_id) && $objQuestionTmp->parent_id != 0) {
@@ -5495,7 +5495,7 @@ class Exercise
             }
         }
 
-        $this->setMediaList($questionList);
+        $this->setMediaList($questionList, $this->course_id);
 
         $this->questionList = $this->transformQuestionListWithMedias($questionList, false);
         $this->questionListUncompressed = $this->transformQuestionListWithMedias($questionList, true);

+ 2 - 2
main/exercice/fill_blanks.class.php

@@ -30,9 +30,9 @@ class FillBlanks extends Question
     /**
      * Constructor
      */
-    public function FillBlanks()
+    public function FillBlanks($course_code = null)
     {
-        parent::question();
+        parent::question($course_code);
         $this->type      = FILL_IN_BLANKS;
         $this->isContent = $this->getIsContent();
     }

+ 2 - 2
main/exercice/freeanswer.class.php

@@ -24,9 +24,9 @@ class FreeAnswer extends Question
     /**
      * Constructor
      */
-    public function __construct()
+    public function __construct($course_code =  null)
     {
-        parent::question();
+        parent::question($course_code);
         $this->type      = FREE_ANSWER;
         $this->isContent = $this->getIsContent();
     }

+ 2 - 2
main/exercice/global_multiple_answer.class.php

@@ -10,9 +10,9 @@ class GlobalMultipleAnswer extends Question
     /**
      *
      */
-    public function GlobalMultipleAnswer()
+    public function GlobalMultipleAnswer($course_code = null)
     {
-        parent::question();
+        parent::question($course_code);
         $this->type      = GLOBAL_MULTIPLE_ANSWER;
         $this->isContent = $this->getIsContent();
     }

+ 2 - 2
main/exercice/hotspot.class.php

@@ -24,8 +24,8 @@ class HotSpot extends Question {
 	static $typePicture = 'hotspot.gif';
 	static $explanationLangVar = 'HotSpot';
 
-	function HotSpot() {
-		parent::question();
+	function HotSpot($course_code = null) {
+		parent::question($course_code);
 		$this -> type = HOT_SPOT;
 	}
 

+ 2 - 2
main/exercice/matching.class.php

@@ -25,9 +25,9 @@ class Matching extends Question
     /**
      * Constructor
      */
-    function Matching()
+    function Matching($course_code = null)
     {
-        parent::question();
+        parent::question($course_code);
         $this->type      = MATCHING;
         $this->isContent = $this->getIsContent();
     }

+ 2 - 2
main/exercice/media_question.class.php

@@ -6,9 +6,9 @@ class MediaQuestion extends Question
 	static $typePicture = 'media-question.png';
 	static $explanationLangVar = 'MediaQuestion';
 
-    public function __construct()
+    public function __construct($course_code = null)
     {
-        parent::question();
+        parent::question($course_code);
 		$this->type = MEDIA_QUESTION;
     }
 

+ 2 - 2
main/exercice/multiple_answer.class.php

@@ -26,9 +26,9 @@ class MultipleAnswer extends Question
     /**
      * Constructor
      */
-    public function MultipleAnswer()
+    public function MultipleAnswer($course_code = null)
     {
-        parent::question();
+        parent::question($course_code);
         $this->type      = MULTIPLE_ANSWER;
         $this->isContent = $this->getIsContent();
     }

+ 2 - 2
main/exercice/multiple_answer_combination.class.php

@@ -25,9 +25,9 @@ class MultipleAnswerCombination extends Question
     /**
      * Constructor
      */
-    public function MultipleAnswerCombination()
+    public function MultipleAnswerCombination($course_code = null)
     {
-        parent::question();
+        parent::question($course_code);
         $this->type      = MULTIPLE_ANSWER_COMBINATION;
         $this->isContent = $this->getIsContent();
     }

+ 2 - 2
main/exercice/multiple_answer_true_false.class.php

@@ -25,9 +25,9 @@ class MultipleAnswerTrueFalse extends Question
     /**
      * Constructor
      */
-    public function MultipleAnswerTrueFalse()
+    public function MultipleAnswerTrueFalse($course_code = null)
     {
-        parent::question();
+        parent::question($course_code);
         $this->type      = MULTIPLE_ANSWER_TRUE_FALSE;
         $this->isContent = $this->getIsContent();
         $this->options   = array(1 => get_lang('True'), 2 => get_lang('False'), 3 => get_lang('DoubtScore'));

+ 2 - 2
main/exercice/oral_expression.class.php

@@ -23,8 +23,8 @@ class OralExpression extends Question
 	/**
 	 * Constructor
 	 */
-	function OralExpression(){
-		parent::question();
+	function OralExpression($course_code = null){
+		parent::question($course_code);
 		$this -> type = ORAL_EXPRESSION;
 		$this -> isContent = $this-> getIsContent();
 	}

+ 5 - 5
main/exercice/question.class.php

@@ -73,7 +73,7 @@ abstract class Question
      *
      * @author - Olivier Brouckaert
      */
-    public function Question()
+    public function Question($course_code = null)
     {
         $this->id            = 0;
         $this->question      = '';
@@ -86,7 +86,7 @@ abstract class Question
         //with an special hotspot: final_overlap, final_missing, final_excess
         $this->extra         = '';
         $this->exerciseList  = array();
-        $this->course        = api_get_course_info();
+        $this->course        = api_get_course_info($course_code);
         $this->category_list = array();
         $this->parent_id     = 0;
         $this->editionMode   = 'normal';
@@ -165,7 +165,7 @@ abstract class Question
         // if the question has been found
         if ($object = Database::fetch_object($result)) {
 
-            $objQuestion = Question::getInstance($object->type);
+            $objQuestion = Question::getInstance($object->type, null, $course_info['code']);
             if (!empty($objQuestion)) {
 
                 $objQuestion->id            = $id;
@@ -1329,14 +1329,14 @@ abstract class Question
      * @param \Exercise
      * @return \Question an instance of a Question subclass (or of Questionc class by default)
      */
-    public static function getInstance($type, Exercise $exercise = null)
+    public static function getInstance($type, Exercise $exercise = null, $course_code = null)
     {
         if (!is_null($type)) {
             list($file_name, $class_name) = self::get_question_type($type);
             if (!empty($file_name)) {
                 include_once $file_name;
                 if (class_exists($class_name)) {
-                    $obj = new $class_name();
+                    $obj = new $class_name($course_code);
                     $obj->exercise = $exercise;
                     return $obj;
                 } else {

+ 2 - 2
main/exercice/unique_answer.class.php

@@ -29,10 +29,10 @@ class UniqueAnswer extends Question
     /**
      * Constructor
      */
-    public function UniqueAnswer()
+    public function UniqueAnswer($course_code = null)
     {
         //this is highly important
-        parent::question();
+        parent::question($course_code);
         $this->type      = UNIQUE_ANSWER;
         $this->isContent = $this->getIsContent();
     }

+ 2 - 2
main/exercice/unique_answer_no_option.class.php

@@ -30,9 +30,9 @@ class UniqueAnswerNoOption extends Question
 	/**
 	 * Constructor
 	 */
-	function UniqueAnswerNoOption(){
+	function UniqueAnswerNoOption($course_code = null){
 		//this is highly important
-		parent::question();
+		parent::question($course_code);
 		$this -> type = UNIQUE_ANSWER_NO_OPTION;
 		$this -> isContent = $this-> getIsContent();
 	}