ILIAS  trunk Revision v12.0_alpha-399-g579a087ced2
class.ilDclRecordListTableGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22{
23 public const EXPORT_EXCEL_ASYNC = 10;
25 protected ?object $parent_obj;
26 protected ilDclTable $table;
31 protected array $object_data;
32 protected array $numeric_fields = [];
33 protected array $filter = [];
34 protected string $mode;
35 protected int $userId;
36 protected ilCtrl $ctrl;
37 protected ilLanguage $lng;
38 protected \ILIAS\DI\UIServices $ui;
39 protected bool $page_active = false;
40
41 public function __construct(
42 ilDclRecordListGUI $a_parent_obj,
43 string $a_parent_cmd,
45 int $tableview_id,
47 ) {
48 global $DIC;
49 $this->ctrl = $DIC->ctrl();
50 $this->userId = $DIC->user()->getId();
51 $this->lng = $DIC->language();
52 $this->ui = $DIC->ui();
53
54 $this->tableview = ilDclTableView::find($tableview_id);
55 $identifier = 'dcl_rl_' . $table->getId() . '_' . $tableview_id;
56 $this->setPrefix($identifier);
57 $this->setFormName($identifier);
58 $this->setId($identifier);
59 $page = new ilDclDetailedViewDefinitionGUI($this->tableview->getId());
60 $this->page_active = $page->getPageObject()->isActive();
61
62 parent::__construct($a_parent_obj, $a_parent_cmd);
63 $this->table = $table;
64 $this->parent_obj = $a_parent_obj;
65 $this->setRowTemplate("tpl.record_list_row.html", "components/ILIAS/DataCollection");
66 $this->mode = $mode;
67
68 // Setup columns and sorting columns
69 if ($this->mode == ilDclRecordListGUI::MODE_MANAGE) {
70 // Add checkbox columns
71 $this->addColumn("", "", "1", true);
72 $this->setSelectAllCheckbox("record_ids[]");
73 $this->addMultiCommand("confirmDeleteRecords", $this->lng->txt('dcl_delete_records'));
74 }
75
76 if ($this->page_active) {
77 $this->addColumn("", "_front", '15px');
78 }
79
80 $this->numeric_fields = [];
81 foreach ($this->tableview->getVisibleFields() as $field) {
82 $title = $field->getTitle();
83 $sort_field = ($field->getRecordQuerySortObject() != null) ? $field->getSortField() : '';
84
85 if ($field->hasNumericSorting()) {
86 $this->numeric_fields[] = $title;
87 }
88 $this->addColumn($title, $sort_field);
89
90 if ($field->hasProperty(ilDclBaseFieldModel::PROP_LEARNING_PROGRESS)) {
91 $this->addColumn($this->lng->txt("dcl_status"), "_status_" . $field->getTitle());
92 }
93 }
94 $this->setTopCommands(true);
95 $this->setEnableHeader(true);
96 $this->setShowRowsSelector(true);
97 $this->setEnableTitle(true);
98 $this->setTitle($table->getTitle());
99 $this->setDefaultOrderDirection($this->table->getDefaultSortFieldOrder());
100 // Set a default sorting?
101 $default_sort_title = 'id';
102 if ($fieldId = $this->table->getDefaultSortField()) {
105 foreach (ilDclStandardField::_getStandardFields($this->table->getId()) as $stdField) {
106 if ($stdField->getId() == $fieldId) {
107 $default_sort_title = $stdField->getTitle();
108 break;
109 }
110 }
111 } else {
112 $default_sort_title = ilDclCache::getFieldCache((int) $fieldId)->getTitle();
113 }
114 $this->setDefaultOrderField($default_sort_title);
115 }
116
117 if (($this->table->getExportEnabled() || ilObjDataCollectionAccess::hasAccessToFields(
118 $this->parent_obj->getRefId(),
119 $this->table->getId()
120 ))) {
121 $this->setExportFormats([self::EXPORT_EXCEL, self::EXPORT_EXCEL_ASYNC]);
122 }
123
124 $this->ctrl->saveParameter($a_parent_obj, 'tableview_id');
125 $this->setFormAction($this->ctrl->getFormAction($a_parent_obj, "applyFilter"));
126 $this->setStyle('table', $this->getStyle('table') . ' ' . 'dcl_record_list');
127 }
128
132 public function getFilter(): array
133 {
134 return $this->filter;
135 }
136
137 public function setRecordData(array $data): void
138 {
139 $this->object_data = $data;
140 $this->buildData();
141 $this->addActionRowIfNeeded();
142 }
143
144 protected function addActionRowIfNeeded(): void
145 {
146 if ($this->needsActionRow()) {
147 $this->addColumn($this->lng->txt("actions"), "", "");
148 }
149 }
150
151 public function numericOrdering(string $a_field): bool
152 {
153 return in_array($a_field, $this->numeric_fields);
154 }
155
159 private function buildData(): void
160 {
161 $data = [];
162 foreach ($this->object_data as $record) {
163 $record_data = [];
164 $record_data["_front"] = null;
165 $record_data['_record'] = $record;
166
167 foreach ($this->tableview->getVisibleFields() as $field) {
168 $title = $field->getTitle();
169 $record_data[$title] = $record->getRecordFieldHTML($field->getId(), ['tableview_id' => $this->tableview->getId()]);
170
171 // Additional column filled in ::fillRow() method, showing the learning progress
172 if ($field->getProperty(ilDclBaseFieldModel::PROP_LEARNING_PROGRESS)) {
173 $record_data["_status_" . $title] = $this->getStatus($record, $field);
174 }
175
176 if ($field->getId() == 'comments') {
177 $record_data['n_comments'] = $record->getNrOfComments();
178 }
179 }
180
181 $this->ctrl->setParameterByClass(ilDclFieldEditGUI::class, "record_id", $record->getId());
182 $this->ctrl->setParameterByClass(ilDclDetailedViewGUI::class, "table_id", $record->getTableId());
183 $this->ctrl->setParameterByClass(ilDclDetailedViewGUI::class, "record_id", $record->getId());
184 $this->ctrl->setParameterByClass(ilDclDetailedViewGUI::class, "tableview_id", $this->tableview->getId());
185 $this->ctrl->setParameterByClass(ilDclRecordEditGUI::class, "record_id", $record->getId());
186 $this->ctrl->setParameterByClass(ilDclRecordEditGUI::class, "tableview_id", $this->tableview->getId());
187 $this->ctrl->setParameterByClass(ilDclRecordEditGUI::class, "mode", $this->mode);
188
189 $action_links = [];
190
191 if ($this->page_active) {
192 $record_data["_front"] = $this->ctrl->getLinkTargetByClass(ilDclDetailedViewGUI::class, 'renderRecord');
193 $action_links[] = $this->ui->factory()->link()->standard(
194 $this->lng->txt('view'),
195 $this->ctrl->getLinkTargetByClass(ilDclDetailedViewGUI::class, 'renderRecord')
196 );
197 }
198
199 if ($record->hasPermissionToEdit($this->parent_obj->getRefId())) {
200 $action_links[] = $this->ui->factory()->link()->standard(
201 $this->lng->txt('edit'),
202 $this->ctrl->getLinkTargetByClass(ilDclRecordEditGUI::class, 'edit')
203 );
204 }
205
206 if ($record->hasPermissionToDelete($this->parent_obj->getRefId())) {
207 $action_links[] = $this->ui->factory()->link()->standard(
208 $this->lng->txt('delete'),
209 $this->ctrl->getLinkTargetByClass(ilDclRecordEditGUI::class, 'confirmDelete')
210 );
211 }
212
213 if ($this->table->getPublicCommentsEnabled()) {
214 $js_code = $this->getCommentJsLinkCode($record->getId());
215 $action_links[] = $this->ui->factory()->button()->shy(
216 $this->lng->txt('dcl_comments'),
217 "#"
218 )->withAdditionalOnLoadCode(function ($id) use ($js_code) {
219 return "document.getElementById('$id').addEventListener('click',function()
220 {
221 $js_code
222 });";
223 });
224 }
225 $action_dropdown = $this->ui->factory()->dropdown()->standard($action_links)
226 ->withLabel($this->lng->txt("actions"));
227 $record_data["_actions"] = $this->ui->renderer()->render($action_dropdown);
228
229 $data[] = $record_data;
230 }
231 $this->setData($data);
232 }
233
234 protected function fillRow(array $a_set): void
235 {
236 $record_obj = $a_set['_record'];
237
242 foreach ($this->tableview->getVisibleFields() as $field) {
243 $title = $field->getTitle();
244 $this->tpl->setCurrentBlock("field");
245 $content = $a_set[$title];
246 if ($content === false || $content === null) {
247 $content = '';
248 } // SW - This ensures to display also zeros in the table...
249
250 $this->tpl->setVariable("CONTENT", $content);
251 $this->tpl->parseCurrentBlock();
252
253 if ($field->getProperty(ilDclBaseFieldModel::PROP_LEARNING_PROGRESS)) {
254 $this->tpl->setCurrentBlock("field");
255 $this->tpl->setVariable("CONTENT", $a_set["_status_" . $title]);
256 $this->tpl->parseCurrentBlock();
257 }
258 }
259
260 if ($a_set["_front"]) {
261 $this->tpl->setCurrentBlock('view');
262 $this->tpl->setVariable(
263 "VIEW_DETAILS",
264 $this->ui->renderer()->render($this->ui->factory()->symbol()->glyph()->enlarge($a_set["_front"]))
265 );
266 $this->tpl->parseCurrentBlock();
267 }
268
269 if (strlen($a_set["_actions"]) > 0) {
270 $this->tpl->setCurrentBlock('actions');
271 $this->tpl->setVariable("ACTIONS", $a_set["_actions"]);
272 $this->tpl->parseCurrentBlock();
273 }
274
275 if ($this->mode == ilDclRecordListGUI::MODE_MANAGE) {
276 if ($record_obj->hasPermissionToDelete($this->parent_obj->getRefId())) {
277 $this->tpl->setCurrentBlock('mode_manage');
278 $this->tpl->setVariable('RECORD_ID', $record_obj->getId());
279 $this->tpl->parseCurrentBlock();
280 } else {
281 $this->tpl->touchBlock('mode_manage_no_owner');
282 }
283 }
284 }
285
286 protected function needsActionRow(): bool
287 {
288 if ($this->table->getPublicCommentsEnabled() || $this->page_active) {
289 return true;
290 }
291
292 foreach ($this->object_data as $record) {
293 if ($record->hasPermissionToEdit($this->parent_obj->getRefId()) ||
294 $record->hasPermissionToDelete($this->parent_obj->getRefId())) {
295 return true;
296 }
297 }
298
299 return false;
300 }
301
305 protected function getStatus(ilDclBaseRecordModel $record, ilDclBaseFieldModel $field): string
306 {
307 $record_field = ilDclCache::getRecordFieldCache($record, $field);
308 $return = "";
309 if ($status = $record_field->getStatus()) {
311 $return = $icons->renderIconForStatus($status->status);
312 }
313
314 return $return;
315 }
316
317 public function initFilter(): void
318 {
319 foreach ($this->tableview->getFilterableFieldSettings() as $field_set) {
320 $field = $field_set->getFieldObject();
321 $value = ilDclCache::getFieldRepresentation($field)->addFilterInputFieldToTable($this);
322 $filter = $this->getFilterItemByPostVar('filter_' . $field->getId());
323
324 $isset = ilSession::has("form_" . $filter->getParentTable()->getId() . "_" . $filter->getFieldId());
325 if (!$field_set->isFilterChangeable() || !$isset) {
326 $value = $field_set->getFilterValue();
327 $filter->setValueByArray($value);
328 $value = $filter->getValue();
329
330 if (!$field_set->isFilterChangeable()) {
331 $filter->setDisabled(true);
332 if ($filter instanceof ilCombinationInputGUI) {
333 $filter->__call('setDisabled', [true]);
334 }
335 }
336 }
337
338 $this->applyFilter($field->getId(), $value);
339 }
340 }
341
342 public function applyFilter($field_id, $filter_value)
343 {
344 if ($filter_value) {
345 $this->filter["filter_" . $field_id] = $filter_value;
346 }
347 }
348
353 public function loadProperty(string $type): string
354 {
355 if ($this->getId() && $this->userId > 0) {
356 $tab_prop = new ilTablePropertiesStorageGUI();
357 return $tab_prop->getProperty($this->getId(), $this->userId, $type);
358 }
359 return "";
360 }
361
365 protected function getCommentJsLinkCode(int $recordId): string
366 {
368 1,
369 $this->parent_obj->getRefId(),
370 'dcl',
371 $this->parent_obj->getObjId(),
372 'dcl',
373 $recordId
374 );
375
376 return ilNoteGUI::getListCommentsJSCall($ajax_hash, '');
377 }
378
382 public function exportData(
383 int $format,
384 bool $send = false
385 ): void {
386 if ($this->dataExists()) {
387 $exporter = new ilDclContentExporter(
388 $this->parent_obj->getRefId(),
389 $this->table->getId(),
390 $this->filter
391 );
392 $exporter->export(ilDclContentExporter::EXPORT_EXCEL, null, true);
393 }
394 }
395}
This class represents a number property in a property form.
static buildAjaxHash(int $node_type, ?int $node_id, string $obj_type, int $obj_id, ?string $sub_type=null, ?int $sub_id=null, int $news_id=0)
Build ajax hash.
Class ilCtrl provides processing control methods.
static getRecordFieldCache(object $record, object $field)
static getFieldCache(int $field_id=0)
static getFieldRepresentation(ilDclBaseFieldModel $field)
@ilCtrl_Calls ilDclDetailedViewDefinitionGUI: ilPageEditorGUI, ilEditClipboardGUI,...
buildData()
@description Parse data from record objects to an array that is then set to this table with ::setData...
getFilter()
@description Return array of fields that are currently stored in the filter.
getCommentJsLinkCode(int $recordId)
@description Get the ajax link for displaying the comments in the right panel (to be wrapped in an on...
applyFilter($field_id, $filter_value)
exportData(int $format, bool $send=false)
Exports the table.
numericOrdering(string $a_field)
Should this field be sorted numeric?
getStatus(ilDclBaseRecordModel $record, ilDclBaseFieldModel $field)
@description This adds the column for status.
static _getStandardFields(int $table_id)
static _isStandardField($field_id)
getId()
Get table id.
static getInstance(int $variant=ilLPStatusIcons::ICON_VARIANT_DEFAULT, ?\ILIAS\UI\Renderer $renderer=null, ?\ILIAS\UI\Factory $factory=null)
language handling
static getListCommentsJSCall(string $a_hash, ?string $a_update_code=null)
Get list comments js call.
static hasAccessToFields(int $ref_id, int $table_id)
static has($a_var)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(?object $a_parent_obj, string $a_parent_cmd="", string $a_template_context="")
setShowRowsSelector(bool $a_value)
Toggle rows-per-page selector.
getFilterItemByPostVar(string $a_post_var)
setTitle(string $a_title, string $a_icon="", string $a_icon_alt="")
setExportFormats(array $formats)
Set available export formats.
setEnableTitle(bool $a_enabletitle)
setFormName(string $a_name="")
addMultiCommand(string $a_cmd, string $a_text)
setPrefix(string $a_prefix)
set prefix for sort and offset fields (if you have two or more tables on a page that you want to sort...
setFormAction(string $a_form_action, bool $a_multipart=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)
setEnableHeader(bool $a_enableheader)
setDefaultOrderField(string $a_defaultorderfield)
fillRow(array $a_set)
Standard Version of Fill Row.
setSelectAllCheckbox(string $a_select_all_checkbox, bool $a_select_all_on_top=false)
setTopCommands(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.
setStyle(string $a_element, string $a_style)
getStyle(string $a_element)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
filter(string $filter_id, array $class_path, string $cmd, bool $activated=true, bool $expanded=true)
if(!file_exists('../ilias.ini.php'))
global $DIC
Definition: shib_login.php:26