ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
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 
7 use ILIAS\UI\Component\ViewControl\Pagination as PaginationInterface;
12 
13 class Pagination implements PaginationInterface
14 {
15  use ComponentHelper;
17  use Triggerer;
18 
22  protected $total_entries = 0;
23 
27  protected $page_size;
28 
32  protected $current_page = 0;
33 
37  protected $internal_signal;
38 
42  protected $target_url;
43 
47  protected $parameter_name = "pagination_offset";
48 
52  protected $max_pages_shown;
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  {
126  return $this->parameter_name;
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  {
221  return $this->max_pages_shown;
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  {
269  return $this->dropdown_label;
270  }
271 
275  public function getDefaultDropdownLabel() : string
276  {
277  return self::DEFAULT_DROPDOWN_LABEL;
278  }
279 }
getDropdownAt()
Below this value, the options are directly rendered as shy-buttons, on and above this value a dropdow...
Definition: Pagination.php:249
withPageSize(int $size)
Set the amount of entries per page.
Definition: Pagination.php:143
getTargetURL()
Get the url this instance should trigger.string|null
Definition: Pagination.php:116
$size
Definition: RandomTest.php:84
__construct(SignalGeneratorInterface $signal_generator)
Definition: Pagination.php:65
trait JavaScriptBindable
Trait for components implementing JavaScriptBindable providing standard implementation.
getMaxPaginationButtons()
Get the maximum amount of page-entries (not records per page!) to be shown.int|null ...
Definition: Pagination.php:219
trait ComponentHelper
Provides common functionality for component implementations.
withCurrentPage(int $page)
Set the selected page.
Definition: Pagination.php:163
checkStringArg($which, $value)
Throw an InvalidArgumentException if $value is no string.
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
getPageLength()
Get the current number of entries on this page.
Definition: Pagination.php:227
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
$total
Definition: Utf8Test.php:87
getNumberOfPages()
Calculate the total number of pages.
Definition: Pagination.php:199
This describes a Pagination Control.
Definition: Pagination.php:13
withDropdownAt(int $amount)
Layout; when number of page-entries reaches $amount, the options will be rendered as dropdown...
Definition: Pagination.php:238
getOffset()
Get the data&#39;s offset according to current page and page size.
Definition: Pagination.php:182
withMaxPaginationButtons(int $amount)
Layout; define, how many page-options are shown (max).
Definition: Pagination.php:208
initSignals()
Set the internal signals for this component.
Definition: Pagination.php:87
getCurrentPage()
Get the currently slected page.
Definition: Pagination.php:174
getDropdownLabel()
Get the template for the label of the dropdown.
Definition: Pagination.php:267
getParameterName()
Get the parameter this instance uses.
Definition: Pagination.php:124
getInternalSignal()
Get the internal signal that is triggered on click of a button.
Definition: Pagination.php:95
getPageSize()
Get the numebr of entries per page.
Definition: Pagination.php:155
getDefaultDropdownLabel()
Get the default label (for comparison, mainly) - the default label will be translated, a custom label will not.
Definition: Pagination.php:275
$url
checkIntArg($which, $value)
Throw an InvalidArgumentException if $value is no int.
withTotalEntries(int $total)
Initialize with the total amount of entries of the controlled data-list.
Definition: Pagination.php:132
withTriggeredSignal(Component\Signal $signal, $event)
Add a triggered signal, replacing any other signals registered on the same event. ...
Definition: Triggerer.php:48