/** * Calculates the number of records in a listing as created by cmclass_get_listing * * @param string $namesearch Search string for course name * @param string $alpha Start initial of course name filter * @param int $id Corresponding courseid, or zero for any * @param boolean $onlyopen If true, only consider classes whose end date has not been passed * @param cm_context_set $contexts Contexts to provide permissions filtering, of null if none * @param int $clusterid Id of a cluster that the class must be assigned to via a track * @return int The number of records */ function cmclass_count_records($namesearch = '', $alpha = '', $id = 0, $onlyopen = false, $contexts = null, $clusterid = 0) { global $CURMAN; $select = 'SELECT COUNT(cls.id) '; $tables = 'FROM ' . $CURMAN->db->prefix_table(CLSTABLE) . ' cls '; $join = 'LEFT JOIN ' . $CURMAN->db->prefix_table(CRSTABLE) . ' crs ' . 'ON crs.id = cls.courseid '; //class associated to a particular cluster via a track if (!empty($clusterid)) { $join .= "JOIN {$CURMAN->db->prefix_table(CLSTRACKCLS)} clstrk\n ON clstrk.classid = cls.id\n JOIN {$CURMAN->db->prefix_table(CLSTTRKTABLE)} clsttrk\n ON clsttrk.trackid = clstrk.trackid\n AND clsttrk.clusterid = {$clusterid} "; } $where = array(); $LIKE = $CURMAN->db->sql_compare(); if (!empty($namesearch)) { $where[] = "((crs.name {$LIKE} '%{$namesearch}%') OR (cls.idnumber {$LIKE} '%{$namesearch}%'))"; } if ($alpha) { $where[] = "(crs.name {$LIKE} '{$alpha}%')"; } if ($id) { $where[] = "(crs.id = {$id})"; } if ($onlyopen) { $curtime = time(); $where[] = "(cls.enddate > {$curtime} OR NOT cls.enddate)"; } if ($contexts !== null) { $where[] = $contexts->sql_filter_for_context_level('cls.id', 'class'); } if (!empty($where)) { $where = 'WHERE ' . implode(' AND ', $where) . ' '; } else { $where = ''; } $sql = $select . $tables . $join . $where; return $CURMAN->db->count_records_sql($sql); }
/** * Calculates the number of records in a listing as created by track_get_listing * * @param string $namesearch Search string for curriculum name * @param string $alpha Start initial of curriculum name filter * @param int $curriculumid Necessary associated curriculum * @param int $clusterid Necessary associated cluster * @param cm_context_set $contexts Contexts to provide permissions filtering, of null if none * @return int The number of records */ function track_count_records($namesearch = '', $alpha = '', $curriculumid = 0, $parentclusterid = 0, $contexts = null) { global $CURMAN; $LIKE = $CURMAN->db->sql_compare(); $where = array('defaulttrack = 0'); if (!empty($namesearch)) { $where[] = "name {$LIKE} '%{$namesearch}%'"; } if ($alpha) { $where[] = "(name {$LIKE} '{$alpha}%')"; } if ($curriculumid) { $where[] = "(curid = {$curriculumid})"; } if ($parentclusterid) { $where[] = "(id IN (SELECT trackid FROM {$CURMAN->db->prefix_table(CLSTTRKTABLE)}\n WHERE clusterid = {$parentclusterid}))"; } if ($contexts !== null) { $where[] = $contexts->sql_filter_for_context_level('id', 'track'); } $where = implode(' AND ', $where); return $CURMAN->db->count_records_select(TRACKTABLE, $where); }