ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
Pagination.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24use ILIAS\UI\Component\ViewControl\Pagination as PaginationInterface;
25use ILIAS\UI\Implementation\Component\ComponentHelper;
29
31
32class Pagination implements PaginationInterface
33{
34 use ComponentHelper;
36 use Triggerer;
37
38 protected int $total_entries = 0;
39 protected int $page_size;
40 protected int $current_page = 0;
42 protected ?string $target_url = null;
43 protected string $parameter_name = "pagination_offset";
44 protected ?int $max_pages_shown = null;
45 protected ?int $dd_threshold = null;
46 protected string $dropdown_label;
48
50 {
51 $this->signal_generator = $signal_generator;
52 $this->initSignals();
53 $this->dropdown_label = self::DEFAULT_DROPDOWN_LABEL;
54 }
55
59 public function withResetSignals(): PaginationInterface
60 {
61 $clone = clone $this;
62 $clone->initSignals();
63 return $clone;
64 }
65
69 protected function initSignals(): void
70 {
71 $this->internal_signal = $this->signal_generator->create();
72 }
73
77 public function getInternalSignal(): Signal
78 {
80 }
81
85 public function withTargetURL(string $url, string $parameter_name): PaginationInterface
86 {
87 $clone = clone $this;
88 $clone->target_url = $url;
89 $clone->parameter_name = $parameter_name;
90 return $clone;
91 }
92
96 public function getTargetURL(): ?string
97 {
98 return $this->target_url;
99 }
100
104 public function getParameterName(): string
105 {
107 }
108
112 public function withTotalEntries(int $total): PaginationInterface
113 {
114 $clone = clone $this;
115 $clone->total_entries = $total;
116 return $clone;
117 }
118
122 public function withPageSize(int $size): PaginationInterface
123 {
124 //raise, if size < 1
125 $clone = clone $this;
126 $clone->page_size = $size;
127 return $clone;
128 }
129
133 public function getPageSize(): int
134 {
135 return $this->page_size;
136 }
137
141 public function withCurrentPage(int $page): PaginationInterface
142 {
143 $clone = clone $this;
144 $clone->current_page = $page;
145 return $clone;
146 }
147
151 public function getCurrentPage(): int
152 {
153 return $this->current_page;
154 }
155
156 protected function getOffset(): int
157 {
158 return $this->page_size * $this->current_page;
159 }
160
164 public function withOnSelect(Signal $signal): PaginationInterface
165 {
166 return $this->withTriggeredSignal($signal, 'select');
167 }
168
172 public function getNumberOfPages(): int
173 {
174 $pages = ceil($this->total_entries / $this->page_size);
175 return (int) $pages;
176 }
177
181 public function withMaxPaginationButtons(int $amount): PaginationInterface
182 {
183 $clone = clone $this;
184 $clone->max_pages_shown = $amount;
185 return $clone;
186 }
187
191 public function getMaxPaginationButtons(): ?int
192 {
194 }
195
196 protected function getPageLength(): int
197 {
198 if ($this->getOffset() + $this->page_size > $this->total_entries) {
199 return $this->total_entries - $this->getOffset();
200 }
201 return $this->page_size;
202 }
203
207 public function withDropdownAt(int $amount): PaginationInterface
208 {
209 $clone = clone $this;
210 $clone->dd_threshold = $amount;
211 return $clone;
212 }
213
217 public function getDropdownAt(): ?int
218 {
219 return $this->dd_threshold;
220 }
221
225 public function withDropdownLabel(string $template): PaginationInterface
226 {
227 $clone = clone $this;
228 $clone->dropdown_label = $template;
229 return $clone;
230 }
231
235 public function getDropdownLabel(): string
236 {
238 }
239
243 public function getDefaultDropdownLabel(): string
244 {
246 }
247
248 public function getRange(): ?Range
249 {
250 if ($this->getPageLength() < 1) {
251 return null;
252 }
253 $f = new \ILIAS\Data\Factory();
254 return $f->range($this->getOffset(), $this->getPageLength());
255 }
256}
A simple class to express a naive range of whole positive numbers.
Definition: Range.php:29
withOnSelect(Signal $signal)
Register a signal with the control.
Definition: Pagination.php:164
withDropdownAt(int $amount)
Layout; when number of page-entries reaches $amount, the options will be rendered as dropdown.
Definition: Pagination.php:207
getRange()
Get the current number of entries on this page.
Definition: Pagination.php:248
getNumberOfPages()
Calculate the total number of pages.
Definition: Pagination.php:172
getParameterName()
Get the parameter this instance uses.
Definition: Pagination.php:104
getMaxPaginationButtons()
Get the maximum amount of page-entries (not records per page!) to be shown.
Definition: Pagination.php:191
getInternalSignal()
Get the internal signal that is triggered on click of a button.
Definition: Pagination.php:77
__construct(SignalGeneratorInterface $signal_generator)
Definition: Pagination.php:49
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:85
getTargetURL()
Get the url this instance should trigger.
Definition: Pagination.php:96
getCurrentPage()
Get the currently selected page.
Definition: Pagination.php:151
getDefaultDropdownLabel()
Get the default label (for comparison, mainly) - the default label will be translated,...
Definition: Pagination.php:243
withCurrentPage(int $page)
Set the selected page.
Definition: Pagination.php:141
withTotalEntries(int $total)
Initialize with the total amount of entries of the controlled data-list.
Definition: Pagination.php:112
initSignals()
Set the internal signals for this component.
Definition: Pagination.php:69
withMaxPaginationButtons(int $amount)
Layout; define, how many page-options are shown (max).
Definition: Pagination.php:181
getDropdownAt()
Below this value, the options are directly rendered as shy-buttons, on and above this value a dropdow...
Definition: Pagination.php:217
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:225
getDropdownLabel()
Get the template for the label of the dropdown.
Definition: Pagination.php:235
withPageSize(int $size)
Set the amount of entries per page.
Definition: Pagination.php:122
getPageSize()
Get the number of entries per page.
Definition: Pagination.php:133
This describes a Pagination Control.
Definition: Pagination.php:33
withTriggeredSignal(C\Signal $signal, string $event)
Add a triggered signal, replacing any other signals registered on the same event.
Definition: Triggerer.php:62
trait JavaScriptBindable
Trait for components implementing JavaScriptBindable providing standard implementation.
$url
Definition: shib_logout.php:68