ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilLanguageFolderTable.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
28
38{
43 protected ilLanguage $lng;
48
49 public function __construct(
50 ilObjLanguageFolder $a_folder,
54 ) {
55 global $DIC;
56 $this->ui_factory = $DIC['ui.factory'];
57 $this->lng = $DIC->language();
58 $this->folder = $a_folder;
59 $this->url_builder = $url_builder;
60 $this->action_token = $action_token;
61 $this->row_id_token = $row_id_token;
62 $this->ctrl = $DIC->ctrl();
63 $this->ilSetting = $DIC->settings();
64 $this->access = $DIC->access();
65 }
66
67 public function getTable(): DataTable\Data
68 {
69 $table = $this->ui_factory->table()->data(
70 $this,
71 '',
72 $this->getColums(),
73 );
74 if ($this->access->checkAccess('write', '', $this->folder->getId())) {
75 $table = $table->withActions($this->getActions());
76 }
77 return $table;
78 }
79
80 protected function getColums(): array
81 {
83 $icon_yes = $f->symbol()->icon()->custom(
84 'assets/images/standard/icon_checked.svg',
85 $this->lng->txt('yes'),
86 'small'
87 );
88 $icon_no = $f->symbol()->icon()->custom(
89 'assets/images/standard/icon_unchecked.svg',
90 $this->lng->txt('no'),
91 'small'
92 );
93 return [
94 'language' => $f->table()->column()->link($this->lng->txt("language"))->withIsSortable(false),
95 'status' => $f->table()->column()->text($this->lng->txt("status"))->withIsSortable(false),
96 'users' => $f->table()->column()->text($this->lng->txt("users"))->withIsSortable(false),
97 'page_translation' => $f->table()->column()->boolean($this->lng->txt("language_translation"), $icon_yes, $icon_no)->withIsSortable(false),
98 'last_refresh' => $f->table()->column()->text($this->lng->txt("last_refresh"))->withIsSortable(false),
99 'last_change' => $f->table()->column()->text($this->lng->txt("last_change"))->withIsSortable(false)
100 ];
101 }
102
103 protected function getActions(): array
104 {
105 $actions = array_merge(
106 $this->buildAction('refresh', 'standard', true),
107 $this->buildAction('install', 'standard'),
108 $this->buildAction('install_local', 'standard'),
109 $this->buildAction('uninstall', 'standard', true),
110 $this->buildAction('lang_uninstall_changes', 'standard', true),
111 $this->buildAction('setSystemLanguage', 'single'),
112 $this->buildAction('setUserLanguage', 'single'),
113 );
114 return $actions;
115 }
116
117 protected function buildAction(string $act, string $type, bool $async = false): array
118 {
119 $action = $this->ui_factory->table()->action()
120 ->$type(
121 $this->lng->txt($act),
122 $this->url_builder->withParameter($this->action_token, $act),
123 $this->row_id_token
124 );
125 if ($async) {
126 $action = $action->withAsync(true);
127 }
128
129 return [$act => $action];
130 }
131
135 public function getItems(?Range $range = null, ?Order $order = null): array
136 {
137 $languages = $this->folder->getLanguages();
138 $data = [];
139 $names = [];
140 $installed = [];
141
142 foreach ($languages as $k => $l) {
143 $data[] = array_merge($l, ["key" => $k]);
144 $names[] = $l['name'];
145 $installed[] = str_starts_with($l["desc"], 'installed') ? 1 : 2;
146 }
147
148 // sort alphabetically but show installed languages first
149 array_multisort($installed, SORT_ASC, $names, SORT_ASC, $data);
150
151 if ($range) {
152 $data = array_slice($data, $range->getStart(), $range->getLength());
153 }
154
155 return $data;
156 }
157
158 public function getRows(
159 \ILIAS\UI\Component\Table\DataRowBuilder $row_builder,
160 array $visible_column_ids,
162 Order $order,
163 ?array $filter_data,
164 ?array $additional_parameters
165 ): Generator {
166 foreach ($this->getItems($range, $order) as $idx => $record) {
167 $obj_id = (string) $record['obj_id'];
168 $language = $record['name'];
169 if ($record["status"]) {
170 $language .= ' (' . $this->lng->txt($record["status"]) . ')';
171 }
172 $to_language = $this->url_builder
173 ->withParameter($this->action_token, 'view')
174 ->withParameter($this->row_id_token, $obj_id)
175 ->withURI($this->getURIWithTargetClass(ilObjLanguageExtGUI::class, 'view'))
176 ->buildURI()->__toString();
177
178 $record['language'] = $this->ui_factory->link()->standard($language, $to_language)->withDisabled();
179
180 $record['status'] = $this->lng->txt($record['desc']);
181
182 $record['page_translation'] = false;
183 if ($this->ilSetting->get("lang_translate_" . $record["key"])) {
184 $record['page_translation'] = true;
185 }
186
187 $record['users'] = ilObjLanguage::countUsers($record["key"]);
188 if ($record["desc"] !== "not_installed") {
189 if ($this->access->checkAccess('write', '', $this->folder->getId())) {
190 $record['language'] = $record['language']->withDisabled(false);
191 }
192 $record['last_refresh'] = ilDatePresentation::formatDate(new ilDateTime($record["last_update"], IL_CAL_DATETIME, 'UTC'));
193
194 $last_change = ilObjLanguage::_getLastLocalChange($record["key"]);
195 $record['last_change'] = ilDatePresentation::formatDate(new ilDateTime($last_change, IL_CAL_DATETIME, 'UTC'));
196 }
197
198 yield $row_builder->buildDataRow($obj_id, $record)
199 ->withDisabledAction('setSystemLanguage', ($record['desc'] === 'not_installed') || ($record['key'] === $this->lng->getDefaultLanguage()))
200 ->withDisabledAction('setUserLanguage', ($record['desc'] === 'not_installed') || ($record['key'] === $this->lng->getUserLanguage()))
201 ->withDisabledAction('refresh', ($record['desc'] === 'not_installed'))
202 ->withDisabledAction('uninstall', ($record['desc'] === 'not_installed'))
203 ->withDisabledAction('lang_uninstall_changes', ($record['desc'] === 'not_installed'))
204 ->withDisabledAction('install', ($record['desc'] !== 'not_installed'))
205 ->withDisabledAction('install_local', ($record['desc'] !== 'not_installed'));
206 }
207 }
208
209 protected function getURIWithTargetClass(string $target_gui, string $command): URI
210 {
211 return new URI(
212 ILIAS_HTTP_PATH . "/" . $this->ctrl->getLinkTargetByClass(
213 $target_gui,
214 $command
215 )
216 );
217 }
218
219 public function getTotalRowCount(?array $filter_data, ?array $additional_parameters): ?int
220 {
221 return 1;
222 }
223}
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
The scope of this class is split ilias-conform URI's into components.
Definition: URI.php:35
const IL_CAL_DATETIME
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false, ?ilObjUser $user=null,)
@classDescription Date and time handling
getRows(\ILIAS\UI\Component\Table\DataRowBuilder $row_builder, array $visible_column_ids, Range $range, Order $order, ?array $filter_data, ?array $additional_parameters)
getItems(?Range $range=null, ?Order $order=null)
Get language data.
buildAction(string $act, string $type, bool $async=false)
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...
__construct(ilObjLanguageFolder $a_folder, URLBuilder $url_builder, URLBuilderToken $action_token, URLBuilderToken $row_id_token)
getURIWithTargetClass(string $target_gui, string $command)
language handling
Class ilObjLanguageFolder contains all function to manage language support for ILIAS3 install,...
static _getLastLocalChange(string $a_key)
get the date of the last local change $a_key language key Return change_date "yyyy-mm-dd hh:mm:ss"
static countUsers(string $a_lang)
Count number of users that use a language.
ILIAS Setting Class.
get(string $a_keyword, ?string $a_default_value=null)
get setting
Interface ilAccessHandler This interface combines all available interfaces which can be called via gl...
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 $DIC
Definition: shib_login.php:26