Explorar o código

Fixing Random query see BT#6261

Julio Montoya %!s(int64=11) %!d(string=hai) anos
pai
achega
54568d7804
Modificáronse 1 ficheiros con 10 adicións e 4 borrados
  1. 10 4
      main/exercice/exercise.class.php

+ 10 - 4
main/exercice/exercise.class.php

@@ -883,18 +883,24 @@ class Exercise
      */
     public function selectRandomList()
     {
+        $TBL_EXERCISE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
+        $TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION);
+
         $random = isset($this->random) && !empty($this->random) ? $this->random : 0;
 
-        $TBL_EXERCICE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
-        $TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION);
+        $randomLimit = "LIMIT $random";
+        // Random all questions so no limit
+        if ($random == -1) {
+            $randomLimit = null;
+        }
 
         // @todo improve this query
         $sql = "SELECT e.question_id
-                FROM $TBL_EXERCICE_QUESTION e INNER JOIN $TBL_QUESTIONS q
+                FROM $TBL_EXERCISE_QUESTION e INNER JOIN $TBL_QUESTIONS q
                     ON (e.question_id= q.iid)
                 WHERE e.c_id = {$this->course_id} AND e.exercice_id	= '".Database::escape_string($this->id)."'
                 ORDER BY RAND()
-                LIMIT $random ";
+                $randomLimit ";
         $result = Database::query($sql);
         $questionList = array();
         while ($row = Database::fetch_object($result)) {