Prechádzať zdrojové kódy

If a category ordered setting was turned on a message will appear "AllQuestionsMustHaveACategory". Adding code in order to manage ordered categories. Adding root category in exercise_reminder.php

Julio Montoya 12 rokov pred
rodič
commit
400fd95f22

+ 5 - 0
main/exercice/admin.php

@@ -574,6 +574,11 @@ if (isset($_GET['hotspotadmin'])) {
 }
 
 if (!$newQuestion && !$modifyQuestion && !$editQuestion && !isset($_GET['hotspotadmin'])) {
+
+    if ($objExercise->randomByCat == EXERCISE_CATEGORY_RANDOM_SHUFFLED || EXERCISE_CATEGORY_RANDOM_ORDERED) {
+        Display::display_normal_message(get_lang('AllQuestionsMustHaveACategory'));
+    }
+
     // Question list (drag n drop view)
     if ($fastEdition) {
         require 'question_list_pagination_admin.inc.php';

+ 17 - 18
main/exercice/exercise.class.php

@@ -4658,7 +4658,7 @@ class Exercise
                 //Getting questions by category
                 $questions_in_category = Testcategory::getQuestionsByCat($this->id);
 
-                $isRandomByCategory = $this->selectRandomByCat();
+                //$isRandomByCategory = $this->selectRandomByCat();
 
                 // on tri les catégories en fonction du terme entre [] en tête de la description de la catégorie
                 /*
@@ -4674,9 +4674,9 @@ class Exercise
 
                 // If test option is Grouped By Categories
 
-                if ($isRandomByCategory == 2) {
+                /*if ($isRandomByCategory == 2) {
                     $questions_in_category = Testcategory::sortTabByBracketLabel($questions_in_category);
-                }
+                }*/
 
                 $number_of_random_question = $this->random;
                 if ($this->random == -1) {
@@ -4722,21 +4722,21 @@ class Exercise
      */
     function get_validated_question_list()
     {
-        //Getting current question list
+        // Getting current question list
         $question_list = $this->selectQuestionList();
 
-        //Getting random by category setting
+        // Getting random by category setting
         $random_by_category = $this->isRandomByCat();
 
         switch ($random_by_category) {
             case EXERCISE_CATEGORY_RANDOM_SHUFFLED:
-                //Randomized array
+                // Randomized array
                 if ($this->isRandom()) {
                     $question_list = $this->selectRandomList($question_list);
                 }
                 break;
             case EXERCISE_CATEGORY_RANDOM_DISABLED:
-                //Randomized array
+                // Randomized array
                 if ($this->isRandom()) {
                     $question_list = $this->selectRandomList($question_list);
                 }
@@ -4746,16 +4746,16 @@ class Exercise
                     //break;
                 }
 
+
                 /**
-                 *  Get questions by category for this exercice
+                 *  Get questions by category for this exercise
                  *  we have to choice $objExercise->random question in each array values of $questions_by_category
-                 *  key of $tabCategoryQuestions are the categopy id (0 for not in a category)
+                 *  key of $tabCategoryQuestions are the category id (0 for not in a category)
                  *  value is the array of question id of this category
                  */
 
                 //Getting questions by category
-                //$questions_by_category = Testcategory::getQuestionsByCat($this->id, $question_list);
-
+                $questions_by_category = Testcategory::getQuestionsByCat($this->id, $question_list);
 
                 /**
                  * The order is based in the category in this case [biology] is first that [maths]
@@ -4773,13 +4773,13 @@ class Exercise
                     //$questions_by_category = Testcategory::sortCategoriesQuestionByName($questions_by_category);
                 //}
 
-/*
                 $number_of_random_question = $this->random;
-                if ($this->random == -1) {
+                if ($this->random == -1 || empty($this->random)) {
                     $number_of_random_question = count($question_list);
                 }
 
                 //Only 1 question per category
+                /*
                 if (!empty($questions_by_category)) {
                     $one_question_per_category = array();
                     $questions_added = array();
@@ -4792,7 +4792,7 @@ class Exercise
                         }
                     }
                     $questions_by_category = $one_question_per_category;
-                }
+                }*/
 
                 $temp_question_list = array();
                 while (list($category_id, $question_list) = each($questions_by_category)) {
@@ -4802,9 +4802,9 @@ class Exercise
 
                 // shuffle the question list if test is not grouped by categories
                 //if ($random_by_category == EXERCISE_CATEGORY_RANDOM_SHUFFLED) {
-                    shuffle($temp_question_list);
+                    //shuffle($temp_question_list);
                 //}
-                $question_list = $temp_question_list;*/
+                $question_list = $temp_question_list;
                 break;
         }
         return $question_list;
@@ -4819,7 +4819,6 @@ class Exercise
     {
         $question_list = $this->get_validated_question_list();
         $question_list = $this->transform_question_list_with_medias($question_list, $expand_media_questions);
-
         return $question_list;
     }
 
@@ -4829,7 +4828,7 @@ class Exercise
      * @params bool expand or not question list (true show all questions, false show media question id instead of the question ids)
      *
      **/
-    function transform_question_list_with_medias($question_list, $expand_media_questions = false)
+    public function transform_question_list_with_medias($question_list, $expand_media_questions = false)
     {
         $new_question_list = array();
         if (!empty($question_list)) {

+ 18 - 2
main/exercice/exercise_reminder.php

@@ -154,7 +154,6 @@ $exercise_result = get_answered_questions_from_attempt($exe_id, $objExercise);
 $remind_list = $exercise_stat_info['questions_to_check'];
 $remind_list = explode(',', $remind_list);
 
-
 echo Display::label(get_lang('QuestionWithNoAnswer'), 'warning');
 echo '<div class="clear"></div><br />';
 
@@ -207,7 +206,24 @@ foreach ($question_list as $questionId) {
     if (!in_array($questionId, $exercise_result)) {
         $question_title = Display::label($question_title, 'warning');
     }
-    $question_title = Display::tag('label', $checkbox.$question_title, $label_attributes);
+
+    //var_dump($objQuestionTmp->category_list);
+    $rootCategories = null;
+    global $app;
+    $repo = $app['orm.em']->getRepository('Entity\CQuizCategory');
+    foreach ($objQuestionTmp->category_list as $categoryId) {
+        $cat = $repo->find($categoryId);
+        $parentCat = $repo->getPath($cat);
+        if (isset($parentCat[0])) {
+            $rootCategories .= $parentCat[0]->getTitle();
+        }
+    }
+
+    if (!empty($rootCategories)) {
+        $rootCategories = Display::label($rootCategories, 'info').' ';
+    }
+
+    $question_title = Display::tag('label', $checkbox.$rootCategories.$question_title, $label_attributes);
     $table .= Display::div($question_title, array('class' => 'exercise_reminder_item'));
 
     if (($counter % $split_by) == 0) {

+ 1 - 0
main/exercice/exercise_submit.php

@@ -521,6 +521,7 @@ if (!isset($_SESSION['questionList'])) {
 
 //Fix in order to get the correct question list
 $question_list_flatten = $objExercise->transform_question_list_with_medias($questionList, true);
+
 Session::write('question_list_flatten', $question_list_flatten);
 
 $clock_expired_time = null;

+ 3 - 4
main/exercice/testcategory.class.php

@@ -249,8 +249,10 @@ class Testcategory
     function get_category_by_title($title , $course_id = 0) {
         $table = Database::get_course_table(TABLE_QUIZ_QUESTION_CATEGORY);
         $course_id = intval($course_id);
-        $sql = "SELECT * FROM $table WHERE title = '$title' AND c_id IN ('0', '$course_id')LIMIT 1";
         $title = Database::escape_string($title);
+
+        $sql = "SELECT * FROM $table WHERE title = '$title' AND c_id IN ('0', '$course_id')LIMIT 1";
+
         $result = Database::query($sql);
         if (Database::num_rows($result)) {
             $result = Database::store_result($result, 'ASSOC');
@@ -306,9 +308,6 @@ class Testcategory
         return false;
 	}
 
-
-
-
 	/**
      * Gets the number of question of category id=in_id
      * @todo I'm removing the $in_id parameter because it seems that you're using $this->id instead of $in_id after confirmation delete this

+ 1 - 0
main/exercice/tests_category.php

@@ -304,6 +304,7 @@ function display_categories($type = 'simple') {
         //'html' => true
     );
 
+    // @todo put this in a function
     $repo = $app['orm.em']->getRepository('Entity\CQuizCategory');
 
     $query = null;