1: <?php
2: /**
3: * Magento
4: *
5: * NOTICE OF LICENSE
6: *
7: * This source file is subject to the Open Software License (OSL 3.0)
8: * that is bundled with this package in the file LICENSE.txt.
9: * It is also available through the world-wide-web at this URL:
10: * http://opensource.org/licenses/osl-3.0.php
11: * If you did not receive a copy of the license and are unable to
12: * obtain it through the world-wide-web, please send an email
13: * to license@magentocommerce.com so we can send you a copy immediately.
14: *
15: * DISCLAIMER
16: *
17: * Do not edit or add to this file if you wish to upgrade Magento to newer
18: * versions in the future. If you wish to customize Magento for your
19: * needs please refer to http://www.magentocommerce.com for more information.
20: *
21: * @category Mage
22: * @package Mage_Catalog
23: * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24: * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25: */
26:
27: /**
28: * Html page block
29: *
30: * @category Mage
31: * @package Mage_Page
32: * @author Magento Core Team <core@magentocommerce.com>
33: *
34: * @todo separate order, mode and pager
35: */
36: class Mage_Catalog_Block_Seo_Sitemap_Tree_Pager extends Mage_Page_Block_Html_Pager
37: {
38: protected $_showPerPage = false;
39: protected $lastPageNumber = 1;
40: protected $_totalNum = 0;
41: protected $_firstNum = 0;
42: protected $_lastNum = 1;
43:
44: public function getCurrentPage($displacement = 0)
45: {
46: if ($page = (int) $this->getRequest()->getParam($this->getPageVarName()) + $displacement) {
47: if ($page > $this->getLastPageNum()) {
48: return $this->getLastPageNum();
49: }
50: return $page;
51: }
52: return 1;
53: }
54:
55: public function getLimit()
56: {
57: $limits = $this->getAvailableLimit();
58: // if ($limit = $this->getRequest()->getParam($this->getLimitVarName())) {
59: // if (isset($limits[$limit])) {
60: // return $limit;
61: // }
62: // }
63: $limits = array_keys($limits);
64: return $limits[0];
65: }
66:
67: public function setCollection($collection)
68: {
69: $this->_collection = $collection;
70: // ->setCurPage($this->getCurrentPage());
71: // If not int - then not limit
72: // if ((int) $this->getLimit()) {
73: // $this->_collection->setPageSize($this->getLimit());
74: // }
75:
76: return $this;
77: }
78:
79: /**
80: * @return Mage_Core_Model_Mysql4_Collection_Abstract
81: */
82: public function getCollection()
83: {
84: return $this->_collection;
85: }
86:
87: public function getFirstNum()
88: {
89: return $this->_firstNum + 1;
90: }
91:
92: public function setFirstNum($firstNum)
93: {
94: $this->_firstNum = $firstNum;
95: return $this;
96: }
97:
98: public function getLastNum()
99: {
100: return $this->_lastNum;
101: }
102:
103: public function setLastNum($lastNum)
104: {
105: $this->_lastNum = $lastNum;
106: return $this;
107: }
108:
109: public function getTotalNum()
110: {
111: return $this->_totalNum;
112: }
113:
114: public function setTotalNum($totalNum)
115: {
116: $this->_totalNum = $totalNum;
117: return $this;
118: }
119:
120: public function isFirstPage()
121: {
122: return $this->getCurrentPage() == 1;
123: }
124:
125: public function getLastPageNum()
126: {
127: return $this->_lastPageNumber;
128: }
129:
130: public function setLastPageNum($lastPageNum)
131: {
132: $this->_lastPageNumber = $lastPageNum;
133: return $this;
134: }
135:
136: public function isLastPage()
137: {
138: return $this->getCurrentPage() >= $this->getLastPageNum();
139: }
140:
141: public function getPages()
142: {
143: $pages = array();
144: if ($this->getLastPageNum() <= $this->_displayPages) {
145: $pages = range(1, $this->getLastPageNum());
146: } else {
147: $half = ceil($this->_displayPages / 2);
148: if ($this->getCurrentPage() >= $half && $this->getCurrentPage() <= $this->getLastPageNum() - $half) {
149: $start = ($this->getCurrentPage() - $half) + 1;
150: $finish = ($start + $this->_displayPages) - 1;
151: } elseif ($this->getCurrentPage() < $half) {
152: $start = 1;
153: $finish = $this->_displayPages;
154: } elseif ($this->getCurrentPage() > ($this->getLastPageNum() - $half)) {
155: $finish = $this->getLastPageNum();
156: $start = $finish - $this->_displayPages + 1;
157: }
158: $pages = range($start, $finish);
159: }
160:
161: return $pages;
162: }
163:
164: public function getPreviousPageUrl()
165: {
166: return $this->getPageUrl($this->getCurrentPage(-1));
167: }
168:
169: public function getNextPageUrl()
170: {
171: return $this->getPageUrl($this->getCurrentPage(+1));
172: }
173:
174: public function getLastPageUrl()
175: {
176: return $this->getPageUrl($this->getLastPageNum());
177: }
178:
179: }
180:
181: