ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
class.ilDclFieldListTableGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 {
23  private ?int $order = null;
24 
25  protected ilDclTable $table;
26 
27  protected \ILIAS\UI\Renderer $renderer;
28  protected \ILIAS\UI\Factory $ui_factory;
29 
30 
31  public function __construct(ilDclFieldListGUI $a_parent_obj, string $a_parent_cmd, int $table_id)
32  {
33  global $DIC;
34 
35  $this->ui_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($this->lng->txt('dcl_order'), '', '30px');
47  $this->addColumn($this->lng->txt('dcl_fieldtitle'), '', 'auto');
48  $this->addColumn($this->lng->txt('dcl_in_export'), '', '30px');
49  $this->addColumn($this->lng->txt('dcl_description'), '', 'auto');
50  $this->addColumn($this->lng->txt('dcl_field_datatype'), '', 'auto');
51  $this->addColumn($this->lng->txt('dcl_unique'), '', 'auto');
52  $this->addColumn($this->lng->txt('actions'), '', '');
53  // Only add mutli command for custom fields
54  if (count($this->table->getRecordFields())) {
55  $this->setSelectAllCheckbox('dcl_field_ids[]');
56  $this->addMultiCommand('confirmDeleteFields', $this->lng->txt('dcl_delete_fields'));
57  }
58 
59  $this->ctrl->setParameterByClass('ildclfieldeditgui', 'table_id', $this->parent_obj->getTableId());
60  $this->ctrl->setParameterByClass('ildclfieldlistgui', 'table_id', $this->parent_obj->getTableId());
61 
62  $this->setFormAction($this->ctrl->getFormActionByClass('ildclfieldlistgui'));
63  $this->addCommandButton('save', $this->lng->txt('dcl_save'));
64 
65  $this->setFormAction($this->ctrl->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($this->table->getTitle());
81  $this->setRowTemplate('tpl.field_list_row.html', 'components/ILIAS/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  if ($this->getExportMode()) {
93  $this->exportData($this->getExportMode(), true);
94  }
95 
96  $this->prepareOutput();
97 
98  if (is_object($this->getParentObject()) && $this->getId() == "") {
99  $this->ctrl->saveParameter($this->getParentObject(), $this->getNavParameter());
100  }
101 
102  if (!$this->getPrintMode()) {
103  // set form action
104  if ($this->form_action != "" && $this->getOpenFormTag()) {
105  $hash = "";
106 
107  if ($this->form_multipart) {
108  $this->tpl->touchBlock("form_multipart_bl");
109  }
110 
111  if ($this->getPreventDoubleSubmission()) {
112  $this->tpl->touchBlock("pdfs");
113  }
114 
115  $this->tpl->setCurrentBlock("tbl_form_header");
116  $this->tpl->setVariable("FORMACTION", $this->getFormAction() . $hash);
117  $this->tpl->setVariable("FORMNAME", $this->getFormName());
118  $this->tpl->parseCurrentBlock();
119  }
120 
121  if ($this->form_action != "" && $this->getCloseFormTag()) {
122  $this->tpl->touchBlock("tbl_form_footer");
123  }
124  }
125 
126  if (!$this->enabled['content']) {
127  return $this->render();
128  }
129 
130  if (!$this->getExternalSegmentation()) {
131  $this->setMaxCount(count($this->row_data));
132  }
133 
134  $this->determineOffsetAndOrder();
135 
136  $this->setFooter("tblfooter", $this->lng->txt("previous"), $this->lng->txt("next"));
137 
138  $data = $this->getData();
139  if ($this->dataExists()) {
140  // sort
141  if (!$this->getExternalSorting() && $this->enabled["sort"]) {
142  $data = ilArrayUtil::sortArray(
143  $data,
144  $this->getOrderField(),
145  $this->getOrderDirection(),
146  $this->numericOrdering($this->getOrderField())
147  );
148  }
149 
150  // slice
151  if (!$this->getExternalSegmentation()) {
152  $data = array_slice($data, $this->getOffset(), $this->getLimit());
153  }
154  }
155 
156  // fill rows
157  if ($this->dataExists()) {
158  if ($this->getPrintMode()) {
160  }
161 
162  $this->tpl->addBlockFile(
163  "TBL_CONTENT",
164  "tbl_content",
165  $this->row_template,
166  $this->row_template_dir
167  );
168 
169  foreach ($data as $set) {
170  $this->tpl->setCurrentBlock("tbl_content");
171  $this->css_row = ($this->css_row !== "tblrow1")
172  ? "tblrow1"
173  : "tblrow2";
174  $this->tpl->setVariable("CSS_ROW", $this->css_row);
175 
176  $this->fillRowFromObject($set);
177  $this->tpl->setCurrentBlock("tbl_content");
178  $this->tpl->parseCurrentBlock();
179  }
180  } else {
181  // add standard no items text (please tell me, if it messes something up, alex, 29.8.2008)
182  $no_items_text = (trim($this->getNoEntriesText()) != '')
183  ? $this->getNoEntriesText()
184  : $this->lng->txt("no_items");
185 
186  $this->css_row = ($this->css_row !== "tblrow1")
187  ? "tblrow1"
188  : "tblrow2";
189 
190  $this->tpl->setCurrentBlock("tbl_no_entries");
191  $this->tpl->setVariable('TBL_NO_ENTRY_CSS_ROW', $this->css_row);
192  $this->tpl->setVariable('TBL_NO_ENTRY_COLUMN_COUNT', $this->column_count);
193  $this->tpl->setVariable('TBL_NO_ENTRY_TEXT', trim($no_items_text));
194  $this->tpl->parseCurrentBlock();
195  }
196 
197  if (!$this->getPrintMode()) {
198  $this->fillFooter();
199 
200  $this->fillHiddenRow();
201 
202  $this->fillActionRow();
203 
204  $this->storeNavParameter();
205  }
206 
207  return $this->render();
208  }
209 
210  public function fillRowFromObject(ilDclBaseFieldModel $a_set): void
211  {
212  if (!$a_set->isStandardField()) {
213  $this->tpl->setVariable('FIELD_ID', $a_set->getId());
214  }
215 
216  $this->tpl->setVariable('NAME', 'order[' . $a_set->getId() . ']');
217  $this->tpl->setVariable('VALUE', $this->order);
218 
219  /* Don't enable setting filter for MOB fields or reference fields that reference a MOB field */
220  $show_exportable = true;
221 
222  if ($a_set->getId() == 'comments') {
223  $show_exportable = false;
224  }
225 
226  if ($show_exportable) {
227  $this->tpl->setVariable('CHECKBOX_EXPORTABLE', 'exportable[' . $a_set->getId() . ']');
228  if ($a_set->getExportable()) {
229  $this->tpl->setVariable('CHECKBOX_EXPORTABLE_CHECKED', 'checked');
230  }
231  } else {
232  $this->tpl->setVariable('NO_FILTER_EXPORTABLE');
233  }
234 
235  $this->order = $this->order + 10;
236  $this->tpl->setVariable('ORDER_NAME', 'order[' . $a_set->getId() . ']');
237  $this->tpl->setVariable('ORDER_VALUE', $this->order);
238 
239  $this->tpl->setVariable('TITLE', $a_set->getTitle());
240  $this->tpl->setVariable('DESCRIPTION', $a_set->getDescription());
241  $this->tpl->setVariable('DATATYPE', $a_set->getPresentationTitle());
242 
243  if (!$a_set->isStandardField()) {
244  if ($a_set->isUnique()) {
245  $icon = $this->ui_factory->symbol()->icon()->custom(ilUtil::getImagePath('standard/icon_checked.svg'), $this->lng->txt("yes"));
246  } else {
247  $icon = $this->ui_factory->symbol()->icon()->custom(ilUtil::getImagePath('standard/icon_unchecked.svg'), $this->lng->txt("no"));
248  }
249  $this->tpl->setVariable('ICON_UNIQUE', $this->renderer->render($icon));
250  } else {
251  $this->tpl->setVariable('NO_UNIQUE');
252  }
253 
254  $this->ctrl->setParameterByClass('ildclfieldeditgui', 'field_id', $a_set->getId());
255 
256  if (!$a_set->isStandardField()) {
258  $this->parent_obj->getDataCollectionObject()->getRefId(),
259  $this->table->getId()
260  )) {
261  $dropdown_items = [];
262  if (in_array($a_set->getDatatypeId(), array_keys(ilDclDatatype::getAllDatatype()))) {
263  $dropdown_items[] = $this->ui_factory->link()->standard(
264  $this->lng->txt('edit'),
265  $this->ctrl->getLinkTargetByClass(ilDclFieldEditGUI::class, 'edit')
266  );
267  }
268  $dropdown_items[] = $this->ui_factory->link()->standard(
269  $this->lng->txt('delete'),
270  $this->ctrl->getLinkTargetByClass(ilDclFieldEditGUI::class, 'confirmDelete')
271  );
272  $dropdown = $this->ui_factory->dropdown()->standard($dropdown_items)->withLabel($this->lng->txt('actions'));
273 
274  $this->tpl->setVariable('ACTIONS', $this->renderer->render($dropdown));
275  } else {
276  $this->tpl->setVariable('ACTIONS');
277  }
278  }
279  }
280 }
setData(array $a_data)
numericOrdering(string $a_field)
Should this field be sorted numeric?
static array static setUseRelativeDates(bool $a_status)
set use relative dates
prepareOutput()
Anything that must be done before HTML is generated.
setTopCommands(bool $a_val)
getStyle(string $a_element)
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)
setShowTemplates(bool $a_value)
setFormName(string $a_name="")
setId(string $a_val)
exportData(int $format, bool $send=false)
Export and optionally send current table data.
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.
global $DIC
Definition: shib_login.php:25
static getImagePath(string $image_name, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
setDefaultOrderDirection(string $a_defaultorderdirection)
getDescription()
Get description.
setTitle(string $a_title, string $a_icon="", string $a_icon_alt="")
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)
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)