فهرست منبع

Add support for is_required field in CourseBuilder and CourseRestorer classes - refs BT#13203

Yannick Warnier 7 سال پیش
والد
کامیت
84ff49654f

+ 8 - 1
src/Chamilo/CourseBundle/Component/CourseCopy/CourseBuilder.php

@@ -945,7 +945,13 @@ class CourseBuilder
 
         $sql = 'SELECT * FROM '.$table_que.' WHERE c_id = '.$courseId.'  ';
         $db_result = Database::query($sql);
+        $is_required = 0;
         while ($obj = Database::fetch_object($db_result)) {
+            if (api_get_configuration_value('allow_required_survey_questions')) {
+                if (isset($obj->is_required)) {
+                    $is_required = $obj->is_required;
+                }
+            }
             $question = new SurveyQuestion(
                 $obj->question_id,
                 $obj->survey_id,
@@ -955,7 +961,8 @@ class CourseBuilder
                 $obj->display,
                 $obj->sort,
                 $obj->shared_question_id,
-                $obj->max_value
+                $obj->max_value,
+                $is_required
             );
             $sql = 'SELECT * FROM '.$table_opt.'
                     WHERE c_id = '.$courseId.' AND question_id = '.$obj->question_id;

+ 6 - 0
src/Chamilo/CourseBundle/Component/CourseCopy/CourseRestorer.php

@@ -2455,6 +2455,12 @@ class CourseRestorer
                 'shared_question_id' => self::DBUTF8($question->shared_question_id),
                 'max_value' => self::DBUTF8($question->max_value),
             ];
+            if (api_get_configuration_value('allow_required_survey_questions')) {
+                if (isset($question->is_required)) {
+                    $params['is_required'] = $question->is_required;
+                }
+            }
+
 
             $new_id = Database::insert($table_que, $params);
             if ($new_id) {

+ 10 - 1
src/Chamilo/CourseBundle/Component/CourseCopy/Resources/SurveyQuestion.php

@@ -45,6 +45,10 @@ class SurveyQuestion extends Resource
      */
     public $options;
 
+    /**
+     * Is this question required (0: no, 1: yes)
+     */
+    public $is_required;
     /**
      * Create a new SurveyQuestion
      * @param int $id
@@ -56,6 +60,7 @@ class SurveyQuestion extends Resource
      * @param int $sort
      * @param int $shared_question_id
      * @param int $max_value
+     * @param int $is_required
      */
     public function __construct(
         $id,
@@ -66,7 +71,8 @@ class SurveyQuestion extends Resource
         $display,
         $sort,
         $shared_question_id,
-        $max_value
+        $max_value,
+        $is_required = false
     ) {
         parent::__construct($id, RESOURCE_SURVEYQUESTION);
         $this->survey_id = $survey_id;
@@ -78,6 +84,9 @@ class SurveyQuestion extends Resource
         $this->shared_question_id = $shared_question_id;
         $this->max_value = $max_value;
         $this->answers = array();
+        if (api_get_configuration_value('allow_required_survey_questions')) {
+            $this->is_required = $is_required;
+        }
     }
 
     /**