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
26use ILIAS\Data\Factory as DataFactory;
27use ILIAS\Refinery\Factory as Refinery;
31use ILIAS\UI\Implementation\Component\ComponentHelper;
33
35{
36 use ComponentHelper;
38
39 public const DEFAULT_LIMITS = [5, 10, 25, 50, 100, 250, 500, \PHP_INT_MAX];
40 public const FNAME_OFFSET = 'offset';
41 public const FNAME_LIMIT = 'limit';
42 protected const NUMBER_OF_VISIBLE_SECTIONS = 7;
43
45 protected array $options;
46 protected ?int $total_count = null;
47 protected int $number_of_entries;
48 protected string $label_limit = '';
49
50 public function __construct(
51 FieldFactory $field_factory,
52 DataFactory $data_factory,
54 SignalGeneratorInterface $signal_generator
55 ) {
56 parent::__construct($data_factory, $refinery);
57
58 $this->setInputGroup(
59 $field_factory->group([
60 self::FNAME_OFFSET => $field_factory->hidden(),
61 self::FNAME_LIMIT => $field_factory->hidden(),
62 ])
63 ->withAdditionalTransformation($this->getRangeTransform())
64 ->withAdditionalTransformation($this->getCorrectOffsetForPageSize())
65 );
66
67 $this->internal_selection_signal = $signal_generator->create();
68 $this->number_of_entries = self::NUMBER_OF_VISIBLE_SECTIONS;
69 }
70
71 protected function getRangeTransform(): Transformation
72 {
73 return $this->refinery->custom()->transformation(
74 function ($v): Range {
75 if (is_null($v)) {
76 $limit = current($this->getLimitOptions());
77 } else {
78 list(self::FNAME_OFFSET => $offset, self::FNAME_LIMIT => $limit) = array_map('intval', $v);
79 };
80 return $this->data_factory->range($offset, $limit);
81 }
82 );
83 }
84
86 {
87 return $this->refinery->custom()->transformation(
88 function ($v): Range {
89 list($offset, $limit) = $v->unpack();
90 if($limit === 0) {
91 $limit = current($this->getLimitOptions());
92 }
93 $current_page = floor($offset / $limit);
94 $offset = $current_page * $limit;
95 return $this->data_factory->range((int)$offset, $limit);
96 }
97 );
98 }
99
100 public function getInternalSignal(): Signal
101 {
103 }
104
105 public function withLimitOptions(array $options): self
106 {
107 $this->checkArgListElements('options', $options, 'int');
108 $clone = clone $this;
109 $clone->options = $options;
110 return $clone;
111 }
112
113 public function getLimitOptions(): array
114 {
115 return $this->options ?? self::DEFAULT_LIMITS;
116 }
117
118 public function getLabelLimit(): string
119 {
120 return $this->label_limit;
121 }
122
123 public function withAriaLabelLimit(string $label_limit): self
124 {
125 $clone = clone $this;
126 $clone->label_limit = $label_limit;
127 return $clone;
128 }
129
130 public function withLabelOffset(string $label): self
131 {
132 $clone = clone $this;
133 $clone->label = $label;
134 return $clone;
135 }
136
138 {
139 $clone = clone $this;
140 $clone->number_of_entries = $number_of_entries;
141 return $clone;
142 }
143
145 {
147 }
148
149 public function getTotalCount(): ?int
150 {
151 return $this->total_count;
152 }
153
154 public function withTotalCount(?int $total_count): self
155 {
156 $clone = clone $this;
157 $clone->total_count = $total_count;
158 return $clone;
159 }
160}
Factory for Date Formats.
Definition: Factory.php:27
Builds data types.
Definition: Factory.php:36
A simple class to express a naive range of whole positive numbers.
Definition: Range.php:29
__construct(FieldFactory $field_factory, DataFactory $data_factory, Refinery $refinery, SignalGeneratorInterface $signal_generator)
Definition: Pagination.php:50
withLimitOptions(array $options)
Optionally provide a list of integers for the page-length selection.
Definition: Pagination.php:105
withTotalCount(?int $total_count)
In order to calculate the sections, the pagination needs to know the total amount of entries.
Definition: Pagination.php:154
withNumberOfVisibleEntries(int $number_of_entries)
You may alter the amount of sections shown simultanously: there is always the first and last section,...
Definition: Pagination.php:137
A transformation is a function from one datatype to another.
This describes a Pagination View Control.
Definition: Pagination.php:29
Describes a source for input names.
Definition: NameSource.php:27
create(string $class='')
Create a signal, each created signal MUST have a unique ID.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Factory.php:21
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Factory.php:21