ILIAS  trunk Revision v12.0_alpha-1540-g00f839d5fa1
DocumentTableGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\WebDAV\Mount;
22
26use Psr\Http\Message\RequestInterface;
27use ilTable2GUI;
29use ilDateTime;
31
33{
34 protected int $factor = 10;
35 protected int $i = 1;
36 protected int $num_rendered_criteria = 0;
37 protected array $optional_columns;
39
41 protected array $ui_components = [];
42
43 protected ?TableDataProvider $provider = null;
44
45 public function __construct(
47 protected UriBuilder $webdav_uri_builder,
48 string $command,
49 protected Factory $ui_factory,
50 protected Renderer $ui_renderer,
51 protected RequestInterface $request,
52 protected bool $is_editable = false
53 ) {
54 $this->setId('mount_instructions_documents');
55 $this->setFormName('mount_instructions_documents');
56
57 parent::__construct($parent_obj, $command);
58
59 $columns = $this->getColumnDefinition();
60 $this->optional_columns = $this->getSelectableColumns();
61 $this->visible_optional_columns = $this->getSelectedColumns();
62
63 foreach ($columns as $index => $column) {
64 if ($this->isColumnVisible($index)) {
65 $this->addColumn(
66 $column['txt'],
67 isset($column['sortable']) && $column['sortable'] ? $column['field'] : '',
68 $column['width'] ?? '',
69 isset($column['is_checkbox']) && (bool) $column['is_checkbox']
70 );
71 }
72 }
73
74 $this->setTitle($this->lng->txt('webdav_tbl_docs_title'));
75 $this->setFormAction($this->ctrl->getFormAction($this->getParentObject(), $command));
76
77 $this->setDefaultOrderDirection('ASC');
78 $this->setDefaultOrderField('sorting');
79 $this->setExternalSorting(true);
80 $this->setExternalSegmentation(true);
81 $this->setLimit(PHP_INT_MAX);
82
83 $this->setRowTemplate('tpl.webdav_documents_row.html', 'components/ILIAS/WebDAV');
84
85 if ($this->is_editable) {
86 $this->addCommandButton('saveDocumentSorting', $this->lng->txt('sorting_save'));
87 }
88
90 }
91
93 {
94 $this->provider = $provider;
95 }
96
97 public function getProvider(): ?TableDataProvider
98 {
99 return $this->provider;
100 }
101
102 #[\Override]
103 public function getSelectableColumns(): array
104 {
105 $optional_columns = array_filter(
106 $this->getColumnDefinition(),
107 static fn(array $column): bool => isset($column['optional']) && $column['optional']
108 );
109
110 $columns = [];
111 foreach ($optional_columns as $column) {
112 $columns[$column['field']] = $column;
113 }
114
115 return $columns;
116 }
117
118 protected function isColumnVisible(int $index): bool
119 {
120 $column_definition = $this->getColumnDefinition();
121 if (array_key_exists($index, $column_definition)) {
122 $column = $column_definition[$index];
123 if (isset($column['optional']) && !$column['optional']) {
124 return true;
125 }
126
127 if (
128 is_array($this->visible_optional_columns) &&
129 array_key_exists($column['field'], $this->visible_optional_columns)
130 ) {
131 return true;
132 }
133 }
134
135 return false;
136 }
137
138 #[\Override]
139 final protected function fillRow(array $row): void
140 {
141 foreach ($this->getColumnDefinition() as $index => $column) {
142 if (!$this->isColumnVisible($index)) {
143 continue;
144 }
145
146 $this->tpl->setCurrentBlock('column');
147 $value = $this->formatCellValue($column['field'], $row);
148 if ($value === '') {
149 $this->tpl->touchBlock('column');
150 } else {
151 $this->tpl->setVariable('COLUMN_VALUE', $value);
152 }
153
154 $this->tpl->parseCurrentBlock();
155 }
156 }
157
158 protected function getColumnDefinition(): array
159 {
160 $i = 0;
161
162 $columns = [];
163
164 $columns[++$i] = [
165 'field' => 'sorting',
166 'txt' => $this->lng->txt('meta_order', 'meta'),
167 'default' => true,
168 'optional' => false,
169 'sortable' => false,
170 'width' => '5%',
171 ];
172
173 $columns[++$i] = [
174 'field' => 'title',
175 'txt' => $this->lng->txt('webdav_tbl_docs_head_title'),
176 'default' => true,
177 'optional' => false,
178 'sortable' => false,
179 'width' => '25%',
180 ];
181
182 $columns[++$i] = [
183 'field' => 'creation_ts',
184 'txt' => $this->lng->txt('created'),
185 'default' => true,
186 'optional' => true,
187 'sortable' => false,
188 ];
189
190 $columns[++$i] = [
191 'field' => 'modification_ts',
192 'txt' => $this->lng->txt('last_change'),
193 'default' => true,
194 'optional' => true,
195 'sortable' => false,
196 ];
197
198 $columns[++$i] = [
199 'field' => 'language',
200 'txt' => $this->lng->txt('language'),
201 'default' => true,
202 'optional' => false,
203 'sortable' => false,
204 ];
205
206 if ($this->is_editable) {
207 $columns[++$i] = [
208 'field' => 'actions',
209 'txt' => $this->lng->txt('actions'),
210 'default' => true,
211 'optional' => false,
212 'sortable' => false,
213 'width' => '10%',
214 ];
215 }
216
217 return $columns;
218 }
219
220 public function populate(): void
221 {
222 if ($this->getExternalSegmentation() && $this->getExternalSorting()) {
224 } elseif (!$this->getExternalSegmentation() && $this->getExternalSorting()) {
225 $this->determineOffsetAndOrder(true);
226 }
227
228 $params = [];
229 if ($this->getExternalSegmentation()) {
230 $params['limit'] = $this->getLimit();
231 $params['offset'] = $this->getOffset();
232 }
233 if ($this->getExternalSorting()) {
234 $params['order_field'] = $this->getOrderField();
235 $params['order_direction'] = $this->getOrderDirection();
236 }
237
239 $data = $this->getProvider()->getList();
240
241 if (!count($data['items']) && $this->getOffset() > 0 && $this->getExternalSegmentation()) {
242 $this->resetOffset();
243 if ($this->getExternalSegmentation()) {
244 $params['limit'] = $this->getLimit();
245 $params['offset'] = $this->getOffset();
246 }
247 $data = $this->getProvider()->getList();
248 }
249
250 $this->preProcessData($data);
251
252 $this->setData($data['items']);
253 if ($this->getExternalSegmentation()) {
254 $this->setMaxCount($data['cnt']);
255 }
256 }
257
258 protected function preProcessData(array &$data): void
259 {
260 foreach ($data['items'] as $key => $document) {
261 $data['items'][$key] = [
262 'id' => $document->getId(),
263 'title' => $document->getTitle(),
264 'creation_ts' => $document->getCreationTs(),
265 'modification_ts' => $document->getModificationTs(),
266 'raw_text' => $document->getUploadedInstructions(),
267 'processed_text' => $document->getProcessedInstructions(),
268 'language' => $document->getLanguage(),
269 ];
270 }
271 }
272
273 protected function formatCellValue(string $column, array $row): string
274 {
275 $function = 'format' . ucfirst($column);
276 if (method_exists($this, $function)) {
277 return $this->{$function}($column, $row);
278 }
279 if (in_array($column, ['creation_ts', 'modification_ts'], true)) {
281 }
282
283 return trim((string) $row[$column]);
284 }
285
286 protected function formatActions(string $column, array $row): string
287 {
288 if (!$this->is_editable) {
289 return '';
290 }
291
292 $this->ctrl->setParameter($this->getParentObject(), 'document_id', $row['id']);
293
294 $edit_btn = $this->ui_factory
295 ->button()
296 ->shy(
297 $this->lng->txt('edit'),
298 $this->ctrl->getLinkTarget($this->getParentObject(), 'showEditDocumentForm')
299 );
300
301 $delete_modal = $this->ui_factory
302 ->modal()
303 ->interruptive(
304 $this->lng->txt('webdav_doc_delete'),
305 $this->lng->txt('webdav_sure_delete_documents_s') . ' ' . $row['title'],
306 $this->ctrl->getFormAction($this->getParentObject(), 'deleteDocument')
307 );
308
309 $delete_btn = $this->ui_factory
310 ->button()
311 ->shy($this->lng->txt('delete'), '#')
312 ->withOnClick($delete_modal->getShowSignal());
313
314 $this->ui_components[] = $delete_modal;
315
316 $this->ctrl->setParameter($this->getParentObject(), 'document_id', null);
317
318 $drop_down = $this->ui_factory
319 ->dropdown()
320 ->standard([$edit_btn, $delete_btn])
321 ->withLabel($this->lng->txt('actions'));
322
323 return $this->ui_renderer->render($drop_down);
324 }
325
326 protected function formatTitle(string $column, array $row): string
327 {
328 if ($row['processed_text'] === null) {
329 $row['processed_text'] = '';
330 }
331
332 $url = $this->webdav_uri_builder->getUriToMountInstructionModalByLanguage($row['language']);
333 $title_link = $this->ui_factory
334 ->button()
335 ->shy($row[$column], '#')
336 ->withAdditionalOnLoadCode(fn($id): string => "$('#$id').click(function(){ triggerWebDAVModal('$url');});");
337
338 return $this->ui_renderer->render([$title_link]);
339 }
340
341 protected function formatSorting(string $column, array $row): string
342 {
343 $value = (string) (($this->i++) * $this->factor);
344 if (!$this->is_editable) {
345 return $value;
346 }
347
348 $sorting_field = new ilNumberInputGUI('', 'sorting[' . $row['id'] . ']');
349 $sorting_field->setValue($value);
350 $sorting_field->setMaxLength(4);
351 $sorting_field->setSize(2);
352
353 return $sorting_field->render();
354 }
355
356 #[\Override]
357 public function getHTML(): string
358 {
359 return parent::getHTML() . $this->ui_renderer->render($this->ui_components);
360 }
361}
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
getSelectableColumns()
Get selectable columns.
formatActions(string $column, array $row)
formatSorting(string $column, array $row)
setProvider(TableDataProvider $provider)
fillRow(array $row)
Standard Version of Fill Row.
__construct(UploadGUI $parent_obj, protected UriBuilder $webdav_uri_builder, string $command, protected Factory $ui_factory, protected Renderer $ui_renderer, protected RequestInterface $request, protected bool $is_editable=false)
formatTitle(string $column, array $row)
formatCellValue(string $column, array $row)
static maybeRenderWebDAVModalInGlobalTpl()
Definition: ModalGUI.php:64
@ilCtrl_isCalledBy ILIAS\WebDAV\Mount\UploadGUI: ilObjWebDAVGUI
Definition: UploadGUI.php:43
const IL_CAL_DATETIME
Class for date presentation.
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
This class represents a number property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setLimit(int $a_limit=0, int $a_default_limit=0)
set max.
determineOffsetAndOrder(bool $a_omit_offset=false)
setTitle(string $a_title, string $a_icon="", string $a_icon_alt="")
setExternalSegmentation(bool $a_val)
addCommandButton(string $a_cmd, string $a_text, string $a_onclick='', string $a_id="", string $a_class="")
setFormName(string $a_name="")
setFormAction(string $a_form_action, bool $a_multipart=false)
resetOffset(bool $a_in_determination=false)
addColumn(string $a_text, string $a_sort_field="", string $a_width="", bool $a_is_checkbox_action_column=false, string $a_class="", string $a_tooltip="", bool $a_tooltip_with_html=false)
setDefaultOrderField(string $a_defaultorderfield)
setExternalSorting(bool $a_val)
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
setId(string $a_val)
setDefaultOrderDirection(string $a_defaultorderdirection)
setData(array $a_data)
Set table data.
setMaxCount(int $a_max_count)
set max.
A component is the most general form of an entity in the UI.
Definition: Component.php:28
This is how the factory for UI elements looks.
Definition: Factory.php:38
An entity that renders components to a string output.
Definition: Renderer.php:31
if(! $DIC->user() ->getId()||!ilLTIConsumerAccess::hasCustomProviderCreationAccess()) $params
Definition: ltiregstart.php:31
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$url
Definition: shib_logout.php:70