Grido@master
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Todo
  • Download

Namespaces

  • Grido
    • Components
      • Actions
      • Columns
      • Filters
    • DataSources
    • PropertyAccessors
    • Translations

Classes

  • Grido\Translations\FileTranslator
  1 <?php
  2 
  3 /**
  4  * This file is part of the Grido (https://github.com/o5/grido)
  5  *
  6  * Copyright (c) 2011 Petr Bugyík (http://petr.bugyik.cz)
  7  *
  8  * For the full copyright and license information, please view
  9  * the file LICENSE.md that was distributed with this source code.
 10  */
 11 
 12 namespace Grido\Components;
 13 
 14 /**
 15  * Paginating grid.
 16  *
 17  * @package     Grido
 18  * @subpackage  Components
 19  * @author      Petr Bugyík
 20  *
 21  * @property-read int $page
 22  * @property-read array $steps
 23  * @property-read int $countEnd
 24  * @property-read int $countBegin
 25  * @property-write \Grido\Grid $grid
 26  */
 27 class Paginator extends \Nette\Utils\Paginator
 28 {
 29     /** @var int */
 30     protected $page;
 31 
 32     /** @var array */
 33     protected $steps = array();
 34 
 35     /** @var int */
 36     protected $countBegin;
 37 
 38     /** @var int */
 39     protected $countEnd;
 40 
 41     /** @var \Grido\Grid */
 42     protected $grid;
 43 
 44     /**
 45      * @param \Grido\Grid $grid
 46      * @return Paginator
 47      */
 48     public function setGrid(\Grido\Grid $grid)
 49     {
 50         $this->grid = $grid;
 51         return $this;
 52     }
 53 
 54     /**********************************************************************************************/
 55 
 56     /**
 57      * @return int
 58      */
 59     public function getPage()
 60     {
 61         if ($this->page === NULL) {
 62             $this->page = parent::getPage();
 63         }
 64 
 65         return $this->page;
 66     }
 67 
 68     /**
 69      * @return array
 70      */
 71     public function getSteps()
 72     {
 73         if (!$this->steps) {
 74             $arr = range(
 75                 max($this->getFirstPage(), $this->getPage() - 3),
 76                 min($this->getLastPage(), $this->getPage() + 3)
 77             );
 78 
 79             $count = 4;
 80             $quotient = ($this->getPageCount() - 1) / $count;
 81 
 82             for ($i = 0; $i <= $count; $i++) {
 83                 $arr[] = (int) (round($quotient * $i) + $this->getFirstPage());
 84             }
 85 
 86             sort($arr);
 87             $this->steps = array_values(array_unique($arr));
 88         }
 89 
 90         return $this->steps;
 91     }
 92 
 93     /**
 94      * @return int
 95      */
 96     public function getCountBegin()
 97     {
 98         if ($this->countBegin === NULL) {
 99             $this->countBegin = $this->grid->getCount() > 0 ? $this->getOffset() + 1 : 0;
100         }
101 
102         return $this->countBegin;
103     }
104 
105     /**
106      * @return int
107      */
108     public function getCountEnd()
109     {
110         if ($this->countEnd === NULL) {
111             $this->countEnd = $this->grid->getCount() > 0
112                 ? min($this->grid->getCount(), $this->getPage() * $this->grid->getPerPage())
113                 : 0;
114         }
115 
116         return $this->countEnd;
117     }
118 }
119 
Grido@master API documentation generated by ApiGen