Esempio n. 1
0
 /**
  * @param int $exercise_id
  * @param int $course_id
  * @param string $order
  * @return array
  */
 public function getCategoryExerciseTree($exercise_id, $course_id, $order = null, $shuffle = false, $excludeCategoryWithNoQuestions = true)
 {
     $table = Database::get_course_table(TABLE_QUIZ_REL_CATEGORY);
     $table_category = Database::get_course_table(TABLE_QUIZ_CATEGORY);
     $sql = "SELECT * FROM {$table} qc INNER JOIN {$table_category} c ON (category_id = c.iid)\n                WHERE exercise_id = {$exercise_id} ";
     if (!empty($order)) {
         $sql .= "ORDER BY {$order}";
     }
     $categories = array();
     $result = Database::query($sql);
     if (Database::num_rows($result)) {
         while ($row = Database::fetch_array($result, 'ASSOC')) {
             if ($excludeCategoryWithNoQuestions) {
                 if ($row['count_questions'] == 0) {
                     continue;
                 }
             }
             $categories[$row['category_id']] = $row;
         }
     }
     if ($shuffle) {
         ArrayClass::shuffle_assoc($categories);
     }
     return $categories;
 }