Ejemplo n.º 1
0
 /**
  * Returns the number of elements in the collection.
  *
  * @link http://php.net/manual/en/class.countable.php
  *
  * @return int
  */
 public function count()
 {
     if ($this->data === null && $this->sql instanceof Sql && is_array($this->sql->groupBy) && count($this->sql->groupBy) === 0) {
         $sql = $this->sql->select('COUNT(*)')->limit(false)->offset(false);
         $count = intval(Connection::instance($this->dbLink)->fetchValue($sql));
         if ($this->sql->offset) {
             $count -= $this->sql->offset;
             if ($count < 0) {
                 return 0;
             }
         }
         if ($this->sql->limit !== false && $count > $this->sql->limit) {
             $count = $this->sql->limit;
         }
         return $count;
     }
     $this->dataToArray();
     return count($this->data);
 }