Browse Source

Add question code in question edition (admin only) see BT#15230

Julio Montoya 6 years ago
parent
commit
709740fe49

+ 0 - 20
main/exercise/export/aiken/aiken_classes.php

@@ -32,26 +32,6 @@ class Aiken2Question extends Question
         return $answer;
     }
 
-    /**
-     * @param string $code
-     *
-     * @return bool
-     */
-    public function addCode($code)
-    {
-        if (api_get_configuration_value('allow_question_code') && !empty($this->id)) {
-            $code = Database::escape_string($code);
-            $table = Database::get_course_table(TABLE_QUIZ_QUESTION);
-            $sql = "UPDATE $table SET code = '$code' 
-                    WHERE iid = {$this->id} AND c_id = {$this->course['real_id']}";
-            Database::query($sql);
-
-            return true;
-        }
-
-        return false;
-    }
-
     public function createAnswersForm($form)
     {
         return true;

+ 34 - 0
main/exercise/question.class.php

@@ -1684,6 +1684,10 @@ abstract class Question
             //$form->addElement('select', 'parent_id', get_lang('AttachToMedia'), $course_medias);
         }
 
+        if (api_get_configuration_value('allow_question_code') && api_is_platform_admin()) {
+            $form->addText('code', get_lang('QuestionCode'));
+        }
+
         $form->addElement('html', '</div>');
 
         if (!isset($_GET['fromExercise'])) {
@@ -1723,6 +1727,10 @@ abstract class Question
         $defaults['questionCategory'] = $this->category;
         $defaults['feedback'] = $this->feedback;
 
+        if (api_get_configuration_value('allow_question_code') && api_is_platform_admin()) {
+            $defaults['code'] = $this->code;
+        }
+
         // Came from he question pool
         if (isset($_GET['fromExercise'])) {
             $form->setDefaults($defaults);
@@ -1755,6 +1763,10 @@ abstract class Question
         if ($this->type != MEDIA_QUESTION) {
             $this->save($exercise);
 
+            if (api_is_platform_admin()) {
+                $this->addCode($form->getSubmitValue('code'));
+            }
+
             // modify the exercise
             $exercise->addToList($this->id);
             $exercise->update_question_positions();
@@ -2422,4 +2434,26 @@ abstract class Question
 
         return false;
     }
+
+
+    /**
+     * @param string $code
+     *
+     * @return bool
+     */
+    public function addCode($code)
+    {
+        if (api_get_configuration_value('allow_question_code') && !empty($this->id)) {
+            $code = Database::escape_string($code);
+            $table = Database::get_course_table(TABLE_QUIZ_QUESTION);
+            $sql = "UPDATE $table SET code = '$code' 
+                    WHERE iid = {$this->id} AND c_id = {$this->course['real_id']}";
+            Database::query($sql);
+
+            return true;
+        }
+
+        return false;
+    }
+
 }

+ 6 - 1
main/exercise/question_admin.inc.php

@@ -35,8 +35,13 @@ if (is_object($objQuestion)) {
     $typesInformation = Question::get_question_type_list();
     $form_title_extra = isset($typesInformation[$type][1]) ? get_lang($typesInformation[$type][1]) : null;
 
+    $code = '';
+    if (isset($objQuestion->code) && !empty($objQuestion->code)) {
+        $code = ' ('.$objQuestion->code.')';
+    }
+
     // form title
-    $form->addHeader($text.': '.$form_title_extra);
+    $form->addHeader($text.': '.$form_title_extra.$code);
 
     // question form elements
     $objQuestion->createForm($form, $objExercise);