/** * Counts the number of courses in a given course category * @param string $categoryCode Category code * @param $searchTerm * @return int Count of courses */ public function count_courses_in_category($categoryCode, $searchTerm = '') { return countCoursesInCategory($categoryCode, $searchTerm); }
/** * @return array */ function browseCourseCategories() { $tbl_category = Database::get_main_table(TABLE_MAIN_CATEGORY); $conditions = null; $whereCondition = null; if (isMultipleUrlSupport()) { $table = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE_CATEGORY); $conditions = " INNER JOIN {$table} a ON (c.id = a.course_category_id)"; $whereCondition = " WHERE a.access_url_id = " . api_get_current_access_url_id(); } $sql = "SELECT c.* FROM {$tbl_category} c\n {$conditions}\n {$whereCondition}\n ORDER BY tree_pos ASC"; $result = Database::query($sql); $url_access_id = 1; if (api_is_multiple_url_enabled()) { $url_access_id = api_get_current_access_url_id(); } $countCourses = CourseManager::countAvailableCourses($url_access_id); $categories = array(); $categories[0][0] = array('id' => 0, 'name' => get_lang('DisplayAll'), 'code' => 'ALL', 'parent_id' => null, 'tree_pos' => 0, 'count_courses' => $countCourses); while ($row = Database::fetch_array($result)) { $count_courses = countCoursesInCategory($row['code']); $row['count_courses'] = $count_courses; if (!isset($row['parent_id'])) { $categories[0][$row['tree_pos']] = $row; } else { $categories[$row['parent_id']][$row['tree_pos']] = $row; } } $count_courses = countCoursesInCategory(); $categories[0][count($categories[0]) + 1] = array('id' => 0, 'name' => get_lang('None'), 'code' => 'NONE', 'parent_id' => null, 'tree_pos' => $row['tree_pos'] + 1, 'children_count' => 0, 'auth_course_child' => true, 'auth_cat_child' => true, 'count_courses' => $count_courses); return $categories; }