ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
Pagination.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 2017 Nils Haagen <nils.haagen@concepts-and-training.de> Extended GPL, see docs/LICENSE */
3
5
7use ILIAS\UI\Component\ViewControl\Pagination as PaginationInterface;
12
13class Pagination implements PaginationInterface
14{
17 use Triggerer;
18
22 protected $total_entries = 0;
23
27 protected $page_size;
28
32 protected $current_page = 0;
33
38
42 protected $target_url;
43
47 protected $parameter_name = "pagination_offset";
48
53
57 protected $dd_threshold;
58
62 protected $dropdown_label;
63
64
65 public function __construct(SignalGeneratorInterface $signal_generator)
66 {
67 $this->signal_generator = $signal_generator;
68 $this->initSignals();
69 $this->dropdown_label = self::DEFAULT_DROPDOWN_LABEL;
70 }
71
75 public function withResetSignals()
76 {
77 $clone = clone $this;
78 $clone->initSignals();
79 return $clone;
80 }
81
87 protected function initSignals()
88 {
89 $this->internal_signal = $this->signal_generator->create();
90 }
91
95 public function getInternalSignal() : Signal
96 {
98 }
99
103 public function withTargetURL(string $url, string $parameter_name) : PaginationInterface
104 {
105 $this->checkStringArg("url", $url);
106 $this->checkStringArg("parameter_name", $parameter_name);
107 $clone = clone $this;
108 $clone->target_url = $url;
109 $clone->parameter_name = $parameter_name;
110 return $clone;
111 }
112
116 public function getTargetURL()
117 {
118 return $this->target_url;
119 }
120
124 public function getParameterName() : string
125 {
127 }
128
132 public function withTotalEntries(int $total) : PaginationInterface
133 {
134 $this->checkIntArg("total", $total);
135 $clone = clone $this;
136 $clone->total_entries = $total;
137 return $clone;
138 }
139
143 public function withPageSize(int $size) : PaginationInterface
144 {
145 $this->checkIntArg("size", $size);
146 //raise, if size < 1
147 $clone = clone $this;
148 $clone->page_size = $size;
149 return $clone;
150 }
151
155 public function getPageSize() : int
156 {
157 return $this->page_size;
158 }
159
163 public function withCurrentPage(int $page) : PaginationInterface
164 {
165 $this->checkIntArg("page", $page);
166 $clone = clone $this;
167 $clone->current_page = $page;
168 return $clone;
169 }
170
174 public function getCurrentPage() : int
175 {
176 return $this->current_page;
177 }
178
182 public function getOffset() : int
183 {
184 $offset = $this->page_size * $this->current_page;
185 return $offset;
186 }
187
191 public function withOnSelect(Signal $signal) : PaginationInterface
192 {
193 return $this->withTriggeredSignal($signal, 'select');
194 }
195
199 public function getNumberOfPages() : int
200 {
201 $pages = ceil($this->total_entries / $this->page_size);
202 return (int) $pages;
203 }
204
208 public function withMaxPaginationButtons(int $amount) : PaginationInterface
209 {
210 $this->checkIntArg("amount", $amount);
211 $clone = clone $this;
212 $clone->max_pages_shown = $amount;
213 return $clone;
214 }
215
219 public function getMaxPaginationButtons()
220 {
222 }
223
227 public function getPageLength() : int
228 {
229 if ($this->getOffset() + $this->page_size > $this->total_entries) {
230 return $this->total_entries - $this->getOffset();
231 }
232 return $this->page_size;
233 }
234
238 public function withDropdownAt(int $amount) : PaginationInterface
239 {
240 $this->checkIntArg("amount", $amount);
241 $clone = clone $this;
242 $clone->dd_threshold = $amount;
243 return $clone;
244 }
245
249 public function getDropdownAt()
250 {
251 return $this->dd_threshold;
252 }
253
257 public function withDropdownLabel(string $template) : PaginationInterface
258 {
259 $clone = clone $this;
260 $clone->dropdown_label = $template;
261 return $clone;
262 }
263
267 public function getDropdownLabel() : string
268 {
270 }
271
275 public function getDefaultDropdownLabel() : string
276 {
278 }
279}
$size
Definition: RandomTest.php:84
$total
Definition: Utf8Test.php:87
An exception for terminatinating execution or to throw for unit testing.
withDropdownAt(int $amount)
Layout; when number of page-entries reaches $amount, the options will be rendered as dropdown.
Definition: Pagination.php:238
getNumberOfPages()
Calculate the total number of pages.
Definition: Pagination.php:199
getParameterName()
Get the parameter this instance uses.
Definition: Pagination.php:124
getMaxPaginationButtons()
Get the maximum amount of page-entries (not records per page!) to be shown.int|null
Definition: Pagination.php:219
getInternalSignal()
Get the internal signal that is triggered on click of a button.
Definition: Pagination.php:95
__construct(SignalGeneratorInterface $signal_generator)
Definition: Pagination.php:65
withTargetURL(string $url, string $parameter_name)
Get a Pagination with this target-url.Shy-Buttons in this control will link to this url and add $para...
Definition: Pagination.php:103
getOffset()
Get the data's offset according to current page and page size.
Definition: Pagination.php:182
getTargetURL()
Get the url this instance should trigger.string|null
Definition: Pagination.php:116
getPageLength()
Get the current number of entries on this page.
Definition: Pagination.php:227
getDefaultDropdownLabel()
Get the default label (for comparison, mainly) - the default label will be translated,...
Definition: Pagination.php:275
withCurrentPage(int $page)
Set the selected page.
Definition: Pagination.php:163
withTotalEntries(int $total)
Initialize with the total amount of entries of the controlled data-list.
Definition: Pagination.php:132
initSignals()
Set the internal signals for this component.
Definition: Pagination.php:87
withMaxPaginationButtons(int $amount)
Layout; define, how many page-options are shown (max).
Definition: Pagination.php:208
getDropdownAt()
Below this value, the options are directly rendered as shy-buttons, on and above this value a dropdow...
Definition: Pagination.php:249
withDropdownLabel(string $template)
Layout; set the label for dropdown.If need (or wish) arises, you can give a template-string with vari...
Definition: Pagination.php:257
getDropdownLabel()
Get the template for the label of the dropdown.
Definition: Pagination.php:267
withPageSize(int $size)
Set the amount of entries per page.
Definition: Pagination.php:143
getPageSize()
Get the numebr of entries per page.
Definition: Pagination.php:155
This describes a Pagination Control.
Definition: Pagination.php:14
withTriggeredSignal(Component\Signal $signal, $event)
Add a triggered signal, replacing any other signals registered on the same event.
Definition: Triggerer.php:48
checkStringArg($which, $value)
Throw an InvalidArgumentException if $value is no string.
checkIntArg($which, $value)
Throw an InvalidArgumentException if $value is no int.
trait JavaScriptBindable
Trait for components implementing JavaScriptBindable providing standard implementation.
trait ComponentHelper
Provides common functionality for component implementations.
$url