From 6d1f67ad92c75b9ce3f20736acfe01256d7a5852 Mon Sep 17 00:00:00 2001 From: Thomas Bruederli Date: Wed, 20 Jun 2012 15:32:23 +0200 Subject: [PATCH] Allow complex queries for kolab_storage_folder::count(); fix row counting from SQL --- plugins/libkolab/lib/kolab_storage_cache.php | 4 ++-- plugins/libkolab/lib/kolab_storage_folder.php | 15 +++++++++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/plugins/libkolab/lib/kolab_storage_cache.php b/plugins/libkolab/lib/kolab_storage_cache.php index 091ddeb1..84841d0a 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 1a522be0..e4f30b7a 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); }