ILIAS  release_8 Revision v8.24
class.ilDclFieldListTableGUI.php
Go to the documentation of this file.
1<?php
2
20{
21 private $order = null;
22
23 protected ilDclTable $table;
24
25 protected \ILIAS\UI\Renderer $renderer;
26 protected \ILIAS\UI\Factory $factory;
27
28
29 public function __construct(ilDclFieldListGUI $a_parent_obj, string $a_parent_cmd, int $table_id)
30 {
31 global $DIC;
32 $lng = $DIC['lng'];
33 $ilCtrl = $DIC['ilCtrl'];
34
35 $this->factory = $DIC->ui()->factory();
36 $this->renderer = $DIC->ui()->renderer();
37
38 parent::__construct($a_parent_obj, $a_parent_cmd);
39
40 $this->parent_obj = $a_parent_obj;
41 $this->table = ilDclCache::getTableCache($table_id);
42 $this->table->showInvalidFields(true);
43
44 $this->setId('dcl_field_list');
45 $this->addColumn('', '', '1', true);
46 $this->addColumn($lng->txt('dcl_order'), '', '30px');
47 $this->addColumn($lng->txt('dcl_fieldtitle'), '', 'auto');
48 $this->addColumn($lng->txt('dcl_in_export'), '', '30px');
49 $this->addColumn($lng->txt('dcl_description'), '', 'auto');
50 $this->addColumn($lng->txt('dcl_field_datatype'), '', 'auto');
51 $this->addColumn($lng->txt('dcl_unique'), '', 'auto');
52 $this->addColumn($lng->txt('actions'), '', '30px');
53 // Only add mutli command for custom fields
54 if (count($this->table->getRecordFields())) {
55 $this->setSelectAllCheckbox('dcl_field_ids[]');
56 $this->addMultiCommand('confirmDeleteFields', $lng->txt('dcl_delete_fields'));
57 }
58
59 $ilCtrl->setParameterByClass('ildclfieldeditgui', 'table_id', $this->parent_obj->getTableId());
60 $ilCtrl->setParameterByClass('ildclfieldlistgui', 'table_id', $this->parent_obj->getTableId());
61
62 $this->setFormAction($ilCtrl->getFormActionByClass('ildclfieldlistgui'));
63 $this->addCommandButton('save', $lng->txt('dcl_save'));
64
65 $this->setFormAction($ilCtrl->getFormAction($a_parent_obj));
66 $this->setFormName('field_list');
67
68 //those two are important as we get our data as objects not as arrays.
69 $this->setExternalSegmentation(true);
70 $this->setExternalSorting(true);
71
72 $this->setTopCommands(true);
73 $this->setEnableHeader(true);
74 $this->setShowRowsSelector(false);
75 $this->setShowTemplates(false);
76 $this->setEnableHeader(true);
77 $this->setEnableTitle(true);
78 $this->setDefaultOrderDirection('asc');
79
80 $this->setTitle($lng->txt('dcl_table_list_fields'));
81 $this->setRowTemplate('tpl.field_list_row.html', 'Modules/DataCollection');
82 $this->setStyle('table', $this->getStyle('table') . ' ' . 'dcl_record_list');
83
84 $this->setData($this->table->getFields());
85 }
86
90 public function getHTML(): string
91 {
93 $ilCtrl = $this->ctrl;
94
95 if ($this->getExportMode()) {
96 $this->exportData($this->getExportMode(), true);
97 }
98
99 $this->prepareOutput();
100
101 if (is_object($ilCtrl) && is_object($this->getParentObject()) && $this->getId() == "") {
102 $ilCtrl->saveParameter($this->getParentObject(), $this->getNavParameter());
103 }
104
105 if (!$this->getPrintMode()) {
106 // set form action
107 if ($this->form_action != "" && $this->getOpenFormTag()) {
108 $hash = "";
109
110 if ($this->form_multipart) {
111 $this->tpl->touchBlock("form_multipart_bl");
112 }
113
114 if ($this->getPreventDoubleSubmission()) {
115 $this->tpl->touchBlock("pdfs");
116 }
117
118 $this->tpl->setCurrentBlock("tbl_form_header");
119 $this->tpl->setVariable("FORMACTION", $this->getFormAction() . $hash);
120 $this->tpl->setVariable("FORMNAME", $this->getFormName());
121 $this->tpl->parseCurrentBlock();
122 }
123
124 if ($this->form_action != "" && $this->getCloseFormTag()) {
125 $this->tpl->touchBlock("tbl_form_footer");
126 }
127 }
128
129 if (!$this->enabled['content']) {
130 return $this->render();
131 }
132
133 if (!$this->getExternalSegmentation()) {
134 $this->setMaxCount(count($this->row_data));
135 }
136
138
139 $this->setFooter("tblfooter", $this->lng->txt("previous"), $this->lng->txt("next"));
140
141 $data = $this->getData();
142 if ($this->dataExists()) {
143 // sort
144 if (!$this->getExternalSorting() && $this->enabled["sort"]) {
146 $data,
147 $this->getOrderField(),
148 $this->getOrderDirection(),
149 $this->numericOrdering($this->getOrderField())
150 );
151 }
152
153 // slice
154 if (!$this->getExternalSegmentation()) {
155 $data = array_slice($data, $this->getOffset(), $this->getLimit());
156 }
157 }
158
159 // fill rows
160 if ($this->dataExists()) {
161 if ($this->getPrintMode()) {
163 }
164
165 $this->tpl->addBlockFile(
166 "TBL_CONTENT",
167 "tbl_content",
168 $this->row_template,
169 $this->row_template_dir
170 );
171
172 foreach ($data as $set) {
173 $this->tpl->setCurrentBlock("tbl_content");
174 $this->css_row = ($this->css_row !== "tblrow1")
175 ? "tblrow1"
176 : "tblrow2";
177 $this->tpl->setVariable("CSS_ROW", $this->css_row);
178
179 $this->fillRowFromObject($set);
180 $this->tpl->setCurrentBlock("tbl_content");
181 $this->tpl->parseCurrentBlock();
182 }
183 } else {
184 // add standard no items text (please tell me, if it messes something up, alex, 29.8.2008)
185 $no_items_text = (trim($this->getNoEntriesText()) != '')
186 ? $this->getNoEntriesText()
187 : $lng->txt("no_items");
188
189 $this->css_row = ($this->css_row !== "tblrow1")
190 ? "tblrow1"
191 : "tblrow2";
192
193 $this->tpl->setCurrentBlock("tbl_no_entries");
194 $this->tpl->setVariable('TBL_NO_ENTRY_CSS_ROW', $this->css_row);
195 $this->tpl->setVariable('TBL_NO_ENTRY_COLUMN_COUNT', $this->column_count);
196 $this->tpl->setVariable('TBL_NO_ENTRY_TEXT', trim($no_items_text));
197 $this->tpl->parseCurrentBlock();
198 }
199
200 if (!$this->getPrintMode()) {
201 $this->fillFooter();
202
203 $this->fillHiddenRow();
204
205 $this->fillActionRow();
206
207 $this->storeNavParameter();
208 }
209
210 return $this->render();
211 }
212
213 public function fillRowFromObject(ilDclBaseFieldModel $a_set): void
214 {
215 global $DIC;
216 $lng = $DIC['lng'];
217 $ilCtrl = $DIC['ilCtrl'];
218
219 if (!$a_set->isStandardField()) {
220 $this->tpl->setVariable('FIELD_ID', $a_set->getId());
221 }
222
223 $this->tpl->setVariable('NAME', 'order[' . $a_set->getId() . ']');
224 $this->tpl->setVariable('VALUE', $this->order);
225
226 /* Don't enable setting filter for MOB fields or reference fields that reference a MOB field */
227 $show_exportable = true;
228
229 if ($a_set->getId() == 'comments') {
230 $show_exportable = false;
231 }
232
233 if ($show_exportable) {
234 $this->tpl->setVariable('CHECKBOX_EXPORTABLE', 'exportable[' . $a_set->getId() . ']');
235 if ($a_set->getExportable()) {
236 $this->tpl->setVariable('CHECKBOX_EXPORTABLE_CHECKED', 'checked');
237 }
238 } else {
239 $this->tpl->setVariable('NO_FILTER_EXPORTABLE', '');
240 }
241
242 $this->order = $this->order + 10;
243 $this->tpl->setVariable('ORDER_NAME', 'order[' . $a_set->getId() . ']');
244 $this->tpl->setVariable('ORDER_VALUE', $this->order);
245
246 $this->tpl->setVariable('TITLE', $a_set->getTitle());
247 $this->tpl->setVariable('DESCRIPTION', $a_set->getDescription());
248 $this->tpl->setVariable('DATATYPE', $a_set->getPresentationTitle());
249
250 if (!$a_set->isStandardField()) {
251 switch ($a_set->isUnique()) {
252 case 0:
253 $icon = $this->factory->symbol()->icon()->custom(ilUtil::getImagePath('icon_not_ok_monochrome.svg'), $this->lng->txt("yes"));
254 break;
255 case 1:
256 $icon = $this->factory->symbol()->icon()->custom(ilUtil::getImagePath('icon_ok_monochrome.svg'), $this->lng->txt("no"));
257 break;
258 }
259 $this->tpl->setVariable('ICON_UNIQUE', $this->renderer->render($icon));
260 } else {
261 $this->tpl->setVariable('NO_UNIQUE', '');
262 }
263
264 $ilCtrl->setParameterByClass('ildclfieldeditgui', 'field_id', $a_set->getId());
265
266 if (!$a_set->isStandardField()) {
267 $alist = new ilAdvancedSelectionListGUI();
268 $alist->setId($a_set->getId());
269 $alist->setListTitle($lng->txt('actions'));
270
272 $this->parent_obj->getDataCollectionObject()->getRefId(),
273 $this->table->getId()
274 )) {
275 if (in_array($a_set->getDatatypeId(), array_keys(ilDclDatatype::getAllDatatype()))) {
276 $alist->addItem($lng->txt('edit'), 'edit', $ilCtrl->getLinkTargetByClass('ildclfieldeditgui', 'edit'));
277 }
278 $alist->addItem(
279 $lng->txt('delete'),
280 'delete',
281 $ilCtrl->getLinkTargetByClass('ildclfieldeditgui', 'confirmDelete')
282 );
283 }
284
285 $this->tpl->setVariable('ACTIONS', $alist->getHTML());
286 }
287 }
288}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static sortArray(array $array, string $a_array_sortby_key, string $a_array_sortorder="asc", bool $a_numeric=false, bool $a_keep_keys=false)
static setUseRelativeDates(bool $a_status)
set use relative dates
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getTableCache(int $table_id=null)
static getAllDatatype(bool $force=false)
Get all possible Datatypes.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(ilDclFieldListGUI $a_parent_obj, string $a_parent_cmd, int $table_id)
fillRowFromObject(ilDclBaseFieldModel $a_set)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
static hasAccessToFields(int $ref_id, int $table_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setShowRowsSelector(bool $a_value)
Toggle rows-per-page selector.
getFormName()
get the name of the parent form
prepareOutput()
Anything that must be done before HTML is generated.
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="")
setEnableTitle(bool $a_enabletitle)
setFormName(string $a_name="")
addMultiCommand(string $a_cmd, string $a_text)
setShowTemplates(bool $a_value)
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)
setSelectAllCheckbox(string $a_select_all_checkbox, bool $a_select_all_on_top=false)
numericOrdering(string $a_field)
Should this field be sorted numeric?
setTopCommands(bool $a_val)
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.
exportData(int $format, bool $send=false)
Export and optionally send current table data.
ilLanguage $lng
setStyle(string $a_element, string $a_style)
getStyle(string $a_element)
setMaxCount(int $a_max_count)
set max.
setFooter(string $a_style, string $a_previous="", string $a_next="")
static getImagePath(string $img, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
global $DIC
Definition: feed.php:28
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc