ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 
6 use ILIAS\UI\Component as C;
11 
12 class Pagination implements C\ViewControl\Pagination
13 {
14  use ComponentHelper;
16  use Triggerer;
17 
21  protected $total_entries = 0;
22 
26  protected $page_size;
27 
31  protected $current_page = 0;
32 
36  protected $internal_signal;
37 
41  protected $target_url;
42 
46  protected $paramter_name = "pagination_offset";
47 
51  protected $max_pages_shown;
52 
56  protected $dd_threshold;
57 
58 
59  public function __construct(SignalGeneratorInterface $signal_generator)
60  {
61  $this->signal_generator = $signal_generator;
62  $this->initSignals();
63  }
64 
68  public function withResetSignals()
69  {
70  $clone = clone $this;
71  $clone->initSignals();
72  return $clone;
73  }
74 
80  protected function initSignals()
81  {
82  $this->internal_signal = $this->signal_generator->create();
83  }
84 
90  public function getInternalSignal()
91  {
93  }
94 
98  public function withTargetURL($url, $parameter_name)
99  {
100  $this->checkStringArg("url", $url);
101  $this->checkStringArg("paramter_name", $parameter_name);
102  $clone = clone $this;
103  $clone->target_url = $url;
104  $clone->paramter_name = $parameter_name;
105  return $clone;
106  }
107 
111  public function getTargetURL()
112  {
113  return $this->target_url;
114  }
115 
119  public function getParameterName()
120  {
121  return $this->paramter_name;
122  }
123 
127  public function withTotalEntries($total)
128  {
129  $this->checkIntArg("total", $total);
130  $clone = clone $this;
131  $clone->total_entries = $total;
132  return $clone;
133  }
134 
138  public function withPageSize($size)
139  {
140  $this->checkIntArg("size", $size);
141  //raise, if size < 1
142  $clone = clone $this;
143  $clone->page_size = $size;
144  return $clone;
145  }
146 
150  public function getPageSize()
151  {
152  return $this->page_size;
153  }
154 
158  public function withCurrentPage($page)
159  {
160  $this->checkIntArg("page", $page);
161  $clone = clone $this;
162  $clone->current_page = $page;
163  return $clone;
164  }
165 
169  public function getCurrentPage()
170  {
171  return $this->current_page;
172  }
173 
177  public function getOffset()
178  {
179  $offset = $this->page_size * $this->current_page;
180  return $offset;
181  }
182 
186  public function withOnSelect(C\Signal $signal)
187  {
188  return $this->withTriggeredSignal($signal, 'select');
189  }
190 
194  public function getNumberOfPages()
195  {
196  $pages = ceil($this->total_entries / $this->page_size);
197  return (int) $pages;
198  }
199 
203  public function withMaxPaginationButtons($amount)
204  {
205  $this->checkIntArg("amount", $amount);
206  $clone = clone $this;
207  $clone->max_pages_shown = $amount;
208  return $clone;
209  }
210 
214  public function getMaxPaginationButtons()
215  {
216  return $this->max_pages_shown;
217  }
218 
224  public function getPageLength()
225  {
226  if ($this->getOffset() + $this->page_size > $this->total_entries) {
227  return $this->total_entries - $this->getOffset();
228  }
229  return $this->page_size;
230  }
231 
235  public function withDropdownAt($amount)
236  {
237  $this->checkIntArg("amount", $amount);
238  $clone = clone $this;
239  $clone->dd_threshold = $amount;
240  return $clone;
241  }
242 
246  public function getDropdownAt()
247  {
248  return $this->dd_threshold;
249  }
250 }
$size
Definition: RandomTest.php:84
__construct(SignalGeneratorInterface $signal_generator)
Definition: Pagination.php:59
trait JavaScriptBindable
Trait for components implementing JavaScriptBindable providing standard implementation.
trait ComponentHelper
Provides common functionality for component implementations.
checkStringArg($which, $value)
Throw an InvalidArgumentException if $value is no string.
getPageLength()
Calculate the total number of pages.
Definition: Pagination.php:224
$total
Definition: Utf8Test.php:87
initSignals()
Set the internal signals for this component.
Definition: Pagination.php:80
getInternalSignal()
get the internal signal that is triggered on click of a button
Definition: Pagination.php:90
$url
checkIntArg($which, $value)
Throw an InvalidArgumentException if $value is no int.
withTriggeredSignal(Component\Signal $signal, $event)
Add a triggered signal, replacing any other signals registered on the same event. ...
Definition: Triggerer.php:48