ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
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;
30
31class Pagination implements PaginationInterface
32{
33 use ComponentHelper;
35 use Triggerer;
36
37 protected int $total_entries = 0;
38 protected int $page_size;
39 protected int $current_page = 0;
41 protected ?string $target_url = null;
42 protected string $parameter_name = "pagination_offset";
43 protected ?int $max_pages_shown = null;
44 protected ?int $dd_threshold = null;
45 protected string $dropdown_label;
47
49 {
50 $this->signal_generator = $signal_generator;
51 $this->initSignals();
52 $this->dropdown_label = self::DEFAULT_DROPDOWN_LABEL;
53 }
54
58 public function withResetSignals(): PaginationInterface
59 {
60 $clone = clone $this;
61 $clone->initSignals();
62 return $clone;
63 }
64
68 protected function initSignals(): void
69 {
70 $this->internal_signal = $this->signal_generator->create();
71 }
72
76 public function getInternalSignal(): Signal
77 {
79 }
80
84 public function withTargetURL(string $url, string $parameter_name): PaginationInterface
85 {
86 $clone = clone $this;
87 $clone->target_url = $url;
88 $clone->parameter_name = $parameter_name;
89 return $clone;
90 }
91
95 public function getTargetURL(): ?string
96 {
97 return $this->target_url;
98 }
99
103 public function getParameterName(): string
104 {
106 }
107
111 public function withTotalEntries(int $total): PaginationInterface
112 {
113 $clone = clone $this;
114 $clone->total_entries = $total;
115 return $clone;
116 }
117
121 public function withPageSize(int $size): PaginationInterface
122 {
123 //raise, if size < 1
124 $clone = clone $this;
125 $clone->page_size = $size;
126 return $clone;
127 }
128
132 public function getPageSize(): int
133 {
134 return $this->page_size;
135 }
136
140 public function withCurrentPage(int $page): PaginationInterface
141 {
142 $clone = clone $this;
143 $clone->current_page = $page;
144 return $clone;
145 }
146
150 public function getCurrentPage(): int
151 {
152 return $this->current_page;
153 }
154
155 protected function getOffset(): int
156 {
157 return $this->page_size * $this->current_page;
158 }
159
163 public function withOnSelect(Signal $signal): PaginationInterface
164 {
165 return $this->withTriggeredSignal($signal, 'select');
166 }
167
171 public function getNumberOfPages(): int
172 {
173 $pages = ceil($this->total_entries / $this->page_size);
174 return (int) $pages;
175 }
176
180 public function withMaxPaginationButtons(int $amount): PaginationInterface
181 {
182 $clone = clone $this;
183 $clone->max_pages_shown = $amount;
184 return $clone;
185 }
186
190 public function getMaxPaginationButtons(): ?int
191 {
193 }
194
195 protected function getPageLength(): int
196 {
197 if ($this->getOffset() + $this->page_size > $this->total_entries) {
198 return $this->total_entries - $this->getOffset();
199 }
200 return $this->page_size;
201 }
202
206 public function withDropdownAt(int $amount): PaginationInterface
207 {
208 $clone = clone $this;
209 $clone->dd_threshold = $amount;
210 return $clone;
211 }
212
216 public function getDropdownAt(): ?int
217 {
218 return $this->dd_threshold;
219 }
220
224 public function withDropdownLabel(string $template): PaginationInterface
225 {
226 $clone = clone $this;
227 $clone->dropdown_label = $template;
228 return $clone;
229 }
230
234 public function getDropdownLabel(): string
235 {
237 }
238
242 public function getDefaultDropdownLabel(): string
243 {
245 }
246
247 public function getRange(): ?Range
248 {
249 if ($this->getPageLength() < 1) {
250 return null;
251 }
252 $f = new \ILIAS\Data\Factory();
253 return $f->range($this->getOffset(), $this->getPageLength());
254 }
255}
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:163
withDropdownAt(int $amount)
Layout; when number of page-entries reaches $amount, the options will be rendered as dropdown.
Definition: Pagination.php:206
getRange()
Get the current number of entries on this page.
Definition: Pagination.php:247
getNumberOfPages()
Calculate the total number of pages.
Definition: Pagination.php:171
getParameterName()
Get the parameter this instance uses.
Definition: Pagination.php:103
getMaxPaginationButtons()
Get the maximum amount of page-entries (not records per page!) to be shown.
Definition: Pagination.php:190
getInternalSignal()
Get the internal signal that is triggered on click of a button.
Definition: Pagination.php:76
__construct(SignalGeneratorInterface $signal_generator)
Definition: Pagination.php:48
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:84
getTargetURL()
Get the url this instance should trigger.
Definition: Pagination.php:95
getCurrentPage()
Get the currently selected page.
Definition: Pagination.php:150
getDefaultDropdownLabel()
Get the default label (for comparison, mainly) - the default label will be translated,...
Definition: Pagination.php:242
withCurrentPage(int $page)
Set the selected page.
Definition: Pagination.php:140
withTotalEntries(int $total)
Initialize with the total amount of entries of the controlled data-list.
Definition: Pagination.php:111
initSignals()
Set the internal signals for this component.
Definition: Pagination.php:68
withMaxPaginationButtons(int $amount)
Layout; define, how many page-options are shown (max).
Definition: Pagination.php:180
getDropdownAt()
Below this value, the options are directly rendered as shy-buttons, on and above this value a dropdow...
Definition: Pagination.php:216
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:224
getDropdownLabel()
Get the template for the label of the dropdown.
Definition: Pagination.php:234
withPageSize(int $size)
Set the amount of entries per page.
Definition: Pagination.php:121
getPageSize()
Get the number of entries per page.
Definition: Pagination.php:132
This describes a Pagination Control.
Definition: Pagination.php:35
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.