ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
AuthPageLanguagesOverviewTable.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use ILIAS\Data;
24use ILIAS\UI;
25use ilArrayUtil;
26use Psr\Http\Message\ServerRequestInterface;
27use ilLanguage;
30
32{
33 public const string ACTIVATE = 'activate';
34 public const string DEACTIVATE = 'deactivate';
35 public const string EDIT = 'edit';
36
37 private ServerRequestInterface $request;
38 private Data\Factory $data_factory;
42 private ?array $records = null;
43
44 public function __construct(
45 private readonly ilCtrlInterface $ctrl,
46 private readonly ilLanguage $lng,
47 \ILIAS\HTTP\Services $http,
48 private readonly \ILIAS\UI\Factory $ui_factory,
49 private readonly \ILIAS\UI\Renderer $ui_renderer,
50 private readonly AuthPageEditorContext $context
51 ) {
52 $this->request = $http->request();
53 $this->data_factory = new Data\Factory();
54 }
55
56 public function getComponent(): UI\Component\Table\Data
57 {
58 $columns = $this->getColumns();
59 $actions = $this->getActions();
60
61 return $this->ui_factory
62 ->table()
63 ->data($this, $this->lng->txt($this->context->pageLanguageIdentifier(true)), $columns)
64 ->withId(self::class . '_' . $this->context->value)
65 ->withOrder(new \ILIAS\Data\Order('language', \ILIAS\Data\Order::ASC))
66 ->withActions($actions)
67 ->withRequest($this->request);
68 }
69
73 private function getColumns(): array
74 {
75 return [
76 'language' => $this->ui_factory
77 ->table()
78 ->column()
79 ->text($this->lng->txt($this->context->pageLanguageIdentifier()))
80 ->withIsSortable(true),
81 'status_icon' => $this->ui_factory
82 ->table()
83 ->column()
84 ->statusIcon($this->lng->txt('active'))
85 ->withIsSortable(true)
86 ];
87 }
88
92 protected function getActions(): array
93 {
94 $query_params_namespace = ['authpage', 'languages'];
95
96 $overview_uri = $this->data_factory->uri(
97 ILIAS_HTTP_PATH . '/' . $this->ctrl->getLinkTargetByClass(
98 \ilAuthPageEditorGUI::class,
100 )
101 );
102
103 $overview_url_builder = new UI\URLBuilder($overview_uri);
104 [
105 $overview_url_builder,
106 $overview_action_parameter,
107 $overview_row_id
108 ] = $overview_url_builder->acquireParameters(
109 $query_params_namespace,
110 'action',
111 'key'
112 );
113
114 return [
115 self::EDIT => $this->ui_factory->table()->action()->single(
116 $this->lng->txt('edit'),
117 $overview_url_builder->withParameter($overview_action_parameter, self::EDIT),
118 $overview_row_id
119 ),
120 self::ACTIVATE => $this->ui_factory->table()->action()->standard(
121 $this->lng->txt('page_design_activate'),
122 $overview_url_builder->withParameter($overview_action_parameter, self::ACTIVATE),
123 $overview_row_id
124 ),
125 self::DEACTIVATE => $this->ui_factory->table()->action()->standard(
126 $this->lng->txt('page_design_deactivate'),
127 $overview_url_builder->withParameter($overview_action_parameter, self::DEACTIVATE),
128 $overview_row_id
129 )
130 ];
131 }
132
133 private function initRecords(): void
134 {
135 if ($this->records === null) {
136 $this->records = [];
137 $i = 0;
138 $entries = $this->lng->getInstalledLanguages();
139 foreach ($entries as $langkey) {
140 $this->records[$i]['key'] = $langkey;
141 $this->records[$i]['id'] = ilLanguage::lookupId($langkey);
142 $status = ilAuthPageEditorSettings::getInstance($this->context)->isIliasEditorEnabled(
143 $langkey
144 );
145
146 $this->records[$i]['status'] = $status;
147 $this->records[$i]['status_icon'] = $this->getStatusIcon($status);
148 $this->records[$i]['language'] = $this->lng->txt('meta_l_' . $langkey);
149
150 ++$i;
151 }
152 }
153 }
154
155 private function getStatusIcon(bool $status): \ILIAS\UI\Component\Symbol\Icon\Icon
156 {
157 if ($status) {
158 return $this->ui_factory->symbol()->icon()->custom(
159 \ilUtil::getImagePath('standard/icon_ok.svg'),
160 $this->lng->txt('active')
161 );
162 }
163
164 return $this->ui_factory->symbol()->icon()->custom(
165 \ilUtil::getImagePath('standard/icon_not_ok.svg'),
166 $this->lng->txt('inactive')
167 );
168 }
169
170 public function getRows(
171 UI\Component\Table\DataRowBuilder $row_builder,
172 array $visible_column_ids,
174 Data\Order $order,
175 ?array $filter_data,
176 ?array $additional_parameters
177 ): \Generator {
178 $records = $this->getRecords($range, $order);
179
180 foreach ($records as $record) {
181 $row_id = (string) $record['key'];
182 $deactivate_action = (bool) $record['status'] === true ? self::ACTIVATE : self::DEACTIVATE;
183 yield $row_builder->buildDataRow($row_id, $record)->withDisabledAction($deactivate_action);
184 }
185 }
186
187 public function getTotalRowCount(
188 ?array $filter_data,
189 ?array $additional_parameters
190 ): ?int {
191 $this->initRecords();
192
193 return \count($this->records);
194 }
195
199 private function sortedRecords(Data\Order $order): array
200 {
201 $records = $this->records;
202 [$order_field, $order_direction] = $order->join([], fn($ret, $key, $value) => [$key, $value]);
203
204 if ($order_field === 'status_icon') {
205 $order_field = 'status';
206 }
207
208 return ilArrayUtil::stableSortArray($records, $order_field, strtolower($order_direction));
209 }
210
214 private function getRecords(Data\Range $range, Data\Order $order): array
215 {
216 $this->initRecords();
217
218 $records = $this->sortedRecords($order);
219
220 return $this->limitRecords($records, $range);
221 }
222
227 private function limitRecords(array $records, Data\Range $range): array
228 {
229 return \array_slice($records, $range->getStart(), $range->getLength());
230 }
231}
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
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
Definition: UI.php:24
__construct(private readonly ilCtrlInterface $ctrl, private readonly ilLanguage $lng, \ILIAS\HTTP\Services $http, private readonly \ILIAS\UI\Factory $ui_factory, private readonly \ILIAS\UI\Renderer $ui_renderer, private readonly AuthPageEditorContext $context)
getRows(UI\Component\Table\DataRowBuilder $row_builder, array $visible_column_ids, Data\Range $range, Data\Order $order, ?array $filter_data, ?array $additional_parameters)
getTotalRowCount(?array $filter_data, ?array $additional_parameters)
Mainly for the purpose of pagination-support, it is important to know about the total number of recor...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static stableSortArray(array $array, string $a_array_sortby, string $a_array_sortorder="asc", bool $a_numeric=false)
Sort an aray using a stable sort algorithm, which preveserves the sequence of array elements which ha...
final const string LANGUAGE_TABLE_ACTIONS_COMMAND
static getInstance(AuthPageEditorContext $context)
language handling
static lookupId(string $a_lang_key)
Lookup obj_id of language.
static getImagePath(string $image_name, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
$http
Definition: deliver.php:30
This describes a symbol.
Definition: Symbol.php:30
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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
global $lng
Definition: privfeed.php:31
$context
Definition: webdav.php:31