ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilWebDAVMountInstructionsDocumentTableGUI.php
Go to the documentation of this file.
1<?php
2
4{
7
9 protected $ui_factory;
10
12 protected $ui_renderer;
13
15 protected $is_editable = false;
16
18 protected $factor = 10;
19
21 protected $i = 1;
22
25
28
30 protected $ui_components = [];
31
33 protected $provider;
34
35 public function __construct(
37 ilWebDAVUriBuilder $a_webdav_uri_builder,
38 string $a_command,
39 ILIAS\UI\Factory $a_ui_factory,
40 ILIAS\UI\Renderer $a_ui_renderer,
41 bool $a_is_editable = false
42 ) {
43 $this->webdav_uri_builder = $a_webdav_uri_builder;
44 $this->ui_factory = $a_ui_factory;
45 $this->ui_renderer = $a_ui_renderer;
46 $this->is_editable = $a_is_editable;
47
48 $this->setId('mount_instructions_documents');
49 $this->setFormName('mount_instructions_documents');
50
51 parent::__construct($a_parent_obj, $a_command);
52
54 $this->optional_columns = (array) $this->getSelectableColumns();
55 $this->visible_optional_columns = (array) $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(), $a_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', 'Services/WebDAV');
78
79 if ($this->is_editable) {
80 $this->setSelectAllCheckbox('webdav_id[]');
81 $this->addCommandButton('saveDocumentSorting', $this->lng->txt('sorting_save'));
82 }
83
85 }
86
87 public function setProvider(ilWebDAVMountInstructionsTableDataProvider $a_provider) : void
88 {
89 $this->provider = $a_provider;
90 }
91
93 {
94 return $this->provider;
95 }
96
97 protected function onBeforeDataFetched(array &$a_params, array &$a_filter) : void
98 {
99 }
100
101 protected function prepareRow(array &$a_row) : void
102 {
103 }
104
105 public function getSelectableColumns()
106 {
107 $optional_columns = array_filter($this->getColumnDefinition(), function ($column) {
108 return isset($column['optional']) && $column['optional'];
109 });
110
111 $columns = [];
112 foreach ($optional_columns as $index => $column) {
113 $columns[$column['field']] = $column;
114 }
115
116 return $columns;
117 }
118
119 protected function isColumnVisible(int $a_index) : bool
120 {
121 $column_definition = $this->getColumnDefinition();
122 if (array_key_exists($a_index, $column_definition)) {
123 $column = $column_definition[$a_index];
124 if (isset($column['optional']) && !$column['optional']) {
125 return true;
126 }
127
128 if (
129 is_array($this->visible_optional_columns) &&
130 array_key_exists($column['field'], $this->visible_optional_columns)
131 ) {
132 return true;
133 }
134 }
135
136 return false;
137 }
138
139 final protected function fillRow($a_row)
140 {
141 $this->prepareRow($a_row);
142
143 foreach ($this->getColumnDefinition() as $index => $column) {
144 if (!$this->isColumnVisible($index)) {
145 continue;
146 }
147
148 $this->tpl->setCurrentBlock('column');
149 $value = $this->formatCellValue($column['field'], $a_row);
150 if ((string) $value === '') {
151 $this->tpl->touchBlock('column');
152 } else {
153 $this->tpl->setVariable('COLUMN_VALUE', $value);
154 }
155
156 $this->tpl->parseCurrentBlock();
157 }
158 }
159
160 protected function getColumnDefinition() : array
161 {
162 $i = 0;
163
164 $columns = [];
165
166 $columns[++$i] = [
167 'field' => 'sorting',
168 'txt' => $this->lng->txt('meta_order', 'meta'),
169 'default' => true,
170 'optional' => false,
171 'sortable' => false,
172 'width' => '5%'
173 ];
174
175 $columns[++$i] = [
176 'field' => 'title',
177 'txt' => $this->lng->txt('webdav_tbl_docs_head_title'),
178 'default' => true,
179 'optional' => false,
180 'sortable' => false,
181 'width' => '25%'
182 ];
183
184 $columns[++$i] = [
185 'field' => 'creation_ts',
186 'txt' => $this->lng->txt('created'),
187 'default' => true,
188 'optional' => true,
189 'sortable' => false
190 ];
191
192 $columns[++$i] = [
193 'field' => 'modification_ts',
194 'txt' => $this->lng->txt('last_change'),
195 'default' => true,
196 'optional' => true,
197 'sortable' => false
198 ];
199
200 $columns[++$i] = [
201 'field' => 'language',
202 'txt' => $this->lng->txt('language'),
203 'default' => true,
204 'optional' => false,
205 'sortable' => false
206 ];
207
208 if ($this->is_editable) {
209 $columns[++$i] = [
210 'field' => 'actions',
211 'txt' => $this->lng->txt('actions'),
212 'default' => true,
213 'optional' => false,
214 'sortable' => false,
215 'width' => '10%'
216 ];
217 };
218
219 return $columns;
220 }
221
222 public function populate() : void
223 {
224 if ($this->getExternalSegmentation() && $this->getExternalSorting()) {
226 } elseif (!$this->getExternalSegmentation() && $this->getExternalSorting()) {
227 $this->determineOffsetAndOrder(true);
228 }
229
230 $params = [];
231 if ($this->getExternalSegmentation()) {
232 $params['limit'] = $this->getLimit();
233 $params['offset'] = $this->getOffset();
234 }
235 if ($this->getExternalSorting()) {
236 $params['order_field'] = $this->getOrderField();
237 $params['order_direction'] = $this->getOrderDirection();
238 }
239
241 $filter = (array) $this->filter;
242
243 foreach ($this->optional_filters as $key => $value) {
244 if ($this->isFilterSelected($key)) {
245 $filter[$key] = $value;
246 }
247 }
248
249 $this->onBeforeDataFetched($params, $filter);
250 $data = $this->getProvider()->getList();
251
252 if (!count($data['items']) && $this->getOffset() > 0 && $this->getExternalSegmentation()) {
253 $this->resetOffset();
254 if ($this->getExternalSegmentation()) {
255 $params['limit'] = $this->getLimit();
256 $params['offset'] = $this->getOffset();
257 }
258 $data = $this->getProvider()->getList();
259 }
260
261 $this->preProcessData($data);
262
263 $this->setData($data['items']);
264 if ($this->getExternalSegmentation()) {
265 $this->setMaxCount($data['cnt']);
266 }
267 }
268
269 protected function preProcessData(array &$data) : void
270 {
275 foreach ($data['items'] as $key => $document) {
276 $data['items'][$key] = [
277 'id' => $document->getId(),
278 'title' => $document->getTitle(),
279 'creation_ts' => $document->getCreationTs(),
280 'modification_ts' => $document->getModificationTs(),
281 'raw_text' => $document->getUploadedInstructions(),
282 'processed_text' => $document->getProcessedInstructions(),
283 'language' => $document->getLanguage(),
284 ];
285 }
286 }
287
288 protected function formatCellValue(string $a_column, array $a_row) : string
289 {
290 if (in_array($a_column, ['creation_ts', 'modification_ts'])) {
291 return \ilDatePresentation::formatDate(new \ilDateTime($a_row[$a_column], IL_CAL_DATETIME));
292 } elseif ('sorting' === $a_column) {
293 return $this->formatSorting($a_row);
294 } elseif ('title' === $a_column) {
295 return $this->formatTitle($a_column, $a_row);
296 } elseif ('actions' === $a_column) {
297 return $this->formatActionsDropDown($a_column, $a_row);
298 } elseif ('language' === $a_column) {
299 return $this->formatLanguage($a_column, $a_row);
300 }
301
302 return trim($a_row[$a_column]);
303 }
304
305 protected function formatActionsDropDown(string $a_column, array $a_row) : string
306 {
307 if (!$this->is_editable) {
308 return '';
309 }
310
311 $this->ctrl->setParameter($this->getParentObject(), 'webdav_id', $a_row['id']);
312
313 $edit_btn = $this->ui_factory
314 ->button()
315 ->shy(
316 $this->lng->txt('edit'),
317 $this->ctrl->getLinkTarget($this->getParentObject(), 'showEditDocumentForm')
318 );
319
320 $delete_modal = $this->ui_factory
321 ->modal()
322 ->interruptive(
323 $this->lng->txt('webdav_doc_delete'),
324 $this->lng->txt('webdav_sure_delete_documents_s') . ' ' . $a_row['title'],
325 $this->ctrl->getFormAction($this->getParentObject(), 'deleteDocument')
326 );
327
328 $delete_btn = $this->ui_factory
329 ->button()
330 ->shy($this->lng->txt('delete'), '#')
331 ->withOnClick($delete_modal->getShowSignal());
332
333 $this->ui_components[] = $delete_modal;
334
335 $this->ctrl->setParameter($this->getParentObject(), 'webdav_id', null);
336
337 $drop_down = $this->ui_factory
338 ->dropdown()
339 ->standard([$edit_btn, $delete_btn])
340 ->withLabel($this->lng->txt('actions'));
341
342 return $this->ui_renderer->render($drop_down);
343 }
344
345 protected function formatLanguage(string $a_column, array $a_row) : string
346 {
347 return $a_row[$a_column];
348 }
349
350 protected function formatTitle(string $a_column, array $a_row)
351 {
352 if ($a_row['processed_text'] == null) {
353 $a_row['processed_text'] = '';
354 }
355
356 global $DIC;
357 $uri_builder = new ilWebDAVUriBuilder($DIC->http()->request());
358 $url = $uri_builder->getUriToMountInstructionModalByLanguage($a_row['language']);
359 $title_link = $this->ui_factory
360 ->button()
361 ->shy($a_row[$a_column], '#')
362 ->withAdditionalOnLoadCode(function ($id) use ($url) {
363 return "$('#$id').click(function(){ triggerWebDAVModal('$url');});";
364 });
365
366 return $this->ui_renderer->render([$title_link]);
367 }
368
369 protected function formatSorting(array $a_row) : string
370 {
371 $value = ($this->i++) * $this->factor;
372 if (!$this->is_editable) {
373 return $value;
374 }
375
376 $sorting_field = new ilNumberInputGUI('', 'sorting[' . $a_row['id'] . ']');
377 $sorting_field->setValue($value);
378 $sorting_field->setMaxLength(4);
379 $sorting_field->setSize(2);
380
381 return $sorting_field->render();
382 }
383
384 public function getHTML()
385 {
386 return parent::getHTML() . $this->ui_renderer->render($this->ui_components);
387 }
388}
if(! $in) $columns
Definition: Utf8Test.php:45
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_DATETIME
@classDescription Date and time handling
This class represents a number property in a property form.
Class ilTable2GUI.
getSelectedColumns()
Get selected columns.
setExternalSorting($a_val)
Set external sorting.
getParentObject()
Get parent object.
setTitle($a_title, $a_icon=0, $a_icon_alt=0)
Set title and title icon.
determineOffsetAndOrder($a_omit_offset=false)
Determine offset and order.
setSelectAllCheckbox($a_select_all_checkbox, $a_select_all_on_top=false)
Set the name of the checkbox that should be toggled with a select all button.
setData($a_data)
set table data @access public
getExternalSorting()
Get external sorting.
getLimit()
Get limit.
setRowTemplate($a_template, $a_template_dir="")
Set row template.
resetOffset($a_in_determination=false)
Reset offset.
setLimit($a_limit=0, $a_default_limit=0)
set max.
setDefaultOrderField($a_defaultorderfield)
Set Default order field.
getExternalSegmentation()
Get external segmentation.
addColumn( $a_text, $a_sort_field="", $a_width="", $a_is_checkbox_action_column=false, $a_class="", $a_tooltip="", $a_tooltip_with_html=false)
Add a column to the header.
getOffset()
Get offset.
setExternalSegmentation($a_val)
Set external segmentation.
setId($a_val)
Set id.
setFormName($a_formname="")
Set Form name.
setFormAction($a_form_action, $a_multipart=false)
Set Form action parameter.
isFilterSelected($a_col)
Is given filter selected?
setDefaultOrderDirection($a_defaultorderdirection)
Set Default order direction.
determineSelectedFilters()
Determine selected filters.
addCommandButton($a_cmd, $a_text, $a_onclick='', $a_id="", $a_class=null)
Add Command button.
getOrderDirection()
Get order direction.
setMaxCount($a_max_count)
set max.
__construct(ilWebDAVMountInstructionsUploadGUI $a_parent_obj, ilWebDAVUriBuilder $a_webdav_uri_builder, string $a_command, ILIAS\UI\Factory $a_ui_factory, ILIAS\UI\Renderer $a_ui_renderer, bool $a_is_editable=false)
setProvider(ilWebDAVMountInstructionsTableDataProvider $a_provider)
static maybeRenderWebDAVModalInGlobalTpl()
This is kind of a singleton pattern.
$index
Definition: metadata.php:128
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
Class ChatMainBarProvider \MainMenu\Provider.
Class Factory.
$url
$DIC
Definition: xapitoken.php:46