ILIAS  release_8 Revision v8.24
class.ilWebDAVMountInstructionsDocumentTableGUI.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
23use Psr\Http\Message\RequestInterface;
24
26{
30 protected RequestInterface $request;
31 protected bool $is_editable = false;
32 protected int $factor = 10;
33 protected int $i = 1;
34 protected int $num_rendered_criteria = 0;
35 protected array $optional_columns;
37
39 protected array $ui_components = [];
40
42
43 public function __construct(
46 string $command,
49 RequestInterface $request,
50 bool $is_editable = false
51 ) {
52 $this->webdav_uri_builder = $webdav_uri_builder;
53 $this->ui_factory = $ui_factory;
54 $this->ui_renderer = $ui_renderer;
55 $this->is_editable = $is_editable;
56 $this->request = $request;
57
58 $this->setId('mount_instructions_documents');
59 $this->setFormName('mount_instructions_documents');
60
61 parent::__construct($parent_obj, $command);
62
63 $columns = $this->getColumnDefinition();
64 $this->optional_columns = $this->getSelectableColumns();
65 $this->visible_optional_columns = $this->getSelectedColumns();
66
67 foreach ($columns as $index => $column) {
68 if ($this->isColumnVisible($index)) {
69 $this->addColumn(
70 $column['txt'],
71 isset($column['sortable']) && $column['sortable'] ? $column['field'] : '',
72 isset($column['width']) ? $column['width'] : '',
73 isset($column['is_checkbox']) ? (bool) $column['is_checkbox'] : false
74 );
75 }
76 }
77
78 $this->setTitle($this->lng->txt('webdav_tbl_docs_title'));
79 $this->setFormAction($this->ctrl->getFormAction($this->getParentObject(), $command));
80
81 $this->setDefaultOrderDirection('ASC');
82 $this->setDefaultOrderField('sorting');
83 $this->setExternalSorting(true);
84 $this->setExternalSegmentation(true);
85 $this->setLimit(PHP_INT_MAX);
86
87 $this->setRowTemplate('tpl.webdav_documents_row.html', 'Services/WebDAV');
88
89 if ($this->is_editable) {
90 $this->addCommandButton('saveDocumentSorting', $this->lng->txt('sorting_save'));
91 }
92
94 }
95
97 {
98 $this->provider = $provider;
99 }
100
102 {
103 return $this->provider;
104 }
105
106 public function getSelectableColumns(): array
107 {
108 $optional_columns = array_filter($this->getColumnDefinition(), fn ($column) => isset($column['optional']) && $column['optional']);
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 final protected function fillRow(array $row): void
139 {
140 foreach ($this->getColumnDefinition() as $index => $column) {
141 if (!$this->isColumnVisible($index)) {
142 continue;
143 }
144
145 $this->tpl->setCurrentBlock('column');
146 $value = $this->formatCellValue($column['field'], $row);
147 if ($value === '') {
148 $this->tpl->touchBlock('column');
149 } else {
150 $this->tpl->setVariable('COLUMN_VALUE', $value);
151 }
152
153 $this->tpl->parseCurrentBlock();
154 }
155 }
156
157 protected function getColumnDefinition(): array
158 {
159 $i = 0;
160
161 $columns = [];
162
163 $columns[++$i] = [
164 'field' => 'sorting',
165 'txt' => $this->lng->txt('meta_order', 'meta'),
166 'default' => true,
167 'optional' => false,
168 'sortable' => false,
169 'width' => '5%'
170 ];
171
172 $columns[++$i] = [
173 'field' => 'title',
174 'txt' => $this->lng->txt('webdav_tbl_docs_head_title'),
175 'default' => true,
176 'optional' => false,
177 'sortable' => false,
178 'width' => '25%'
179 ];
180
181 $columns[++$i] = [
182 'field' => 'creation_ts',
183 'txt' => $this->lng->txt('created'),
184 'default' => true,
185 'optional' => true,
186 'sortable' => false
187 ];
188
189 $columns[++$i] = [
190 'field' => 'modification_ts',
191 'txt' => $this->lng->txt('last_change'),
192 'default' => true,
193 'optional' => true,
194 'sortable' => false
195 ];
196
197 $columns[++$i] = [
198 'field' => 'language',
199 'txt' => $this->lng->txt('language'),
200 'default' => true,
201 'optional' => false,
202 'sortable' => false
203 ];
204
205 if ($this->is_editable) {
206 $columns[++$i] = [
207 'field' => 'actions',
208 'txt' => $this->lng->txt('actions'),
209 'default' => true,
210 'optional' => false,
211 'sortable' => false,
212 'width' => '10%'
213 ];
214 };
215
216 return $columns;
217 }
218
219 public function populate(): void
220 {
221 if ($this->getExternalSegmentation() && $this->getExternalSorting()) {
223 } elseif (!$this->getExternalSegmentation() && $this->getExternalSorting()) {
224 $this->determineOffsetAndOrder(true);
225 }
226
227 $params = [];
228 if ($this->getExternalSegmentation()) {
229 $params['limit'] = $this->getLimit();
230 $params['offset'] = $this->getOffset();
231 }
232 if ($this->getExternalSorting()) {
233 $params['order_field'] = $this->getOrderField();
234 $params['order_direction'] = $this->getOrderDirection();
235 }
236
238 $data = $this->getProvider()->getList();
239
240 if (!count($data['items']) && $this->getOffset() > 0 && $this->getExternalSegmentation()) {
241 $this->resetOffset();
242 if ($this->getExternalSegmentation()) {
243 $params['limit'] = $this->getLimit();
244 $params['offset'] = $this->getOffset();
245 }
246 $data = $this->getProvider()->getList();
247 }
248
249 $this->preProcessData($data);
250
251 $this->setData($data['items']);
252 if ($this->getExternalSegmentation()) {
253 $this->setMaxCount($data['cnt']);
254 }
255 }
256
257 protected function preProcessData(array &$data): void
258 {
259 foreach ($data['items'] as $key => $document) {
260 $data['items'][$key] = [
261 'id' => $document->getId(),
262 'title' => $document->getTitle(),
263 'creation_ts' => $document->getCreationTs(),
264 'modification_ts' => $document->getModificationTs(),
265 'raw_text' => $document->getUploadedInstructions(),
266 'processed_text' => $document->getProcessedInstructions(),
267 'language' => $document->getLanguage(),
268 ];
269 }
270 }
271
272 protected function formatCellValue(string $column, array $row): string
273 {
274 $function = 'format' . ucfirst($column);
275 if (method_exists($this, $function)) {
276 return $this->{$function}($column, $row);
277 }
278 if (in_array($column, ['creation_ts', 'modification_ts'])) {
280 }
281
282 return trim($row[$column]);
283 }
284
285 protected function formatActions(string $column, array $row): string
286 {
287 if (!$this->is_editable) {
288 return '';
289 }
290
291 $this->ctrl->setParameter($this->getParentObject(), 'document_id', $row['id']);
292
293 $edit_btn = $this->ui_factory
294 ->button()
295 ->shy(
296 $this->lng->txt('edit'),
297 $this->ctrl->getLinkTarget($this->getParentObject(), 'showEditDocumentForm')
298 );
299
300 $delete_modal = $this->ui_factory
301 ->modal()
302 ->interruptive(
303 $this->lng->txt('webdav_doc_delete'),
304 $this->lng->txt('webdav_sure_delete_documents_s') . ' ' . $row['title'],
305 $this->ctrl->getFormAction($this->getParentObject(), 'deleteDocument')
306 );
307
308 $delete_btn = $this->ui_factory
309 ->button()
310 ->shy($this->lng->txt('delete'), '#')
311 ->withOnClick($delete_modal->getShowSignal());
312
313 $this->ui_components[] = $delete_modal;
314
315 $this->ctrl->setParameter($this->getParentObject(), 'document_id', null);
316
317 $drop_down = $this->ui_factory
318 ->dropdown()
319 ->standard([$edit_btn, $delete_btn])
320 ->withLabel($this->lng->txt('actions'));
321
322 return $this->ui_renderer->render($drop_down);
323 }
324
325 protected function formatTitle(string $column, array $row): string
326 {
327 if ($row['processed_text'] == null) {
328 $row['processed_text'] = '';
329 }
330
331 $uri_builder = new ilWebDAVUriBuilder($this->request);
332 $url = $uri_builder->getUriToMountInstructionModalByLanguage($row['language']);
333 $title_link = $this->ui_factory
334 ->button()
335 ->shy($row[$column], '#')
336 ->withAdditionalOnLoadCode(fn ($id) => "$('#$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 = strval(($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 public function getHTML(): string
357 {
358 return parent::getHTML() . $this->ui_renderer->render($this->ui_components);
359 }
360}
const IL_CAL_DATETIME
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
@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, ilWebDAVUriBuilder $webdav_uri_builder, string $command, Factory $ui_factory, Renderer $ui_renderer, RequestInterface $request, bool $is_editable=false)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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:33
$index
Definition: metadata.php:145
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
string $key
Consumer key/client ID value.
Definition: System.php:193
$url