implemented users count function in user backend
authorLars Kneschke <l.kneschke@metaways.de>
Mon, 29 Dec 2014 07:34:27 +0000 (08:34 +0100)
committerPhilipp Schüle <p.schuele@metaways.de>
Mon, 29 Dec 2014 09:03:10 +0000 (10:03 +0100)
Change-Id: I5a50a45c5daefcaf71b0475a437403054e53be97
Reviewed-on: http://gerrit.tine20.com/customers/1486
Tested-by: Jenkins CI (http://ci.tine20.com/)
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
tine20/Admin/Controller/User.php
tine20/Tinebase/User/Sql.php

index 739ee68..e4715e4 100644 (file)
@@ -100,8 +100,7 @@ class Admin_Controller_User extends Tinebase_Controller_Abstract
     {
         $this->checkRight('VIEW_ACCOUNTS');
         
-        $users = $this->_userBackend->getUsers($_filter, NULL, 'ASC', NULL, NULL, 'Tinebase_Model_FullUser');
-        $result = count($users);
+        $result = $this->_userBackend->getUsersCount($_filter);
         
         return $result;
     }
index e743d85..79f7a16 100644 (file)
@@ -132,20 +132,20 @@ class Tinebase_User_Sql extends Tinebase_User_Abstract
         if ($_sort !== NULL && isset($this->rowNameMapping[$_sort])) {
             $select->order($this->_db->table_prefix . $this->_tableName . '.' . $this->rowNameMapping[$_sort] . ' ' . $_dir);
         }
-
+        
         if (!empty($_filter)) {
             $whereStatement = array();
-            $defaultValues = array(
+            $defaultValues  = array(
                 $this->rowNameMapping['accountLastName'], 
                 $this->rowNameMapping['accountFirstName'], 
                 $this->rowNameMapping['accountLoginName']
             );
+            
             // prepare for case insensitive search
-            $db = Tinebase_Core::getDb();
             foreach ($defaultValues as $defaultValue) {
-                $whereStatement[] = Tinebase_Backend_Sql_Command::factory($db)->prepareForILike($this->_db->quoteIdentifier($defaultValue)) . ' LIKE ' . Tinebase_Backend_Sql_Command::factory($db)->prepareForILike('?');
+                $whereStatement[] = $this->_dbCommand->prepareForILike($this->_db->quoteIdentifier($defaultValue)) . ' LIKE ' . $this->_dbCommand->prepareForILike('?');
             }
-        
+            
             $select->where('(' . implode(' OR ', $whereStatement) . ')', '%' . $_filter . '%');
         }
         
@@ -154,16 +154,48 @@ class Tinebase_User_Sql extends Tinebase_User_Abstract
         if ($_accountClass == 'Tinebase_Model_User') {
             $select->where($this->_db->quoteInto($this->_db->quoteIdentifier('status') . ' = ?', 'enabled'));
         }
-
+        
         $stmt = $select->query();
-
         $rows = $stmt->fetchAll(Zend_Db::FETCH_ASSOC);
-
+        
         $result = new Tinebase_Record_RecordSet($_accountClass, $rows, TRUE);
         
         return $result;
     }
+    
+    /**
+     * get total count of users
+     *
+     * @param string $_filter
+     * @return int
+     */
+    public function getUsersCount($_filter = null)
+    {
+        $select = $this->_db->select()
+            ->from(SQL_TABLE_PREFIX . 'accounts', array('count' => 'COUNT(' . $this->_db->quoteIdentifier('id') . ')'));
         
+        if (!empty($_filter)) {
+            $whereStatement = array();
+            $defaultValues  = array(
+                $this->rowNameMapping['accountLastName'], 
+                $this->rowNameMapping['accountFirstName'], 
+                $this->rowNameMapping['accountLoginName']
+            );
+            
+            // prepare for case insensitive search
+            foreach ($defaultValues as $defaultValue) {
+                $whereStatement[] = $this->_dbCommand->prepareForILike($this->_db->quoteIdentifier($defaultValue)) . ' LIKE ' . $this->_dbCommand->prepareForILike('?');
+            }
+            
+            $select->where('(' . implode(' OR ', $whereStatement) . ')', '%' . $_filter . '%');
+        }
+        
+        $stmt = $select->query();
+        $rows = $stmt->fetchAll(Zend_Db::FETCH_COLUMN);
+        
+        return $rows[0];
+    }
+    
     /**
      * get user by property
      *