Browse Source

Merge branch '1.11.x' of github.com:chamilo/chamilo-lms into 1.11.x

Angel Fernando Quiroz Campos 6 years ago
parent
commit
63c19a5f50

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

@@ -32,6 +32,26 @@ 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;

+ 8 - 4
main/exercise/export/aiken/aiken_import.inc.php

@@ -191,9 +191,15 @@ function aiken_import_exercise($file)
             if (isset($question_array['description'])) {
                 $question->updateDescription($question_array['description']);
             }
+
             $type = $question->selectType();
             $question->type = constant($type);
             $question->save($exercise);
+
+            if (isset($question_array['code'])) {
+                $question->addCode($question_array['code']);
+            }
+
             $last_question_id = $question->selectId();
             //3. Create answer
             $answer = new Answer($last_question_id);
@@ -297,11 +303,9 @@ function aiken_parse_file(&$exercise_info, $exercisePath, $file, $questionFile)
             //weight for correct answer
             $exercise_info['question'][$question_index]['weighting'][$correct_answer_index] = 1;
         } elseif (preg_match('/^SCORE:\s?(.*)/', $info, $matches)) {
-            //the correct answers
-            $correct_answer_index = array_search($matches[1], $answers_array);
             $exercise_info['question'][$question_index]['score'] = (float) $matches[1];
-            //weight for correct answer
-            //$exercise_info['question'][$question_index]['weighting'][$correct_answer_index] = 1;
+        } elseif (preg_match('/^CODE:\s?(.*)/', $info, $matches)) {
+            $exercise_info['question'][$question_index]['code'] = $matches[1];
         } elseif (preg_match('/^ANSWER_EXPLANATION:\s?(.*)/', $info, $matches)) {
             //Comment of correct answer
             $correct_answer_index = array_search($matches[1], $answers_array);

+ 1 - 1
main/inc/lib/glossary.lib.php

@@ -419,7 +419,7 @@ class GlossaryManager
                 Display::return_icon('view_text.png', get_lang('TableView'), '', ICON_SIZE_MEDIUM).'</a>';
         }
 
-        if (!api_is_anonymous()) {
+        if (api_is_allowed_to_edit(true, true, true)) {
             $actionsLeft .= Display::url(
                 Display::return_icon('export_to_documents.png', get_lang('ExportToDocArea'), [], ICON_SIZE_MEDIUM),
                 api_get_self().'?'.api_get_cidreq().'&'.http_build_query(['action' => 'export_documents'])

+ 4 - 0
main/install/configuration.dist.php

@@ -1067,6 +1067,10 @@ VALUES (2, 13, 'session_courses_read_only_mode', 'Lock Course In Session', 1, 1,
 // Hide social media links
 //$_configuration['hide_social_media_links'] = false;
 
+// Allow code field in exercise questions
+//ALTER TABLE c_quiz_question ADD COLUMN code VARCHAR(255) NULL DEFAULT NULL;
+// $_configuration['allow_question_code'] = false;
+
 // ------ Custom DB changes (keep this at the end)
 // Add user activation by confirmation email
 // This option prevents the new user to login in the platform if your account is not confirmed via email