ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
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 mixed $additional_viewcontrol_data,
164 mixed $filter_data,
165 mixed $additional_parameters
166 ): Generator {
167 foreach ($this->getItems($range, $order) as $idx => $record) {
168 $obj_id = (string) $record['obj_id'];
169 $language = $record['name'];
170 if (array_key_exists('status', $record) and $record['status'] !== '') {
171 $language .= ' (' . $this->lng->txt($record["status"]) . ')';
172 }
173 $to_language = $this->url_builder
174 ->withParameter($this->action_token, 'view')
175 ->withParameter($this->row_id_token, $obj_id)
176 ->withURI($this->getURIWithTargetClass(ilObjLanguageExtGUI::class, 'view'))
177 ->buildURI()->__toString();
178
179 $record['language'] = $this->ui_factory->link()->standard($language, $to_language)->withDisabled();
180
181 $record['status'] = $this->lng->txt($record['desc']);
182
183 $record['page_translation'] = false;
184 if ($this->ilSetting->get("lang_translate_" . $record["key"])) {
185 $record['page_translation'] = true;
186 }
187
188 $record['users'] = ilObjLanguage::countUsers($record["key"]);
189 if ($record["desc"] !== "not_installed") {
190 if ($this->access->checkAccess('write', '', $this->folder->getId())) {
191 $record['language'] = $record['language']->withDisabled(false);
192 }
193 $record['last_refresh'] = ilDatePresentation::formatDate(new ilDateTime($record["last_update"], IL_CAL_DATETIME, 'UTC'));
194
195 $last_change = ilObjLanguage::_getLastLocalChange($record["key"]);
196 $record['last_change'] = ilDatePresentation::formatDate(new ilDateTime($last_change, IL_CAL_DATETIME, 'UTC'));
197 }
198
199 yield $row_builder->buildDataRow($obj_id, $record)
200 ->withDisabledAction('setSystemLanguage', ($record['desc'] === 'not_installed') || ($record['key'] === $this->lng->getDefaultLanguage()))
201 ->withDisabledAction('setUserLanguage', ($record['desc'] === 'not_installed') || ($record['key'] === $this->lng->getUserLanguage()))
202 ->withDisabledAction('refresh', ($record['desc'] === 'not_installed'))
203 ->withDisabledAction('uninstall', ($record['desc'] === 'not_installed'))
204 ->withDisabledAction('lang_uninstall_changes', ($record['desc'] === 'not_installed'))
205 ->withDisabledAction('install', ($record['desc'] !== 'not_installed'))
206 ->withDisabledAction('install_local', ($record['desc'] !== 'not_installed'));
207 }
208 }
209
210 protected function getURIWithTargetClass(string $target_gui, string $command): URI
211 {
212 return new URI(
213 ILIAS_HTTP_PATH . "/" . $this->ctrl->getLinkTargetByClass(
214 $target_gui,
215 $command
216 )
217 );
218 }
219
220 public function getTotalRowCount(
221 mixed $additional_viewcontrol_data,
222 mixed $filter_data,
223 mixed $additional_parameters
224 ): ?int {
225 return 1;
226 }
227}
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, mixed $additional_viewcontrol_data, mixed $filter_data, mixed $additional_parameters)
getItems(?Range $range=null, ?Order $order=null)
Get language data.
buildAction(string $act, string $type, bool $async=false)
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(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
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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