ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
class.ilCourseInfoFileTableGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21use ILIAS\Data\Factory as ilDataFactory;
22use ILIAS\DI\UIServices as ilUIServices;
23use ILIAS\HTTP\Services as ilHTTPServices;
24use ILIAS\Refinery\Factory as ilRefineryFactory;
25use ILIAS\UI\Component\Table\Data as ilDataTable;
27use ILIAS\UI\URLBuilderToken as ilURLBuilderToken;
28use JetBrains\PhpStorm\NoReturn;
29
31{
32 public const string TABLE_COL_FILENAME = 'filename';
33 public const string TABLE_COL_FILESIZE = 'filesize';
34 public const string TABLE_COL_FILETYPE = 'filetype';
35 protected const string ALL_OBJECTS = "ALL_OBJECTS";
36 protected const string TABLE_ACTION_CONFIRM_DELETE = 'confirm_delete';
37 protected const string TABLE_ACTION_DELETE = 'delete';
38 protected const string LNG_TABLE_COL_FILENAME = 'filename';
39 protected const string LNG_TABLE_COL_FILESIZE = 'filesize';
40 protected const string LNG_TABLE_COL_FILETYPE = 'filetype';
41 protected const string LNG_TABLE_ACTION_CONFIRM_DELETE = 'delete';
42 protected const string LNG_TABLE_TITLE = 'crs_info_download';
43 protected const string TABLE_ID = "crsfltbl";
44 protected const string ROW_ID = "row_ids";
45 protected const string TABLE_ACTION_ID = "table_action";
46
48 protected ilURLBuilderToken $action_parameter_token;
49 protected ilURLBuilderToken $row_id_token;
50 protected ilDataTable $table;
51
52 public function __construct(
53 protected ilCourseInfoFileTableDataRetrieval $data_retrieval,
54 protected ilLanguage $lng,
55 protected ilUIServices $ui_services,
56 protected ilHTTPServices $http_services,
57 protected ilRefineryFactory $refinery,
58 protected ilCtrl $ctrl,
59 protected ilDataFactory $data_factory
60 ) {
61 }
62
63 protected function getColumns(): array
64 {
65 return [
66 self::TABLE_COL_FILENAME => $this->ui_services->factory()->table()->column()->text(
67 $this->lng->txt(self::TABLE_COL_FILENAME)
68 ),
69 self::TABLE_COL_FILESIZE => $this->ui_services->factory()->table()->column()->number(
70 $this->lng->txt(self::TABLE_COL_FILESIZE)
71 ),
72 self::TABLE_COL_FILETYPE => $this->ui_services->factory()->table()->column()->text(
73 $this->lng->txt(self::TABLE_COL_FILETYPE)
74 )
75 ];
76 }
77
78 protected function getActions(): array
79 {
80 $this->url_builder = new URLBuilder($this->data_factory->uri($this->http_services->request()->getUri()->__toString()));
81 list($this->url_builder, $this->action_parameter_token, $this->row_id_token) =
82 $this->url_builder->acquireParameters(
83 ['datatable', self::TABLE_ID],
84 self::TABLE_ACTION_ID,
85 self::ROW_ID
86 );
87 return [
88 self::TABLE_ACTION_CONFIRM_DELETE => $this->ui_services->factory()->table()->action()->multi(
89 $this->lng->txt(self::LNG_TABLE_ACTION_CONFIRM_DELETE),
90 $this->url_builder->withParameter($this->action_parameter_token, self::TABLE_ACTION_CONFIRM_DELETE),
91 $this->row_id_token
92 )->withAsync(true)
93 ];
94 }
95
96 protected function initTable(): void
97 {
98 if (isset($this->table)) {
99 return;
100 }
101 $this->table = $this->ui_services->factory()->table()->data(
102 $this->data_retrieval,
103 $this->lng->txt(self::LNG_TABLE_TITLE),
104 $this->getColumns()
105 )
106 ->withId(self::TABLE_ID)
107 ->withActions($this->getActions())
108 ->withRequest($this->http_services->request());
109 }
110
111 protected function readIdsFromQuery(): array
112 {
113 $tokens = $this->http_services->wrapper()->query()->retrieve(
114 $this->row_id_token->getName(),
115 $this->refinery->custom()->transformation(fn($v) => $v)
116 );
117 return is_array($tokens) ? $tokens : [$tokens];
118 }
119
123 protected function delete(array $ids): void
124 {
125 $this->data_retrieval->deleteFilesByIds($ids);
126 $this->ui_services->mainTemplate()->setOnScreenMessage('success', $this->lng->txt('settings_saved'), true);
127 $this->ctrl->redirectByClass(ilObjCourseGUI::class, 'editInfo');
128 }
129
130 #[NoReturn] protected function showDeleteModal(array $ids): void
131 {
132 $items = [];
133 foreach ($ids as $id) {
134 $items[] = $this->ui_services->factory()->modal()->interruptiveItem()->standard(
135 $id . '',
136 $this->data_retrieval->getFileTitle((int) $id)
137 );
138 }
139 echo($this->ui_services->renderer()->renderAsync([
140 $this->ui_services->factory()->modal()->interruptive(
141 $this->lng->txt('confirm'),
142 $this->lng->txt('info_delete_sure'),
143 (string) $this->url_builder
144 ->withParameter(
145 $this->action_parameter_token,
146 self::TABLE_ACTION_DELETE
147 )->withParameter(
148 $this->row_id_token,
149 $ids
150 )->buildURI()
151 )->withAffectedItems($items)
152 ]));
153 exit();
154 }
155
156 public function handleCommands(): void
157 {
158 $this->initTable();
159 if (!$this->http_services->wrapper()->query()->has($this->action_parameter_token->getName())) {
160 return;
161 }
162 $action = $this->http_services->wrapper()->query()->retrieve(
163 $this->action_parameter_token->getName(),
164 $this->refinery->to()->string()
165 );
166 $tokens = $this->http_services->wrapper()->query()->retrieve(
167 $this->row_id_token->getName(),
168 $this->refinery->custom()->transformation(fn($v) => $v)
169 );
170 $all_entries = ($tokens[0] ?? "") === self::ALL_OBJECTS;
171 $ids = [];
172 if ($all_entries) {
173 $ids = $this->data_retrieval->getAllFileIds();
174 }
175 if (!$all_entries) {
176 $ids = $this->readIdsFromQuery();
177 }
178 if (is_null($ids[0]) || count($ids) === 0) {
179 $ids = [];
180 }
181 switch ($action) {
183 $this->showDeleteModal($ids);
184 break;
186 $this->delete($ids);
187 break;
188 }
189 }
190
191 public function getHTML(): string
192 {
193 $this->initTable();
194 return $this->ui_services->renderer()->render([$this->table]);
195 }
196}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Provides fluid interface to RBAC services.
Definition: UIServices.php:25
Builds data types.
Definition: Factory.php:36
Class Services.
Definition: Services.php:38
__construct(protected ilCourseInfoFileTableDataRetrieval $data_retrieval, protected ilLanguage $lng, protected ilUIServices $ui_services, protected ilHTTPServices $http_services, protected ilRefineryFactory $refinery, protected ilCtrl $ctrl, protected ilDataFactory $data_factory)
Class ilCtrl provides processing control methods.
language handling
exit
This describes a Data Table.
Definition: Data.php:33
global $lng
Definition: privfeed.php:31