ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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->setDescription($this->tableview->getTitle());
100 $this->setDefaultOrderDirection($this->table->getDefaultSortFieldOrder());
101 // Set a default sorting?
102 $default_sort_title = 'id';
103 if ($fieldId = $this->table->getDefaultSortField()) {
106 foreach (ilDclStandardField::_getStandardFields($this->table->getId()) as $stdField) {
107 if ($stdField->getId() == $fieldId) {
108 $default_sort_title = $stdField->getTitle();
109 break;
110 }
111 }
112 } else {
113 $default_sort_title = ilDclCache::getFieldCache((int) $fieldId)->getTitle();
114 }
115 $this->setDefaultOrderField($default_sort_title);
116 }
117
118 if (($this->table->getExportEnabled() || ilObjDataCollectionAccess::hasAccessToFields(
119 $this->parent_obj->getRefId(),
120 $this->table->getId()
121 ))) {
122 $this->setExportFormats([self::EXPORT_EXCEL, self::EXPORT_EXCEL_ASYNC]);
123 }
124
125 $this->ctrl->saveParameter($a_parent_obj, 'tableview_id');
126 $this->setFormAction($this->ctrl->getFormAction($a_parent_obj, "applyFilter"));
127 $this->setStyle('table', $this->getStyle('table') . ' ' . 'dcl_record_list');
128 }
129
133 public function getFilter(): array
134 {
135 return $this->filter;
136 }
137
138 public function setRecordData(array $data): void
139 {
140 $this->object_data = $data;
141 $this->buildData();
142 $this->addActionRowIfNeeded();
143 }
144
145 protected function addActionRowIfNeeded(): void
146 {
147 if ($this->needsActionRow()) {
148 $this->addColumn($this->lng->txt("actions"), "", "");
149 }
150 }
151
152 public function numericOrdering(string $a_field): bool
153 {
154 return in_array($a_field, $this->numeric_fields);
155 }
156
160 private function buildData(): void
161 {
162 $data = [];
163 foreach ($this->object_data as $record) {
164 $record_data = [];
165 $record_data["_front"] = null;
166 $record_data['_record'] = $record;
167
168 foreach ($this->tableview->getVisibleFields() as $field) {
169 $title = $field->getTitle();
170 $record_data[$title] = $record->getRecordFieldHTML($field->getId(), ['tableview_id' => $this->tableview->getId()]);
171
172 // Additional column filled in ::fillRow() method, showing the learning progress
173 if ($field->getProperty(ilDclBaseFieldModel::PROP_LEARNING_PROGRESS)) {
174 $record_data["_status_" . $title] = $this->getStatus($record, $field);
175 }
176
177 if ($field->getId() == 'comments') {
178 $record_data['n_comments'] = $record->getNrOfComments();
179 }
180 }
181
182 $this->ctrl->setParameterByClass(ilDclFieldEditGUI::class, "record_id", $record->getId());
183 $this->ctrl->setParameterByClass(ilDclDetailedViewGUI::class, "table_id", $record->getTableId());
184 $this->ctrl->setParameterByClass(ilDclDetailedViewGUI::class, "record_id", $record->getId());
185 $this->ctrl->setParameterByClass(ilDclDetailedViewGUI::class, "tableview_id", $this->tableview->getId());
186 $this->ctrl->setParameterByClass(ilDclRecordEditGUI::class, "record_id", $record->getId());
187 $this->ctrl->setParameterByClass(ilDclRecordEditGUI::class, "tableview_id", $this->tableview->getId());
188 $this->ctrl->setParameterByClass(ilDclRecordEditGUI::class, "mode", $this->mode);
189
190 $action_links = [];
191
192 if ($this->page_active) {
193 $record_data["_front"] = $this->ctrl->getLinkTargetByClass(ilDclDetailedViewGUI::class, 'renderRecord');
194 $action_links[] = $this->ui->factory()->link()->standard(
195 $this->lng->txt('view'),
196 $this->ctrl->getLinkTargetByClass(ilDclDetailedViewGUI::class, 'renderRecord')
197 );
198 }
199
200 if ($record->hasPermissionToEdit($this->parent_obj->getRefId())) {
201 $action_links[] = $this->ui->factory()->link()->standard(
202 $this->lng->txt('edit'),
203 $this->ctrl->getLinkTargetByClass(ilDclRecordEditGUI::class, 'edit')
204 );
205 }
206
207 if ($record->hasPermissionToDelete($this->parent_obj->getRefId())) {
208 $action_links[] = $this->ui->factory()->link()->standard(
209 $this->lng->txt('delete'),
210 $this->ctrl->getLinkTargetByClass(ilDclRecordEditGUI::class, 'confirmDelete')
211 );
212 }
213
214 if ($this->table->getPublicCommentsEnabled()) {
215 $js_code = $this->getCommentJsLinkCode($record->getId());
216 $action_links[] = $this->ui->factory()->button()->shy(
217 $this->lng->txt('dcl_comments'),
218 "#"
219 )->withAdditionalOnLoadCode(function ($id) use ($js_code) {
220 return "document.getElementById('$id').addEventListener('click',function()
221 {
222 $js_code
223 });";
224 });
225 }
226 $action_dropdown = $this->ui->factory()->dropdown()->standard($action_links)
227 ->withLabel($this->lng->txt("actions"));
228 $record_data["_actions"] = $this->ui->renderer()->render($action_dropdown);
229
230 $data[] = $record_data;
231 }
232 $this->setData($data);
233 }
234
235 protected function fillRow(array $a_set): void
236 {
237 $record_obj = $a_set['_record'];
238
243 foreach ($this->tableview->getVisibleFields() as $field) {
244 $title = $field->getTitle();
245 $this->tpl->setCurrentBlock("field");
246 $content = $a_set[$title];
247 if ($content === false || $content === null) {
248 $content = '';
249 } // SW - This ensures to display also zeros in the table...
250
251 $this->tpl->setVariable("CONTENT", $content);
252 $this->tpl->parseCurrentBlock();
253
254 if ($field->getProperty(ilDclBaseFieldModel::PROP_LEARNING_PROGRESS)) {
255 $this->tpl->setCurrentBlock("field");
256 $this->tpl->setVariable("CONTENT", $a_set["_status_" . $title]);
257 $this->tpl->parseCurrentBlock();
258 }
259 }
260
261 if ($a_set["_front"]) {
262 $this->tpl->setCurrentBlock('view');
263 $this->tpl->setVariable(
264 "VIEW_DETAILS",
265 $this->ui->renderer()->render($this->ui->factory()->symbol()->glyph()->enlarge($a_set["_front"]))
266 );
267 $this->tpl->parseCurrentBlock();
268 }
269
270 if (strlen($a_set["_actions"]) > 0) {
271 $this->tpl->setCurrentBlock('actions');
272 $this->tpl->setVariable("ACTIONS", $a_set["_actions"]);
273 $this->tpl->parseCurrentBlock();
274 }
275
276 if ($this->mode == ilDclRecordListGUI::MODE_MANAGE) {
277 if ($record_obj->hasPermissionToDelete($this->parent_obj->getRefId())) {
278 $this->tpl->setCurrentBlock('mode_manage');
279 $this->tpl->setVariable('RECORD_ID', $record_obj->getId());
280 $this->tpl->parseCurrentBlock();
281 } else {
282 $this->tpl->touchBlock('mode_manage_no_owner');
283 }
284 }
285 }
286
287 protected function needsActionRow(): bool
288 {
289 if ($this->table->getPublicCommentsEnabled() || $this->page_active) {
290 return true;
291 }
292
293 foreach ($this->object_data as $record) {
294 if ($record->hasPermissionToEdit($this->parent_obj->getRefId()) ||
295 $record->hasPermissionToDelete($this->parent_obj->getRefId())) {
296 return true;
297 }
298 }
299
300 return false;
301 }
302
306 protected function getStatus(ilDclBaseRecordModel $record, ilDclBaseFieldModel $field): string
307 {
308 $record_field = ilDclCache::getRecordFieldCache($record, $field);
309 $return = "";
310 if ($status = $record_field->getStatus()) {
312 $return = $icons->renderIconForStatus($status->status);
313 }
314
315 return $return;
316 }
317
318 public function initFilter(): void
319 {
320 foreach ($this->tableview->getFilterableFieldSettings() as $field_set) {
321 $field = $field_set->getFieldObject();
322 $value = ilDclCache::getFieldRepresentation($field)->addFilterInputFieldToTable($this);
323 $filter = $this->getFilterItemByPostVar('filter_' . $field->getId());
324
325 $isset = ilSession::has("form_" . $filter->getParentTable()->getId() . "_" . $filter->getFieldId());
326 if (!$field_set->isFilterChangeable() || !$isset) {
327 $value = $field_set->getFilterValue();
328 $filter->setValueByArray($value);
329 $value = $filter->getValue();
330
331 if (!$field_set->isFilterChangeable()) {
332 $filter->setDisabled(true);
333 if ($filter instanceof ilCombinationInputGUI) {
334 $filter->__call('setDisabled', [true]);
335 }
336 }
337 }
338
339 $this->applyFilter($field->getId(), $value);
340 }
341 }
342
343 public function applyFilter($field_id, $filter_value)
344 {
345 if ($filter_value) {
346 $this->filter["filter_" . $field_id] = $filter_value;
347 }
348 }
349
354 public function loadProperty(string $type): string
355 {
356 if ($this->getId() && $this->userId > 0) {
357 $tab_prop = new ilTablePropertiesStorageGUI();
358 return $tab_prop->getProperty($this->getId(), $this->userId, $type);
359 }
360 return "";
361 }
362
366 protected function getCommentJsLinkCode(int $recordId): string
367 {
369 1,
370 $this->parent_obj->getRefId(),
371 'dcl',
372 $this->parent_obj->getObjId(),
373 'dcl',
374 $recordId
375 );
376
377 return ilNoteGUI::getListCommentsJSCall($ajax_hash, '');
378 }
379
383 public function exportData(
384 int $format,
385 bool $send = false
386 ): void {
387 if ($this->dataExists()) {
388 $exporter = new ilDclContentExporter(
389 $this->parent_obj->getRefId(),
390 $this->table->getId(),
391 $this->filter
392 );
393 $exporter->export(ilDclContentExporter::EXPORT_EXCEL, null, true);
394 }
395 }
396}
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)
Hook-Class for exporting data-collections (used in SOAP-Class) This Class avoids duplicated code by r...
@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="")
setDescription(string $a_val)
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, $class_path, string $cmd, bool $activated=true, bool $expanded=true)
if(!file_exists('../ilias.ini.php'))
global $DIC
Definition: shib_login.php:26