ILIAS  trunk Revision v13.0_alpha-52-g21c366bbdd4
ScheduleTable.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use Generator;
35use ILIAS\Refinery\Factory as Refinery;
39use ILIAS\UI\Factory as UIFactory;
40use ILIAS\UI\Renderer as UIRenderer;
43use ilLanguage;
44use ilUtil;
45
46class ScheduleTable implements Table
47{
49
50 public const ID = 'bksd';
51
52 public const ROW_ID_PARAMETER = 'schedule_id';
53
54 public const ACTION_PARAMETER = 'action';
55
56 public const ACTION_TYPE_PARAMETER = 'action_type';
57
58 public function __construct(
59 private readonly ilCtrlInterface $ctrl,
60 private readonly ilLanguage $lng,
61 private readonly ilGlobalTemplateInterface $tpl,
62 private readonly UIFactory $ui_factory,
63 private readonly UIRenderer $ui_renderer,
64 private readonly Refinery $refinery,
65 private readonly AccessManager $access,
66 private readonly HttpService $http,
67 private readonly ScheduleManager $schedule_manager,
68 private readonly int $ref_id,
69 ) {
70 }
71
72 public function getTableId(): string
73 {
74 return self::ID;
75 }
76
80 public function getComponents(URLBuilder $url_builder): array
81 {
82 return [
83 $this->ui_factory->table()->data($this, $this->lng->txt('book_schedules'), $this->getColumns())
84 ->withActions($this->getTableActions()->getEnabledActions(...$this->acquireParameters($url_builder)))
85 ->withRequest($this->http->getRequest())
86 ->withId($this->getTableId())
87 ];
88 }
89
90 public function getTotalRowCount(
91 mixed $additional_viewcontrol_data,
92 mixed $filter_data,
93 mixed $additional_parameters
94 ): ?int {
95 return count($this->loadRecords($filter_data));
96 }
97
98 public function getRows(
99 DataRowBuilder $row_builder,
100 array $visible_column_ids,
102 Order $order,
103 mixed $additional_viewcontrol_data,
104 mixed $filter_data,
105 mixed $additional_parameters
106 ): Generator {
107 $records = $this->limitRecords($range, $this->sortRecords($order, $this->loadRecords($filter_data)));
108
109 foreach ($records as $record) {
110 yield $this->getTableActions()->onDataRow(
111 $row_builder->buildDataRow(
112 (string) $record['booking_schedule_id'],
113 [
114 'title' => $record['title'] ?? '',
115 'is_used' => (bool) ($record['is_used'] ?? false),
116 ]
117 ),
118 $record
119 );
120 }
121 }
122
123 protected function loadRecords(mixed $filter_data): array
124 {
125 return $this->schedule_manager->getScheduleData();
126 }
127
128 protected function sortRecords(Order $order, array $records): array
129 {
130 $order_data = $order->get();
131 if ($order_data === []) {
132 return $records;
133 }
134
135 foreach ($order_data as $key => $value) {
136 $order_direction = $value === Order::DESC ? -1 : 1;
137 $callable = match ($key) {
138 'title' => static fn(array $a, array $b): int => strcmp($a['title'], $b['title']) * $order_direction,
139 'is_used' => static fn(array $a, array $b): int => (($a['is_used'] ?? false) <=> ($b['is_used'] ?? false)) * -$order_direction,
140 default => null,
141 };
142
143 if ($callable === null) {
144 continue;
145 }
146
147 usort($records, $callable);
148 }
149
150 return $records;
151 }
152
153 protected function limitRecords(Range $range, array $records): array
154 {
155 return array_slice($records, $range->getStart(), $range->getLength());
156 }
157
161 private function getColumns(): array
162 {
163 $column_factory = $this->ui_factory->table()->column();
164 $icon_factory = $this->ui_factory->symbol()->icon();
165 return [
166 'title' => $column_factory->text($this->lng->txt('title'))->withIsSortable(true),
167 'is_used' => $column_factory->boolean(
168 $this->lng->txt('book_is_used'),
169 $icon_factory->custom(
170 ilUtil::getImagePath('standard/icon_ok.svg'),
171 $this->lng->txt('yes')
172 ),
173 $icon_factory->custom(
174 ilUtil::getImagePath('standard/icon_not_ok.svg'),
175 $this->lng->txt('no')
176 )
177 )->withIsSortable(true),
178 ];
179 }
180
184 protected function acquireParameters(URLBuilder $url_builder): array
185 {
186 return $url_builder->acquireParameters(
187 [self::ID],
188 self::ROW_ID_PARAMETER,
189 self::ACTION_PARAMETER,
190 self::ACTION_TYPE_PARAMETER
191 );
192 }
193
194 protected function getTableActions(): TableActions
195 {
196 return (new ScheduleTableActionsFactory(
197 $this->ctrl,
198 $this->lng,
199 $this->tpl,
200 $this->ui_factory,
201 $this->ui_renderer,
202 $this->refinery,
203 $this->access,
204 $this->http,
205 $this->schedule_manager,
206 $this->ref_id,
207 ))->getTableActions();
208 }
209}
getTotalRowCount(mixed $additional_viewcontrol_data, mixed $filter_data, mixed $additional_parameters)
Mainly for the purpose of pagination-support, it is important to know about the total number of recor...
__construct(private readonly ilCtrlInterface $ctrl, private readonly ilLanguage $lng, private readonly ilGlobalTemplateInterface $tpl, private readonly UIFactory $ui_factory, private readonly UIRenderer $ui_renderer, private readonly Refinery $refinery, private readonly AccessManager $access, private readonly HttpService $http, private readonly ScheduleManager $schedule_manager, private readonly int $ref_id,)
getRows(DataRowBuilder $row_builder, array $visible_column_ids, Range $range, Order $order, mixed $additional_viewcontrol_data, mixed $filter_data, mixed $additional_parameters)
This is called by the table to retrieve rows; map data-records to rows using the $row_builder e....
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
Builds data types.
Definition: Factory.php:36
Both the subject and the direction need to be specified when expressing an order.
Definition: Order.php:29
A simple class to express a naive range of whole positive numbers.
Definition: Range.php:29
acquireParameters(array $namespace, string ... $names)
Definition: URLBuilder.php:138
language handling
Util class various functions, usage as namespace.
static getImagePath(string $image_name, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
return['3gp', '7z', 'ai', 'aif', 'aifc', 'aiff', 'au', 'arw', 'avi', 'backup', 'bak', 'bas', 'bpmn', 'bpmn2', 'bmp', 'bib', 'bibtex', 'bz', 'bz2', 'c', 'c++', 'cc', 'cct', 'cdf', 'cer', 'class', 'cls', 'conf', 'cpp', 'crt', 'crs', 'crw', 'cr2', 'css', 'cst', 'csv', 'cur', 'db', 'dcr', 'des', 'dng', 'doc', 'docx', 'dot', 'dotx', 'dtd', 'dvi', 'el', 'eps', 'epub', 'f', 'f77', 'f90', 'flv', 'for', 'g3', 'gif', 'gl', 'gan', 'ggb', 'gsd', 'gsm', 'gtar', 'gz', 'gzip', 'h', 'hpp', 'htm', 'html', 'htmls', 'ibooks', 'ico', 'ics', 'ini', 'ipynb', 'java', 'jbf', 'jpeg', 'jpg', 'js', 'jsf', 'jso', 'json', 'latex', 'lang', 'less', 'log', 'lsp', 'ltx', 'm1v', 'm2a', 'm2v', 'm3u', 'm4a', 'm4v', 'markdown', 'm', 'mat', 'md', 'mdl', 'mdown', 'mid', 'min', 'midi', 'mobi', 'mod', 'mov', 'movie', 'mp2', 'mp3', 'mp4', 'mpa', 'mpeg', 'mpg', 'mph', 'mpga', 'mpp', 'mpt', 'mpv', 'mpx', 'mv', 'mw', 'mv4', 'nb', 'nbp', 'nef', 'nif', 'niff', 'obj', 'obm', 'odt', 'ods', 'odp', 'odg', 'odf', 'oga', 'ogg', 'ogv', 'old', 'p', 'pas', 'pbm', 'pcl', 'pct', 'pcx', 'pdf', 'pgm', 'pic', 'pict', 'png', 'por', 'pov', 'project', 'properties', 'ppa', 'ppm', 'pps', 'ppsx', 'ppt', 'pptx', 'ppz', 'ps', 'psd', 'pwz', 'qt', 'qtc', 'qti', 'qtif', 'r', 'ra', 'ram', 'rar', 'rast', 'rda', 'rev', 'rexx', 'ris', 'rf', 'rgb', 'rm', 'rmd', 'rmi', 'rmm', 'rmp', 'rt', 'rtf', 'rtx', 'rv', 's', 's3m', 'sav', 'sbs', 'sec', 'sdml', 'sgm', 'sgml', 'smi', 'smil', 'srt', 'sps', 'spv', 'stl', 'svg', 'swa', 'swf', 'swz', 'tar', 'tex', 'texi', 'texinfo', 'text', 'tgz', 'tif', 'tiff', 'ttf', 'txt', 'tmp', 'uvproj', 'vdf', 'vimeo', 'viv', 'vivo', 'vrml', 'vsdx', 'vtt', 'wav', 'webm', 'wmv', 'wmx', 'wmz', 'woff', 'wwd', 'xhtml', 'xif', 'xls', 'xlsx', 'xmind', 'xml', 'xsl', 'xsd', 'zip']
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
A component is the most general form of an entity in the UI.
Definition: Component.php:28
A Column describes the form of presentation for a certain aspect of data, i.e.
Definition: Column.php:28
buildDataRow(string $id, array $record)
An entity that renders components to a string output.
Definition: Renderer.php:31
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static http()
Fetches the global http state from ILIAS.
readonly ilGlobalTemplateInterface $tpl
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
global $lng
Definition: privfeed.php:26