Exemplo n.º 1
0
 /**
  * Returns objects count in collection
  *
  * @return bool|null
  */
 public function count()
 {
     $this->select('count(*)');
     $result = null;
     $sql = $this->compile();
     $tbl = $this->getStatement('table');
     $cache_key = OrmCache::genKey($sql, $this->values_accum);
     if (($result_cached = OrmCache::getCachedQuery($cache_key)) !== false && $this->use_cache) {
         return $result_cached;
     }
     if (($result_cached = OrmCache::getFromInternalCache($cache_key)) !== false) {
         return $result_cached;
     }
     $result = Db::getCell($this->compile(), $this->values_accum);
     if ($this->use_cache) {
         OrmCache::cacheQuery($cache_key, $tbl['sql'], $result);
         return $result;
     }
     OrmCache::storeInternal($cache_key, $tbl['sql'], $result);
     return $result;
 }