/** * Count the number of courses belonging to the category and all its * subcategories (recursivly). * The count does NOT include root courses. * * @param int identifier of the category * @param int count, starting value of counting (default: 0) * @return int number of courses */ function claro_count_all_courses($id, $count = 0) { // Get table name $tbl_mdb_names = claro_sql_get_main_tbl(); $tbl_category = $tbl_mdb_names['category']; $tbl_rel_course_category = $tbl_mdb_names['rel_course_category']; // Count number of courses for this category $sql = "SELECT COUNT(rcc.courseId) AS nbCourses\n FROM `" . $tbl_rel_course_category . "` AS rcc\n WHERE rcc.categoryId = " . (int) $id . "\n AND rootCourse != 1"; $result = Claroline::getDatabase()->query($sql); $nbCourses = $result->fetch(Database_ResultSet::FETCH_VALUE); $count = $nbCourses > 0 ? $count + $nbCourses : $count; // Retrieve all children of this category $sql = "SELECT id\n FROM `" . $tbl_category . "`\n WHERE idParent = " . (int) $id; $result = Claroline::getDatabase()->query($sql); // Get each child foreach ($result as $row) { $count = +claro_count_all_courses($row['id'], $count); } return $count; }
/** * Count the number of courses for the specified category * and all its sub categories (recursivly). * The count does NOT include root courses. * * @return int number of courses */ public static function countAllCourses($id) { return claro_count_all_courses($id); }