ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
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;
32
34{
35 public const string ACTIVATE = 'activate';
36 public const string DEACTIVATE = 'deactivate';
37 public const string EDIT = 'edit';
38 public const string PREVIEW = 'preview';
39
40 private ServerRequestInterface $request;
41 private Data\Factory $data_factory;
45 private ?array $records = null;
46
47 public function __construct(
48 private readonly ilCtrlInterface $ctrl,
49 private readonly ilLanguage $lng,
50 \ILIAS\HTTP\Services $http,
51 private readonly \ILIAS\UI\Factory $ui_factory,
52 private readonly \ILIAS\UI\Renderer $ui_renderer,
53 private readonly AuthPageEditorContext $context,
54 private readonly bool $has_write_access
55 ) {
56 $this->request = $http->request();
57 $this->data_factory = new Data\Factory();
58 }
59
60 public function getComponent(): UI\Component\Table\Data
61 {
62 $columns = $this->getColumns();
63 $actions = $this->getActions();
64
65 return $this->ui_factory
66 ->table()
67 ->data($this, $this->lng->txt($this->context->pageLanguageIdentifier(true)), $columns)
68 ->withId(str_replace('\\', '', self::class) . '_' . $this->context->value)
69 ->withOrder(new \ILIAS\Data\Order('language', \ILIAS\Data\Order::ASC))
70 ->withRange(new Range(0, 100))
71 ->withActions($actions)
72 ->withRequest($this->request);
73 }
74
78 private function getColumns(): array
79 {
80 return [
81 'language' => $this->ui_factory
82 ->table()
83 ->column()
84 ->text($this->lng->txt($this->context->pageLanguageIdentifier()))
85 ->withIsSortable(true),
86 'status_icon' => $this->ui_factory
87 ->table()
88 ->column()
89 ->statusIcon($this->lng->txt('active'))
90 ->withIsSortable(true)
91 ];
92 }
93
97 protected function getActions(): array
98 {
99 $query_params_namespace = ['authpage', 'languages'];
100
101 $overview_uri = $this->data_factory->uri(
102 ILIAS_HTTP_PATH . '/' . $this->ctrl->getLinkTargetByClass(
103 \ilAuthPageEditorGUI::class,
105 )
106 );
107
108 $overview_url_builder = new UI\URLBuilder($overview_uri);
109 [
110 $overview_url_builder,
111 $overview_action_parameter,
112 $overview_row_id
113 ] = $overview_url_builder->acquireParameters(
114 $query_params_namespace,
115 'action',
116 'key'
117 );
118
119 $actions = [];
120 $actions[self::EDIT] = $this->ui_factory->table()->action()->single(
121 $this->lng->txt($this->has_write_access ? 'edit' : 'preview'),
122 $overview_url_builder->withParameter($overview_action_parameter, $this->has_write_access ? self::EDIT : self::PREVIEW),
123 $overview_row_id
124 );
125
126 if ($this->has_write_access) {
127 $actions[self::ACTIVATE] = $this->ui_factory->table()->action()->standard(
128 $this->lng->txt('page_design_activate'),
129 $overview_url_builder->withParameter($overview_action_parameter, self::ACTIVATE),
130 $overview_row_id
131 );
132
133 $actions[self::DEACTIVATE] = $this->ui_factory->table()->action()->standard(
134 $this->lng->txt('page_design_deactivate'),
135 $overview_url_builder->withParameter($overview_action_parameter, self::DEACTIVATE),
136 $overview_row_id
137 );
138 }
139
140 return $actions;
141 }
142
143 private function initRecords(): void
144 {
145 if ($this->records === null) {
146 $this->records = [];
147 $i = 0;
148 $entries = $this->lng->getInstalledLanguages();
149 foreach ($entries as $langkey) {
150 $this->records[$i]['key'] = $langkey;
151 $this->records[$i]['id'] = ilLanguage::lookupId($langkey);
152 $status = ilAuthPageEditorSettings::getInstance($this->context)->isIliasEditorEnabled(
153 $langkey
154 );
155
156 $this->records[$i]['status'] = $status;
157 $this->records[$i]['status_icon'] = $this->getStatusIcon($status);
158 $this->records[$i]['language'] = $this->lng->txt('meta_l_' . $langkey);
159
160 ++$i;
161 }
162 }
163 }
164
165 private function getStatusIcon(bool $status): \ILIAS\UI\Component\Symbol\Icon\Icon
166 {
167 if ($status) {
168 return $this->ui_factory->symbol()->icon()->custom(
169 \ilUtil::getImagePath('standard/icon_ok.svg'),
170 $this->lng->txt('active')
171 );
172 }
173
174 return $this->ui_factory->symbol()->icon()->custom(
175 \ilUtil::getImagePath('standard/icon_not_ok.svg'),
176 $this->lng->txt('inactive')
177 );
178 }
179
180 public function getRows(
181 UI\Component\Table\DataRowBuilder $row_builder,
182 array $visible_column_ids,
184 Data\Order $order,
185 mixed $additional_viewcontrol_data,
186 mixed $filter_data,
187 mixed $additional_parameters
188 ): \Generator {
189 $records = $this->getRecords($range, $order);
190
191 foreach ($records as $record) {
192 $row_id = (string) $record['key'];
193 $deactivate_action = (bool) $record['status'] === true ? self::ACTIVATE : self::DEACTIVATE;
194 yield $row_builder->buildDataRow($row_id, $record)->withDisabledAction($deactivate_action);
195 }
196 }
197
198 public function getTotalRowCount(
199 mixed $additional_viewcontrol_data,
200 mixed $filter_data,
201 mixed $additional_parameters
202 ): ?int {
203 $this->initRecords();
204
205 return \count($this->records);
206 }
207
211 private function sortedRecords(Data\Order $order): array
212 {
213 $records = $this->records;
214 [$order_field, $order_direction] = $order->join([], fn($ret, $key, $value) => [$key, $value]);
215
216 if ($order_field === 'status_icon') {
217 $order_field = 'status';
218 }
219
220 return ilArrayUtil::stableSortArray($records, $order_field, strtolower($order_direction));
221 }
222
226 private function getRecords(Data\Range $range, Data\Order $order): array
227 {
228 $this->initRecords();
229
230 $records = $this->sortedRecords($order);
231
232 return $this->limitRecords($records, $range);
233 }
234
239 private function limitRecords(array $records, Data\Range $range): array
240 {
241 return \array_slice($records, $range->getStart(), $range->getLength());
242 }
243}
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
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, \ILIAS\HTTP\Services $http, private readonly \ILIAS\UI\Factory $ui_factory, private readonly \ILIAS\UI\Renderer $ui_renderer, private readonly AuthPageEditorContext $context, private readonly bool $has_write_access)
getRows(UI\Component\Table\DataRowBuilder $row_builder, array $visible_column_ids, Data\Range $range, Data\Order $order, mixed $additional_viewcontrol_data, mixed $filter_data, mixed $additional_parameters)
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...
@ilCtrl_isCalledBy ilAuthPageEditorGUI: ilObjAuthSettingsGUI @ilCtrl_Calls ilAuthPageEditorGUI: ilLog...
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