00001 <?php 00002 /** 00003 * Magento 00004 * 00005 * NOTICE OF LICENSE 00006 * 00007 * This source file is subject to the Open Software License (OSL 3.0) 00008 * that is bundled with this package in the file LICENSE.txt. 00009 * It is also available through the world-wide-web at this URL: 00010 * http://opensource.org/licenses/osl-3.0.php 00011 * If you did not receive a copy of the license and are unable to 00012 * obtain it through the world-wide-web, please send an email 00013 * to license@magentocommerce.com so we can send you a copy immediately. 00014 * 00015 * DISCLAIMER 00016 * 00017 * Do not edit or add to this file if you wish to upgrade Magento to newer 00018 * versions in the future. If you wish to customize Magento for your 00019 * needs please refer to http://www.magentocommerce.com for more information. 00020 * 00021 * @category Mage 00022 * @package Mage_Page 00023 * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com) 00024 * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) 00025 */ 00026 00027 /** 00028 * Html page block 00029 * 00030 * @category Mage 00031 * @package Mage_Page 00032 * @author Magento Core Team <core@magentocommerce.com> 00033 * 00034 * @todo separate order, mode and pager 00035 */ 00036 class Mage_Catalog_Block_Seo_Sitemap_Tree_Pager extends Mage_Page_Block_Html_Pager 00037 { 00038 protected $_showPerPage = false; 00039 protected $lastPageNumber = 1; 00040 protected $_totalNum = 0; 00041 protected $_firstNum = 0; 00042 protected $_lastNum = 1; 00043 00044 public function getCurrentPage($displacement = 0) 00045 { 00046 if ($page = (int) $this->getRequest()->getParam($this->getPageVarName()) + $displacement) { 00047 if ($page > $this->getLastPageNum()) { 00048 return $this->getLastPageNum(); 00049 } 00050 return $page; 00051 } 00052 return 1; 00053 } 00054 00055 public function getLimit() 00056 { 00057 $limits = $this->getAvailableLimit(); 00058 // if ($limit = $this->getRequest()->getParam($this->getLimitVarName())) { 00059 // if (isset($limits[$limit])) { 00060 // return $limit; 00061 // } 00062 // } 00063 $limits = array_keys($limits); 00064 return $limits[0]; 00065 } 00066 00067 public function setCollection($collection) 00068 { 00069 $this->_collection = $collection; 00070 // ->setCurPage($this->getCurrentPage()); 00071 // If not int - then not limit 00072 // if ((int) $this->getLimit()) { 00073 // $this->_collection->setPageSize($this->getLimit()); 00074 // } 00075 00076 return $this; 00077 } 00078 00079 /** 00080 * @return Mage_Core_Model_Mysql4_Collection_Abstract 00081 */ 00082 public function getCollection() 00083 { 00084 return $this->_collection; 00085 } 00086 00087 public function getFirstNum() 00088 { 00089 return $this->_firstNum + 1; 00090 } 00091 00092 public function setFirstNum($firstNum) 00093 { 00094 $this->_firstNum = $firstNum; 00095 return $this; 00096 } 00097 00098 public function getLastNum() 00099 { 00100 return $this->_lastNum; 00101 } 00102 00103 public function setLastNum($lastNum) 00104 { 00105 $this->_lastNum = $lastNum; 00106 return $this; 00107 } 00108 00109 public function getTotalNum() 00110 { 00111 return $this->_totalNum; 00112 } 00113 00114 public function setTotalNum($totalNum) 00115 { 00116 $this->_totalNum = $totalNum; 00117 return $this; 00118 } 00119 00120 public function isFirstPage() 00121 { 00122 return $this->getCurrentPage() == 1; 00123 } 00124 00125 public function getLastPageNum() 00126 { 00127 return $this->_lastPageNumber; 00128 } 00129 00130 public function setLastPageNum($lastPageNum) 00131 { 00132 $this->_lastPageNumber = $lastPageNum; 00133 return $this; 00134 } 00135 00136 public function isLastPage() 00137 { 00138 return $this->getCurrentPage() >= $this->getLastPageNum(); 00139 } 00140 00141 public function getPages() 00142 { 00143 $pages = array(); 00144 if ($this->getLastPageNum() <= $this->_displayPages) { 00145 $pages = range(1, $this->getLastPageNum()); 00146 } else { 00147 $half = ceil($this->_displayPages / 2); 00148 if ($this->getCurrentPage() >= $half && $this->getCurrentPage() <= $this->getLastPageNum() - $half) { 00149 $start = ($this->getCurrentPage() - $half) + 1; 00150 $finish = ($start + $this->_displayPages) - 1; 00151 } elseif ($this->getCurrentPage() < $half) { 00152 $start = 1; 00153 $finish = $this->_displayPages; 00154 } elseif ($this->getCurrentPage() > ($this->getLastPageNum() - $half)) { 00155 $finish = $this->getLastPageNum(); 00156 $start = $finish - $this->_displayPages + 1; 00157 } 00158 $pages = range($start, $finish); 00159 } 00160 00161 return $pages; 00162 } 00163 00164 public function getPreviousPageUrl() 00165 { 00166 return $this->getPageUrl($this->getCurrentPage(-1)); 00167 } 00168 00169 public function getNextPageUrl() 00170 { 00171 return $this->getPageUrl($this->getCurrentPage(+1)); 00172 } 00173 00174 public function getLastPageUrl() 00175 { 00176 return $this->getPageUrl($this->getLastPageNum()); 00177 } 00178 00179 } 00180