ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilWebDAVMountInstructionsDocumentTableGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
24use Psr\Http\Message\RequestInterface;
25
27{
28 protected int $factor = 10;
29 protected int $i = 1;
30 protected int $num_rendered_criteria = 0;
31 protected array $optional_columns;
33
35 protected array $ui_components = [];
36
38
39 public function __construct(
41 protected ilWebDAVUriBuilder $webdav_uri_builder,
42 string $command,
43 protected Factory $ui_factory,
44 protected Renderer $ui_renderer,
45 protected RequestInterface $request,
46 protected bool $is_editable = false
47 ) {
48 $this->setId('mount_instructions_documents');
49 $this->setFormName('mount_instructions_documents');
50
51 parent::__construct($parent_obj, $command);
52
53 $columns = $this->getColumnDefinition();
54 $this->optional_columns = $this->getSelectableColumns();
55 $this->visible_optional_columns = $this->getSelectedColumns();
56
57 foreach ($columns as $index => $column) {
58 if ($this->isColumnVisible($index)) {
59 $this->addColumn(
60 $column['txt'],
61 isset($column['sortable']) && $column['sortable'] ? $column['field'] : '',
62 isset($column['width']) ? $column['width'] : '',
63 isset($column['is_checkbox']) ? (bool) $column['is_checkbox'] : false
64 );
65 }
66 }
67
68 $this->setTitle($this->lng->txt('webdav_tbl_docs_title'));
69 $this->setFormAction($this->ctrl->getFormAction($this->getParentObject(), $command));
70
71 $this->setDefaultOrderDirection('ASC');
72 $this->setDefaultOrderField('sorting');
73 $this->setExternalSorting(true);
74 $this->setExternalSegmentation(true);
75 $this->setLimit(PHP_INT_MAX);
76
77 $this->setRowTemplate('tpl.webdav_documents_row.html', 'components/ILIAS/WebDAV');
78
79 if ($this->is_editable) {
80 $this->addCommandButton('saveDocumentSorting', $this->lng->txt('sorting_save'));
81 }
82
84 }
85
87 {
88 $this->provider = $provider;
89 }
90
92 {
93 return $this->provider;
94 }
95
96 public function getSelectableColumns(): array
97 {
98 $optional_columns = array_filter(
99 $this->getColumnDefinition(),
100 fn($column): bool => isset($column['optional']) && $column['optional']
101 );
102
103 $columns = [];
104 foreach ($optional_columns as $column) {
105 $columns[$column['field']] = $column;
106 }
107
108 return $columns;
109 }
110
111 protected function isColumnVisible(int $index): bool
112 {
113 $column_definition = $this->getColumnDefinition();
114 if (array_key_exists($index, $column_definition)) {
115 $column = $column_definition[$index];
116 if (isset($column['optional']) && !$column['optional']) {
117 return true;
118 }
119
120 if (
121 is_array($this->visible_optional_columns) &&
122 array_key_exists($column['field'], $this->visible_optional_columns)
123 ) {
124 return true;
125 }
126 }
127
128 return false;
129 }
130
131 final protected function fillRow(array $row): void
132 {
133 foreach ($this->getColumnDefinition() as $index => $column) {
134 if (!$this->isColumnVisible($index)) {
135 continue;
136 }
137
138 $this->tpl->setCurrentBlock('column');
139 $value = $this->formatCellValue($column['field'], $row);
140 if ($value === '') {
141 $this->tpl->touchBlock('column');
142 } else {
143 $this->tpl->setVariable('COLUMN_VALUE', $value);
144 }
145
146 $this->tpl->parseCurrentBlock();
147 }
148 }
149
150 protected function getColumnDefinition(): array
151 {
152 $i = 0;
153
154 $columns = [];
155
156 $columns[++$i] = [
157 'field' => 'sorting',
158 'txt' => $this->lng->txt('meta_order', 'meta'),
159 'default' => true,
160 'optional' => false,
161 'sortable' => false,
162 'width' => '5%'
163 ];
164
165 $columns[++$i] = [
166 'field' => 'title',
167 'txt' => $this->lng->txt('webdav_tbl_docs_head_title'),
168 'default' => true,
169 'optional' => false,
170 'sortable' => false,
171 'width' => '25%'
172 ];
173
174 $columns[++$i] = [
175 'field' => 'creation_ts',
176 'txt' => $this->lng->txt('created'),
177 'default' => true,
178 'optional' => true,
179 'sortable' => false
180 ];
181
182 $columns[++$i] = [
183 'field' => 'modification_ts',
184 'txt' => $this->lng->txt('last_change'),
185 'default' => true,
186 'optional' => true,
187 'sortable' => false
188 ];
189
190 $columns[++$i] = [
191 'field' => 'language',
192 'txt' => $this->lng->txt('language'),
193 'default' => true,
194 'optional' => false,
195 'sortable' => false
196 ];
197
198 if ($this->is_editable) {
199 $columns[++$i] = [
200 'field' => 'actions',
201 'txt' => $this->lng->txt('actions'),
202 'default' => true,
203 'optional' => false,
204 'sortable' => false,
205 'width' => '10%'
206 ];
207 };
208
209 return $columns;
210 }
211
212 public function populate(): void
213 {
214 if ($this->getExternalSegmentation() && $this->getExternalSorting()) {
216 } elseif (!$this->getExternalSegmentation() && $this->getExternalSorting()) {
217 $this->determineOffsetAndOrder(true);
218 }
219
220 $params = [];
221 if ($this->getExternalSegmentation()) {
222 $params['limit'] = $this->getLimit();
223 $params['offset'] = $this->getOffset();
224 }
225 if ($this->getExternalSorting()) {
226 $params['order_field'] = $this->getOrderField();
227 $params['order_direction'] = $this->getOrderDirection();
228 }
229
231 $data = $this->getProvider()->getList();
232
233 if (!count($data['items']) && $this->getOffset() > 0 && $this->getExternalSegmentation()) {
234 $this->resetOffset();
235 if ($this->getExternalSegmentation()) {
236 $params['limit'] = $this->getLimit();
237 $params['offset'] = $this->getOffset();
238 }
239 $data = $this->getProvider()->getList();
240 }
241
242 $this->preProcessData($data);
243
244 $this->setData($data['items']);
245 if ($this->getExternalSegmentation()) {
246 $this->setMaxCount($data['cnt']);
247 }
248 }
249
250 protected function preProcessData(array &$data): void
251 {
252 foreach ($data['items'] as $key => $document) {
253 $data['items'][$key] = [
254 'id' => $document->getId(),
255 'title' => $document->getTitle(),
256 'creation_ts' => $document->getCreationTs(),
257 'modification_ts' => $document->getModificationTs(),
258 'raw_text' => $document->getUploadedInstructions(),
259 'processed_text' => $document->getProcessedInstructions(),
260 'language' => $document->getLanguage(),
261 ];
262 }
263 }
264
265 protected function formatCellValue(string $column, array $row): string
266 {
267 $function = 'format' . ucfirst($column);
268 if (method_exists($this, $function)) {
269 return $this->{$function}($column, $row);
270 }
271 if (in_array($column, ['creation_ts', 'modification_ts'])) {
273 }
274
275 return trim((string) $row[$column]);
276 }
277
278 protected function formatActions(string $column, array $row): string
279 {
280 if (!$this->is_editable) {
281 return '';
282 }
283
284 $this->ctrl->setParameter($this->getParentObject(), 'document_id', $row['id']);
285
286 $edit_btn = $this->ui_factory
287 ->button()
288 ->shy(
289 $this->lng->txt('edit'),
290 $this->ctrl->getLinkTarget($this->getParentObject(), 'showEditDocumentForm')
291 );
292
293 $delete_modal = $this->ui_factory
294 ->modal()
295 ->interruptive(
296 $this->lng->txt('webdav_doc_delete'),
297 $this->lng->txt('webdav_sure_delete_documents_s') . ' ' . $row['title'],
298 $this->ctrl->getFormAction($this->getParentObject(), 'deleteDocument')
299 );
300
301 $delete_btn = $this->ui_factory
302 ->button()
303 ->shy($this->lng->txt('delete'), '#')
304 ->withOnClick($delete_modal->getShowSignal());
305
306 $this->ui_components[] = $delete_modal;
307
308 $this->ctrl->setParameter($this->getParentObject(), 'document_id', null);
309
310 $drop_down = $this->ui_factory
311 ->dropdown()
312 ->standard([$edit_btn, $delete_btn])
313 ->withLabel($this->lng->txt('actions'));
314
315 return $this->ui_renderer->render($drop_down);
316 }
317
318 protected function formatTitle(string $column, array $row): string
319 {
320 if ($row['processed_text'] == null) {
321 $row['processed_text'] = '';
322 }
323
324 $uri_builder = new ilWebDAVUriBuilder($this->request);
325 $url = $uri_builder->getUriToMountInstructionModalByLanguage($row['language']);
326 $title_link = $this->ui_factory
327 ->button()
328 ->shy($row[$column], '#')
329 ->withAdditionalOnLoadCode(fn($id): string => "$('#$id').click(function(){ triggerWebDAVModal('$url');});");
330
331 return $this->ui_renderer->render([$title_link]);
332 }
333
334 protected function formatSorting(string $column, array $row): string
335 {
336 $value = strval(($this->i++) * $this->factor);
337 if (!$this->is_editable) {
338 return $value;
339 }
340
341 $sorting_field = new ilNumberInputGUI('', 'sorting[' . $row['id'] . ']');
342 $sorting_field->setValue($value);
343 $sorting_field->setMaxLength(4);
344 $sorting_field->setSize(2);
345
346 return $sorting_field->render();
347 }
348
349 public function getHTML(): string
350 {
351 return parent::getHTML() . $this->ui_renderer->render($this->ui_components);
352 }
353}
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
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
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.
setProvider(ilWebDAVMountInstructionsTableDataProvider $provider)
__construct(ilWebDAVMountInstructionsUploadGUI $parent_obj, protected ilWebDAVUriBuilder $webdav_uri_builder, string $command, protected Factory $ui_factory, protected Renderer $ui_renderer, protected RequestInterface $request, protected bool $is_editable=false)
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:68