Overview

Packages

  • currencysymbol
  • MAbout
  • Mage
    • Admin
    • Adminhtml
    • AdminNotification
    • Api
    • Api2
    • Authorizenet
    • Backup
    • Bundle
    • Captcha
    • Catalog
    • CatalogIndex
    • CatalogInventory
    • CatalogRule
    • CatalogSearch
    • Centinel
    • Checkout
    • Cms
    • Compiler
    • Connect
    • Contacts
    • Core
    • Cron
    • CurrencySymbol
    • Customer
    • Dataflow
    • Directory
    • DirtectPost
    • Downloadable
    • Eav
    • GiftMessage
    • GoogleAnalytics
    • GoogleBase
    • GoogleCheckout
    • ImportExport
    • Index
    • Install
    • Log
    • Media
    • Newsletter
    • Oauth
    • Page
    • PageCache
    • Paygate
    • Payment
    • Paypal
    • PaypalUk
    • Persistent
    • Poll
    • ProductAlert
    • Rating
    • Reports
    • Review
    • Rss
    • Rule
    • Sales
    • SalesRule
    • Sedfriend
    • Sendfriend
    • Shipping
    • Sitemap
    • Tag
    • Tax
    • Usa
    • Weee
    • Widget
    • Wishlist
    • XmlConnect
  • None
  • Phoenix
    • Moneybookers
  • PHP
  • Zend
    • Date
    • Mime
    • XmlRpc

Classes

  • Mage_Catalog_Block_Seo_Sitemap_Tree_Pager
  • Mage_Page_Block_Html
  • Mage_Page_Block_Html_Breadcrumbs
  • Mage_Page_Block_Html_Footer
  • Mage_Page_Block_Html_Head
  • Mage_Page_Block_Html_Header
  • Mage_Page_Block_Html_Notices
  • Mage_Page_Block_Html_Pager
  • Mage_Page_Block_Html_Topmenu
  • Mage_Page_Block_Html_Welcome
  • Mage_Page_Block_Html_Wrapper
  • Mage_Page_Block_Js_Cookie
  • Mage_Page_Block_Redirect
  • Mage_Page_Helper_Data
  • Mage_Page_Helper_Html
  • Mage_Page_Helper_Layout
  • Mage_Page_Model_Config
  • Mage_Page_Model_Source_Layout
  • Overview
  • Package
  • Class
  • Tree
  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_Page
 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_Page_Block_Html_Pager extends Mage_Core_Block_Template
 37: {
 38:     protected $_collection = null;
 39:     protected $_pageVarName    = 'p';
 40:     protected $_limitVarName   = 'limit';
 41:     protected $_availableLimit = array(10=>10,20=>20,50=>50);
 42:     protected $_dispersion     = 3;
 43:     protected $_displayPages   = 5;
 44:     protected $_showPerPage    = true;
 45:     protected $_limit          = null;
 46:     protected $_outputRequired = true;
 47: 
 48:     /**
 49:      * Pages quantity per frame
 50:      * @var int
 51:      */
 52:     protected $_frameLength = 5;
 53: 
 54:     /**
 55:      * Next/previous page position relatively to the current frame
 56:      * @var int
 57:      */
 58:     protected $_jump = 5;
 59: 
 60:     /**
 61:      * Frame initialization flag
 62:      * @var bool
 63:      */
 64:     protected $_frameInitialized = false;
 65: 
 66:     /**
 67:      * Start page position in frame
 68:      * @var int
 69:      */
 70:     protected $_frameStart;
 71: 
 72:     /**
 73:      * Finish page position in frame
 74:      * @var int
 75:      */
 76:     protected $_frameEnd;
 77: 
 78:     protected function _construct()
 79:     {
 80:         parent::_construct();
 81:         $this->setData('show_amounts', true);
 82:         $this->setData('use_container', true);
 83:         $this->setTemplate('page/html/pager.phtml');
 84:     }
 85: 
 86:     public function getCurrentPage()
 87:     {
 88:         if ($page = (int) $this->getRequest()->getParam($this->getPageVarName())) {
 89:             return $page;
 90:         }
 91:         return 1;
 92:     }
 93: 
 94:     public function getLimit()
 95:     {
 96:         if ($this->_limit !== null) {
 97:             return $this->_limit;
 98:         }
 99:         $limits = $this->getAvailableLimit();
100:         if ($limit = $this->getRequest()->getParam($this->getLimitVarName())) {
101:             if (isset($limits[$limit])) {
102:                 return $limit;
103:             }
104:         }
105:         $limits = array_keys($limits);
106:         return $limits[0];
107:     }
108: 
109:     /**
110:      * Setter for limit items per page
111:      *
112:      * @param int $limit
113:      * @return Mage_Page_Block_Html_Pager
114:      */
115:     public function setLimit($limit)
116:     {
117:         $this->_limit = $limit;
118:         return $this;
119:     }
120: 
121:     public function setCollection($collection)
122:     {
123:         $this->_collection = $collection
124:             ->setCurPage($this->getCurrentPage());
125:         // If not int - then not limit
126:         if ((int) $this->getLimit()) {
127:             $this->_collection->setPageSize($this->getLimit());
128:         }
129: 
130:         $this->_setFrameInitialized(false);
131: 
132:         return $this;
133:     }
134: 
135:     /**
136:      * @return Mage_Core_Model_Mysql4_Collection_Abstract
137:      */
138:     public function getCollection()
139:     {
140:         return $this->_collection;
141:     }
142: 
143:     public function setPageVarName($varName)
144:     {
145:         $this->_pageVarName = $varName;
146:         return $this;
147:     }
148: 
149:     public function getPageVarName()
150:     {
151:         return $this->_pageVarName;
152:     }
153: 
154:     public function setShowPerPage($varName)
155:     {
156:         $this->_showPerPage=$varName;
157:         return $this;
158:     }
159: 
160:     public function getShowPerPage()
161:     {
162:         if(sizeof($this->getAvailableLimit())<=1) {
163:             return false;
164:         }
165:         return $this->_showPerPage;
166:     }
167: 
168:     public function setLimitVarName($varName)
169:     {
170:         $this->_limitVarName = $varName;
171:         return $this;
172:     }
173: 
174:     public function getLimitVarName()
175:     {
176:         return $this->_limitVarName;
177:     }
178: 
179:     public function setAvailableLimit(array $limits)
180:     {
181:         $this->_availableLimit = $limits;
182:     }
183: 
184:     public function getAvailableLimit()
185:     {
186:         return $this->_availableLimit;
187:     }
188: 
189:     public function getFirstNum()
190:     {
191:         $collection = $this->getCollection();
192:         return $collection->getPageSize()*($collection->getCurPage()-1)+1;
193:     }
194: 
195:     public function getLastNum()
196:     {
197:         $collection = $this->getCollection();
198:         return $collection->getPageSize()*($collection->getCurPage()-1)+$collection->count();
199:     }
200: 
201:     public function getTotalNum()
202:     {
203:         return $this->getCollection()->getSize();
204:     }
205: 
206:     public function isFirstPage()
207:     {
208:         return $this->getCollection()->getCurPage() == 1;
209:     }
210: 
211:     public function getLastPageNum()
212:     {
213:         return $this->getCollection()->getLastPageNumber();
214:     }
215: 
216:     public function isLastPage()
217:     {
218:         return $this->getCollection()->getCurPage() >= $this->getLastPageNum();
219:     }
220: 
221:     public function isLimitCurrent($limit)
222:     {
223:         return $limit == $this->getLimit();
224:     }
225: 
226:     public function isPageCurrent($page)
227:     {
228:         return $page == $this->getCurrentPage();
229:     }
230: 
231:     public function getPages()
232:     {
233:         $collection = $this->getCollection();
234: 
235:         $pages = array();
236:         if ($collection->getLastPageNumber() <= $this->_displayPages) {
237:             $pages = range(1, $collection->getLastPageNumber());
238:         }
239:         else {
240:             $half = ceil($this->_displayPages / 2);
241:             if ($collection->getCurPage() >= $half && $collection->getCurPage() <= $collection->getLastPageNumber() - $half) {
242:                 $start  = ($collection->getCurPage() - $half) + 1;
243:                 $finish = ($start + $this->_displayPages) - 1;
244:             }
245:             elseif ($collection->getCurPage() < $half) {
246:                 $start  = 1;
247:                 $finish = $this->_displayPages;
248:             }
249:             elseif ($collection->getCurPage() > ($collection->getLastPageNumber() - $half)) {
250:                 $finish = $collection->getLastPageNumber();
251:                 $start  = $finish - $this->_displayPages + 1;
252:             }
253: 
254:             $pages = range($start, $finish);
255:         }
256:         return $pages;
257:     }
258: 
259:     public function getFirstPageUrl()
260:     {
261:         return $this->getPageUrl(1);
262:     }
263: 
264:     public function getPreviousPageUrl()
265:     {
266:         return $this->getPageUrl($this->getCollection()->getCurPage(-1));
267:     }
268: 
269:     public function getNextPageUrl()
270:     {
271:         return $this->getPageUrl($this->getCollection()->getCurPage(+1));
272:     }
273: 
274:     public function getLastPageUrl()
275:     {
276:         return $this->getPageUrl($this->getCollection()->getLastPageNumber());
277:     }
278: 
279:     public function getPageUrl($page)
280:     {
281:         return $this->getPagerUrl(array($this->getPageVarName()=>$page));
282:     }
283: 
284:     public function getLimitUrl($limit)
285:     {
286:         return $this->getPagerUrl(array($this->getLimitVarName()=>$limit));
287:     }
288: 
289:     public function getPagerUrl($params=array())
290:     {
291:         $urlParams = array();
292:         $urlParams['_current']  = true;
293:         $urlParams['_escape']   = true;
294:         $urlParams['_use_rewrite']   = true;
295:         $urlParams['_query']    = $params;
296:         return $this->getUrl('*/*/*', $urlParams);
297:     }
298: 
299:     /**
300:      * Getter for $_frameStart
301:      *
302:      * @return int
303:      */
304:     public function getFrameStart()
305:     {
306:         $this->_initFrame();
307:         return $this->_frameStart;
308:     }
309: 
310:     /**
311:      * Getter for $_frameEnd
312:      *
313:      * @return int
314:      */
315:     public function getFrameEnd()
316:     {
317:         $this->_initFrame();
318:         return $this->_frameEnd;
319:     }
320: 
321:     /**
322:      * Return array of pages in frame
323:      *
324:      * @return array
325:      */
326:     public function getFramePages()
327:     {
328:         $start = $this->getFrameStart();
329:         $end = $this->getFrameEnd();
330:         return range($start, $end);
331:     }
332: 
333:     /**
334:      * Return page number of Previous jump
335:      *
336:      * @return int
337:      */
338:     public function getPreviousJumpPage()
339:     {
340:         if (!$this->getJump()) {
341:             return null;
342:         }
343:         $frameStart = $this->getFrameStart();
344:         if ($frameStart - 1 > 1) {
345:             return max(2, $frameStart - $this->getJump());
346:         }
347: 
348:         return null;
349:     }
350: 
351:     /**
352:      * Prepare URL for Previous Jump
353:      *
354:      * @return string
355:      */
356:     public function getPreviousJumpUrl()
357:     {
358:         return $this->getPageUrl($this->getPreviousJumpPage());
359:     }
360: 
361:     /**
362:      * Return page number of Next jump
363:      *
364:      * @return int
365:      */
366:     public function getNextJumpPage()
367:     {
368:         if (!$this->getJump()) {
369:             return null;
370:         }
371:         $frameEnd = $this->getFrameEnd();
372:         if ($this->getLastPageNum() - $frameEnd > 1) {
373:             return min($this->getLastPageNum() - 1, $frameEnd + $this->getJump());
374:         }
375: 
376:         return null;
377:     }
378: 
379:     /**
380:      * Prepare URL for Next Jump
381:      *
382:      * @return string
383:      */
384:     public function getNextJumpUrl()
385:     {
386:         return $this->getPageUrl($this->getNextJumpPage());
387:     }
388: 
389:     /**
390:      * Getter for $_frameLength
391:      *
392:      * @return int
393:      */
394:     public function getFrameLength()
395:     {
396:         return $this->_frameLength;
397:     }
398: 
399:     /**
400:      * Getter for $_jump
401:      *
402:      * @return int
403:      */
404:     public function getJump()
405:     {
406:         return $this->_jump;
407:     }
408: 
409:     /**
410:      * Setter for $_frameLength
411:      *
412:      * @param int $frame
413:      * @return Mage_Page_Block_Html_Pager
414:      */
415:     public function setFrameLength($frame)
416:     {
417:         $frame = abs(intval($frame));
418:         if ($frame == 0) {
419:             $frame = $this->_frameLength;
420:         }
421:         if ($this->getFrameLength() != $frame) {
422:             $this->_setFrameInitialized(false);
423:             $this->_frameLength = $frame;
424:         }
425: 
426:         return $this;
427:     }
428: 
429:     /**
430:      * Setter for $_jump
431:      *
432:      * @param int $jump
433:      * @return Mage_Page_Block_Html_Pager
434:      */
435:     public function setJump($jump)
436:     {
437:         $jump = abs(intval($jump));
438:         if ($this->getJump() != $jump) {
439:             $this->_setFrameInitialized(false);
440:             $this->_jump = $jump;
441:         }
442: 
443:         return $this;
444:     }
445: 
446:     /**
447:      * Whether to show first page in pagination or not
448:      *
449:      * @return bool
450:      */
451:     public function canShowFirst()
452:     {
453:         return $this->getJump() > 1 && $this->getFrameStart() > 1;
454:     }
455: 
456:     /**
457:      * Whether to show last page in pagination or not
458:      *
459:      * @return bool
460:      */
461:     public function canShowLast()
462:     {
463:         return $this->getJump() > 1 && $this->getFrameEnd() < $this->getLastPageNum();
464:     }
465: 
466:     /**
467:      * Whether to show link to Previous Jump
468:      *
469:      * @return bool
470:      */
471:     public function canShowPreviousJump()
472:     {
473:         return $this->getPreviousJumpPage() !== null;
474:     }
475: 
476:     /**
477:      * Whether to show link to Next Jump
478:      *
479:      * @return bool
480:      */
481:     public function canShowNextJump()
482:     {
483:         return $this->getNextJumpPage() !== null;
484:     }
485: 
486:     /**
487:      * Initialize frame data, such as frame start, frame start etc.
488:      *
489:      * @return Mage_Page_Block_Html_Pager
490:      */
491:     protected function _initFrame()
492:     {
493:         if (!$this->isFrameInitialized()) {
494:             $start = 0;
495:             $end = 0;
496: 
497:             $collection = $this->getCollection();
498:             if ($collection->getLastPageNumber() <= $this->getFrameLength()) {
499:                 $start = 1;
500:                 $end = $collection->getLastPageNumber();
501:             }
502:             else {
503:                 $half = ceil($this->getFrameLength() / 2);
504:                 if ($collection->getCurPage() >= $half && $collection->getCurPage() <= $collection->getLastPageNumber() - $half) {
505:                     $start  = ($collection->getCurPage() - $half) + 1;
506:                     $end = ($start + $this->getFrameLength()) - 1;
507:                 }
508:                 elseif ($collection->getCurPage() < $half) {
509:                     $start  = 1;
510:                     $end = $this->getFrameLength();
511:                 }
512:                 elseif ($collection->getCurPage() > ($collection->getLastPageNumber() - $half)) {
513:                     $end = $collection->getLastPageNumber();
514:                     $start  = $end - $this->getFrameLength() + 1;
515:                 }
516:             }
517:             $this->_frameStart = $start;
518:             $this->_frameEnd = $end;
519: 
520:             $this->_setFrameInitialized(true);
521:         }
522: 
523:         return $this;
524:     }
525: 
526:     /**
527:      * Setter for flag _frameInitialized
528:      *
529:      * @param bool $flag
530:      * @return Mage_Page_Block_Html_Pager
531:      */
532:     protected function _setFrameInitialized($flag)
533:     {
534:         $this->_frameInitialized = (bool)$flag;
535:         return $this;
536:     }
537: 
538:     /**
539:      * Check if frame data was initialized
540:      *
541:      * @return Mage_Page_Block_Html_Pager
542:      */
543:     public function isFrameInitialized()
544:     {
545:         return $this->_frameInitialized;
546:     }
547: 
548:     /**
549:      * Getter for alternative text for Previous link in pagination frame
550:      *
551:      * @return string
552:      */
553:     public function getAnchorTextForPrevious()
554:     {
555:         return Mage::getStoreConfig('design/pagination/anchor_text_for_previous');
556:     }
557: 
558:     /**
559:      * Getter for alternative text for Next link in pagination frame
560:      *
561:      * @return string
562:      */
563:     public function getAnchorTextForNext()
564:     {
565:         return Mage::getStoreConfig('design/pagination/anchor_text_for_next');
566:     }
567: 
568:     /**
569:      * Set whether output of the pager is mandatory
570:      *
571:      * @param bool $isRequired
572:      * @return Mage_Page_Block_Html_Pager
573:      */
574:     public function setIsOutputRequired($isRequired)
575:     {
576:         $this->_outputRequired = (bool)$isRequired;
577:         return $this;
578:     }
579: 
580:     /**
581:      * Determine whether the pagination should be eventually rendered
582:      *
583:      * @return string
584:      */
585:     protected function _toHtml()
586:     {
587:         if ($this->_outputRequired || $this->getTotalNum() > $this->getLimit()) {
588:             return parent::_toHtml();
589:         }
590:         return '';
591:     }
592: }
593: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0