Allow complex queries for kolab_storage_folder::count(); fix row counting from SQL

This commit is contained in:
Thomas Bruederli 2012-06-20 15:32:23 +02:00
parent f5824e32b4
commit 6d1f67ad92
2 changed files with 13 additions and 6 deletions

View file

@ -352,13 +352,13 @@ class kolab_storage_cache
// cache is in sync, we can count records in local DB
if ($this->synched) {
$sql_result = $this->db->query(
"SELECT COUNT(*) AS NUMROWS FROM kolab_cache ".
"SELECT COUNT(*) AS numrows FROM kolab_cache ".
"WHERE resource=? " . $this->_sql_where($query),
$this->resource_uri
);
$sql_arr = $this->db->fetch_assoc($sql_result);
$count = intval($sql_arr['NUMROWS']);
$count = intval($sql_arr['numrows']);
}
else {
// search IMAP by object type

View file

@ -272,17 +272,24 @@ class kolab_storage_folder
/**
* Get number of objects stored in this folder
*
* @param string $type Object type (e.g. contact, event, todo, journal, note, configuration)
* @param mixed Pseudo-SQL query as list of filter parameter triplets
* or string with object type (e.g. contact, event, todo, journal, note, configuration)
* @return integer The number of objects of the given type
* @see self::select()
*/
public function count($type = null)
public function count($type_or_query = null)
{
if (!$type) $type = $this->type;
if (!$type_or_query)
$query = array(array('type','=',$this->type));
else if (is_string($type_or_query))
$query = array(array('type','=',$type_or_query));
else
$query = (array)$type_or_query;
// synchronize cache first
$this->cache->synchronize();
return $this->cache->count(array(array('type','=',$type)));
return $this->cache->count($query);
}