Exemplo n.º 1
0
/**
 * Count the number of sub categories belonging to a category (recursivly).
 *
 * @param int       identifier of the category
 * @return int      number of sub categories
 */
function claro_count_all_sub_categories($id, $count = 0)
{
    // Get table name
    $tbl_mdb_names = claro_sql_get_main_tbl();
    $tbl_category = $tbl_mdb_names['category'];
    // Count number of courses for this category
    $sql = "SELECT COUNT(c.id) AS nbSubCategories\n            FROM `" . $tbl_category . "` AS c\n            WHERE c.idParent = " . (int) $id;
    $result = Claroline::getDatabase()->query($sql);
    $nbSubCategories = $result->fetch(Database_ResultSet::FETCH_VALUE);
    $count = $nbSubCategories > 0 ? $count + $nbSubCategories : $count;
    // Retrieve all subcategories
    $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_sub_categories($row['id'], $count);
    }
    return $count;
}
Exemplo n.º 2
0
 /**
  * Count the number of sub categories of the current category (recursivly).
  *
  * @return int      number of sub categories
  */
 public static function countAllSubCategories($id)
 {
     return claro_count_all_sub_categories($id);
 }