Example #1
0
 /**
  * Count records according to given criteria
  *
  * @param Array $options Options
  * @return Int
  */
 public function count(array $options = null)
 {
     if ($this->_model instanceof Garp_Model_Db) {
         unset($options['sort']);
         $options['fields'] = 'COUNT(*)';
         try {
             $result = $this->fetch($options);
             return !empty($result[0]['COUNT(*)']) ? $result[0]['COUNT(*)'] : 0;
         } catch (Zend_Db_Statement_Exception $e) {
             /**
              * @todo When fetching results
              * filtered using a HABTM relationship, extra
              * meta field are returned from the binding table.
              * This results in an SQL error; when using COUNT()
              * and returning results from multiple tables a
              * GROUP BY clause is mandatory. This must be fixed in
              * the future.
              */
             return 1000;
         }
     } else {
         return $this->_model->count();
     }
 }