ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
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  {
92  $lng = $this->lng;
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 
137  $this->determineOffsetAndOrder();
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"]) {
145  $data = ilArrayUtil::sortArray(
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 }
setData(array $a_data)
numericOrdering(string $a_field)
Should this field be sorted numeric?
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
prepareOutput()
Anything that must be done before HTML is generated.
setTopCommands(bool $a_val)
getStyle(string $a_element)
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...
setFormAction(string $a_form_action, bool $a_multipart=false)
setEnableTitle(bool $a_enabletitle)
addCommandButton(string $a_cmd, string $a_text, string $a_onclick='', string $a_id="", string $a_class="")
setSelectAllCheckbox(string $a_select_all_checkbox, bool $a_select_all_on_top=false)
static getImagePath(string $img, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
setShowTemplates(bool $a_value)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setFormName(string $a_name="")
ilLanguage $lng
setId(string $a_val)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
exportData(int $format, bool $send=false)
Export and optionally send current table data.
global $DIC
Definition: feed.php:28
fillRowFromObject(ilDclBaseFieldModel $a_set)
setStyle(string $a_element, string $a_style)
static hasAccessToFields(int $ref_id, int $table_id)
setExternalSorting(bool $a_val)
setShowRowsSelector(bool $a_value)
Toggle rows-per-page selector.
static getTableCache(int $table_id=null)
static getAllDatatype(bool $force=false)
Get all possible Datatypes.
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
setDefaultOrderDirection(string $a_defaultorderdirection)
getDescription()
Get description.
setTitle(string $a_title, string $a_icon="", string $a_icon_alt="")
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setFooter(string $a_style, string $a_previous="", string $a_next="")
__construct(Container $dic, ilPlugin $plugin)
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)
static setUseRelativeDates(bool $a_status)
set use relative dates
addMultiCommand(string $a_cmd, string $a_text)
__construct(ilDclFieldListGUI $a_parent_obj, string $a_parent_cmd, int $table_id)
determineOffsetAndOrder(bool $a_omit_offset=false)
setEnableHeader(bool $a_enableheader)
setMaxCount(int $a_max_count)
set max.
getDatatypeId()
Get datatype_id.
setExternalSegmentation(bool $a_val)
static sortArray(array $array, string $a_array_sortby_key, string $a_array_sortorder="asc", bool $a_numeric=false, bool $a_keep_keys=false)