plugins/libkolab
Thomas Brüderli
bruederli at kolabsys.com
Wed Jun 20 15:32:50 CEST 2012
plugins/libkolab/lib/kolab_storage_cache.php | 4 ++--
plugins/libkolab/lib/kolab_storage_folder.php | 15 +++++++++++----
2 files changed, 13 insertions(+), 6 deletions(-)
New commits:
commit 6d1f67ad92c75b9ce3f20736acfe01256d7a5852
Author: Thomas Bruederli <bruederli at kolabsys.com>
Date: Wed Jun 20 15:32:23 2012 +0200
Allow complex queries for kolab_storage_folder::count(); fix row counting from SQL
diff --git a/plugins/libkolab/lib/kolab_storage_cache.php b/plugins/libkolab/lib/kolab_storage_cache.php
index 091ddeb..84841d0 100644
--- a/plugins/libkolab/lib/kolab_storage_cache.php
+++ b/plugins/libkolab/lib/kolab_storage_cache.php
@@ -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
diff --git a/plugins/libkolab/lib/kolab_storage_folder.php b/plugins/libkolab/lib/kolab_storage_folder.php
index 1a522be..e4f30b7 100644
--- a/plugins/libkolab/lib/kolab_storage_folder.php
+++ b/plugins/libkolab/lib/kolab_storage_folder.php
@@ -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);
}
More information about the commits
mailing list