1 <?php
2
3 4 5 6 7 8 9 10
11
12 namespace Grido\Components;
13
14 15 16 17 18 19 20 21 22 23 24 25 26
27 class Paginator extends \Nette\Utils\Paginator
28 {
29
30 protected $page;
31
32
33 protected $steps = array();
34
35
36 protected $countBegin;
37
38
39 protected $countEnd;
40
41
42 protected $grid;
43
44 45 46 47
48 public function setGrid(\Grido\Grid $grid)
49 {
50 $this->grid = $grid;
51 return $this;
52 }
53
54
55
56 57 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 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 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 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