web/lib/Zend/Paginator.php
changeset 886 1e110b03ae96
parent 807 877f952ae2bd
child 1230 68c69c656a2c
--- a/web/lib/Zend/Paginator.php	Sun Apr 21 10:07:03 2013 +0200
+++ b/web/lib/Zend/Paginator.php	Sun Apr 21 21:54:24 2013 +0200
@@ -14,9 +14,9 @@
  *
  * @category   Zend
  * @package    Zend_Paginator
- * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  * @license    http://framework.zend.com/license/new-bsd     New BSD License
- * @version    $Id: Paginator.php 22865 2010-08-21 12:28:09Z ramon $
+ * @version    $Id: Paginator.php 24754 2012-05-05 02:30:56Z adamlundrigan $
  */
 
 /**
@@ -32,7 +32,7 @@
 /**
  * @category   Zend
  * @package    Zend_Paginator
- * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  * @license    http://framework.zend.com/license/new-bsd     New BSD License
  */
 class Zend_Paginator implements Countable, IteratorAggregate
@@ -524,13 +524,26 @@
     }
 
     /**
-     * Returns the total number of items available.
+     * Returns the total number of items available.  Uses cache if caching is enabled.
      *
      * @return integer
      */
     public function getTotalItemCount()
     {
-        return count($this->getAdapter());
+        if (!$this->_cacheEnabled()) {
+            return count($this->getAdapter());
+        } else {
+            $cacheId   = md5($this->_getCacheInternalId(). '_itemCount');            
+            $itemCount = self::$_cache->load($cacheId);
+
+            if ($itemCount === false) {
+                $itemCount = count($this->getAdapter());
+
+                self::$_cache->save($itemCount, $cacheId, array($this->_getCacheInternalId()));
+            }
+            
+            return $itemCount;
+        }
     }
 
     /**
@@ -1044,10 +1057,18 @@
      */
     protected function _getCacheInternalId()
     {
-        return md5(serialize(array(
-            $this->getAdapter(),
-            $this->getItemCountPerPage()
-        )));
+        $adapter = $this->getAdapter();
+        
+        if (method_exists($adapter, 'getCacheIdentifier')) {
+            return md5(serialize(array(
+                $adapter->getCacheIdentifier(), $this->getItemCountPerPage()
+            )));
+        } else {
+            return md5(serialize(array(
+                $adapter,
+                $this->getItemCountPerPage()
+            )));
+        }
     }
 
     /**
@@ -1057,7 +1078,7 @@
      */
     protected function _calculatePageCount()
     {
-        return (integer) ceil($this->getAdapter()->count() / $this->getItemCountPerPage());
+        return (integer) ceil($this->getTotalItemCount() / $this->getItemCountPerPage());
     }
 
     /**