web/lib/Zend/Paginator.php
changeset 807 877f952ae2bd
parent 207 621fa6caec0c
child 1230 68c69c656a2c
equal deleted inserted replaced
805:5e7a0fedabdf 807:877f952ae2bd
    12  * obtain it through the world-wide-web, please send an email
    12  * obtain it through the world-wide-web, please send an email
    13  * to license@zend.com so we can send you a copy immediately.
    13  * to license@zend.com so we can send you a copy immediately.
    14  *
    14  *
    15  * @category   Zend
    15  * @category   Zend
    16  * @package    Zend_Paginator
    16  * @package    Zend_Paginator
    17  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
    17  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
    18  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    18  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    19  * @version    $Id: Paginator.php 22865 2010-08-21 12:28:09Z ramon $
    19  * @version    $Id: Paginator.php 24754 2012-05-05 02:30:56Z adamlundrigan $
    20  */
    20  */
    21 
    21 
    22 /**
    22 /**
    23  * @see Zend_Loader_PluginLoader
    23  * @see Zend_Loader_PluginLoader
    24  */
    24  */
    30 require_once 'Zend/Json.php';
    30 require_once 'Zend/Json.php';
    31 
    31 
    32 /**
    32 /**
    33  * @category   Zend
    33  * @category   Zend
    34  * @package    Zend_Paginator
    34  * @package    Zend_Paginator
    35  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
    35  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
    36  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    36  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    37  */
    37  */
    38 class Zend_Paginator implements Countable, IteratorAggregate
    38 class Zend_Paginator implements Countable, IteratorAggregate
    39 {
    39 {
    40     /**
    40     /**
   522 
   522 
   523         return $this->_pageCount;
   523         return $this->_pageCount;
   524     }
   524     }
   525 
   525 
   526     /**
   526     /**
   527      * Returns the total number of items available.
   527      * Returns the total number of items available.  Uses cache if caching is enabled.
   528      *
   528      *
   529      * @return integer
   529      * @return integer
   530      */
   530      */
   531     public function getTotalItemCount()
   531     public function getTotalItemCount()
   532     {
   532     {
   533         return count($this->getAdapter());
   533         if (!$this->_cacheEnabled()) {
       
   534             return count($this->getAdapter());
       
   535         } else {
       
   536             $cacheId   = md5($this->_getCacheInternalId(). '_itemCount');            
       
   537             $itemCount = self::$_cache->load($cacheId);
       
   538 
       
   539             if ($itemCount === false) {
       
   540                 $itemCount = count($this->getAdapter());
       
   541 
       
   542                 self::$_cache->save($itemCount, $cacheId, array($this->_getCacheInternalId()));
       
   543             }
       
   544             
       
   545             return $itemCount;
       
   546         }
   534     }
   547     }
   535 
   548 
   536     /**
   549     /**
   537      * Clear the page item cache.
   550      * Clear the page item cache.
   538      *
   551      *
  1042      *
  1055      *
  1043      * @return string
  1056      * @return string
  1044      */
  1057      */
  1045     protected function _getCacheInternalId()
  1058     protected function _getCacheInternalId()
  1046     {
  1059     {
  1047         return md5(serialize(array(
  1060         $adapter = $this->getAdapter();
  1048             $this->getAdapter(),
  1061         
  1049             $this->getItemCountPerPage()
  1062         if (method_exists($adapter, 'getCacheIdentifier')) {
  1050         )));
  1063             return md5(serialize(array(
       
  1064                 $adapter->getCacheIdentifier(), $this->getItemCountPerPage()
       
  1065             )));
       
  1066         } else {
       
  1067             return md5(serialize(array(
       
  1068                 $adapter,
       
  1069                 $this->getItemCountPerPage()
       
  1070             )));
       
  1071         }
  1051     }
  1072     }
  1052 
  1073 
  1053     /**
  1074     /**
  1054      * Calculates the page count.
  1075      * Calculates the page count.
  1055      *
  1076      *
  1056      * @return integer
  1077      * @return integer
  1057      */
  1078      */
  1058     protected function _calculatePageCount()
  1079     protected function _calculatePageCount()
  1059     {
  1080     {
  1060         return (integer) ceil($this->getAdapter()->count() / $this->getItemCountPerPage());
  1081         return (integer) ceil($this->getTotalItemCount() / $this->getItemCountPerPage());
  1061     }
  1082     }
  1062 
  1083 
  1063     /**
  1084     /**
  1064      * Creates the page collection.
  1085      * Creates the page collection.
  1065      *
  1086      *