<?php

class class_model extends Cf_Model
{

    /**
     *
     * @param type $username
     * @param type $classRx
     * @param type $rows
     * @param type $page
     * @return type json, plain array
     */
    function getAllClasses($username, $searchletter, $includes, $excludes, $rows = 10, $page = 1)
    {
        $this->load->model('advancedreports_model');

        try
        {
            $includes = (array) $includes;
            $excludes = (array) $excludes;

            $escapedSearchletter = $this->db->escape_str($searchletter);
            $sql = sprintf("SELECT DISTINCT contextname FROM CONTEXTS WHERE contextname ~ '%s' ORDER BY contextname ASC",$escapedSearchletter);

            $skip = ($page - 1) * $rows;
            $data = $this->advancedreports_model->runQuery($username, $sql, '', '', $skip, $rows, $includes, $excludes);
            return $data['rows'];
        }
        catch (Exception $e)
        {
            log_message(log_level_for_exception($e), $e->getMessage() . " " . $e->getFile() . " line:" . $e->getLine());
            throw $e;
        }
    }

}

?>