1 | <?php |
||
19 | class View implements \IteratorAggregate |
||
20 | { |
||
21 | /** |
||
22 | * @var Configuration |
||
23 | */ |
||
24 | protected $config; |
||
25 | |||
26 | /** |
||
27 | * @var Node|null |
||
28 | */ |
||
29 | protected $first; |
||
30 | |||
31 | /** |
||
32 | * @var Node|null |
||
33 | */ |
||
34 | protected $prev; |
||
35 | |||
36 | /** |
||
37 | * @var Node |
||
38 | */ |
||
39 | protected $current; |
||
40 | |||
41 | /** |
||
42 | * @var Node|null |
||
43 | */ |
||
44 | protected $next; |
||
45 | |||
46 | /** |
||
47 | * @var Node|null |
||
48 | */ |
||
49 | protected $last; |
||
50 | |||
51 | /** |
||
52 | * @var ArrayCollection|null |
||
53 | */ |
||
54 | protected $list; |
||
55 | |||
56 | /** |
||
57 | * @param Configuration $config |
||
58 | */ |
||
59 | 27 | public function __construct(Configuration $config) { |
|
62 | |||
63 | /** |
||
64 | * @return int |
||
65 | */ |
||
66 | 14 | public function getTotal() |
|
70 | |||
71 | /** |
||
72 | * @return Node|null |
||
73 | */ |
||
74 | 5 | public function getFirst() |
|
81 | |||
82 | /** |
||
83 | * @return Node|null |
||
84 | */ |
||
85 | 3 | public function getPrev() |
|
95 | |||
96 | /** |
||
97 | * @return Node |
||
98 | */ |
||
99 | 10 | public function getCurrent() |
|
110 | |||
111 | /** |
||
112 | * @return Node|null |
||
113 | */ |
||
114 | 3 | public function getNext() |
|
124 | |||
125 | /** |
||
126 | * @return Node|null |
||
127 | */ |
||
128 | 3 | public function getLast() |
|
135 | |||
136 | /** |
||
137 | * @return ArrayCollection |
||
138 | */ |
||
139 | 7 | public function getIterator() |
|
140 | { |
||
141 | 7 | if (!($this->list instanceof ArrayCollection)) { |
|
142 | 7 | $this->list = new ArrayCollection(); |
|
143 | |||
144 | 7 | if ($this->getTotal() > 1) { |
|
145 | 6 | list($page, $page_to) = $this->getNavigateRange(); |
|
146 | 6 | for (; $page <= $page_to; $page++) { |
|
147 | 6 | if ($page == $this->config->getCurrentPage()) { |
|
148 | 6 | $this->list->add($this->getCurrent()); |
|
149 | 6 | } else { |
|
150 | 6 | $this->list->add(new Node($page, $this->buildLink($page))); |
|
151 | } |
||
152 | 6 | } |
|
153 | 6 | } |
|
154 | 7 | } |
|
155 | |||
156 | 7 | return $this->list; |
|
157 | } |
||
158 | |||
159 | /** |
||
160 | * @param int $page |
||
161 | * |
||
162 | * @return string |
||
163 | */ |
||
164 | 20 | protected function buildLink($page) |
|
176 | |||
177 | /** |
||
178 | * @return int[] |
||
179 | */ |
||
180 | 6 | protected function getNavigateRange() |
|
208 | } |
||
209 |