ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilDclTableViewEditFieldsTableGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 {
23  public function __construct(ilDclTableViewEditGUI $a_parent_obj)
24  {
25  global $DIC;
26  $lng = $DIC['lng'];
27  $ilCtrl = $DIC['ilCtrl'];
28  parent::__construct($a_parent_obj);
29 
30  $this->setId('dcl_tableviews');
31  $this->setTitle($lng->txt('dcl_tableview_fieldsettings'));
32  $this->addColumn($lng->txt('dcl_fieldtitle'), "", 'auto');
33  $this->addColumn($lng->txt('dcl_field_visible'), "", 'auto');
34  $this->addColumn($lng->txt('dcl_filter'), "", 'auto');
35  $this->addColumn($lng->txt('dcl_std_filter'), "", 'auto');
36  $this->addColumn($lng->txt('dcl_filter_changeable'), "", 'auto');
37 
38  $ilCtrl->saveParameter($this, 'tableview_id');
39  $this->setFormAction($ilCtrl->getFormActionByClass(ilDclTableViewEditGUI::class));
40  $this->addCommandButton('saveTable', $lng->txt('dcl_save'));
41 
42  $this->setExternalSegmentation(true);
43  $this->setExternalSorting(true);
44 
45  $this->setRowTemplate('tpl.tableview_fields_row.html', 'Modules/DataCollection');
46  $this->setTopCommands(true);
47  $this->setEnableHeader(true);
48  $this->setShowRowsSelector(false);
49  $this->setShowTemplates(false);
50  $this->setEnableHeader(true);
51  $this->setEnableTitle(true);
52  $this->setDefaultOrderDirection('asc');
53 
54  $this->parseData($a_parent_obj->tableview->getFieldSettings());
55  }
56 
57  public function parseData(array $data): void
58  {
59  //enable/disable comments
60  if (!$this->parent_obj->table->getPublicCommentsEnabled()) {
61  foreach ($data as $key => $rec) {
62  if ($rec->getField() == 'comments') {
63  unset($data[$key]);
64  }
65  }
66  }
67  $this->setData($data);
68  }
69 
73  public function getHTML(): string
74  {
75  $lng = $this->lng;
76  $ilCtrl = $this->ctrl;
77 
78  if ($this->getExportMode()) {
79  $this->exportData($this->getExportMode(), true);
80  }
81 
82  $this->prepareOutput();
83 
84  if (is_object($this->getParentObject()) && $this->getId() == "") {
85  $ilCtrl->saveParameter($this->getParentObject(), $this->getNavParameter());
86  }
87 
88  if (!$this->getPrintMode()) {
89  // set form action
90  if ($this->form_action != "" && $this->getOpenFormTag()) {
91  $hash = "";
92 
93  if ($this->form_multipart) {
94  $this->tpl->touchBlock("form_multipart_bl");
95  }
96 
97  if ($this->getPreventDoubleSubmission()) {
98  $this->tpl->touchBlock("pdfs");
99  }
100 
101  $this->tpl->setCurrentBlock("tbl_form_header");
102  $this->tpl->setVariable("FORMACTION", $this->getFormAction() . $hash);
103  $this->tpl->setVariable("FORMNAME", $this->getFormName());
104  $this->tpl->parseCurrentBlock();
105  }
106 
107  if ($this->form_action != "" && $this->getCloseFormTag()) {
108  $this->tpl->touchBlock("tbl_form_footer");
109  }
110  }
111 
112  if (!$this->enabled['content']) {
113  return $this->render();
114  }
115 
116  if (!$this->getExternalSegmentation()) {
117  $this->setMaxCount(count($this->row_data));
118  }
119 
120  $this->determineOffsetAndOrder();
121 
122  $this->setFooter("tblfooter", $this->lng->txt("previous"), $this->lng->txt("next"));
123 
124  $data = $this->getData();
125  if ($this->dataExists()) {
126  // sort
127  if (!$this->getExternalSorting() && $this->enabled["sort"]) {
128  $data = ilArrayUtil::sortArray(
129  $data,
130  $this->getOrderField(),
131  $this->getOrderDirection(),
132  $this->numericOrdering($this->getOrderField())
133  );
134  }
135 
136  // slice
137  if (!$this->getExternalSegmentation()) {
138  $data = array_slice($data, $this->getOffset(), $this->getLimit());
139  }
140  }
141 
142  // fill rows
143  if ($this->dataExists()) {
144  if ($this->getPrintMode()) {
146  }
147 
148  $this->tpl->addBlockFile(
149  "TBL_CONTENT",
150  "tbl_content",
151  $this->row_template,
152  $this->row_template_dir
153  );
154 
155  foreach ($data as $set) {
156  $this->tpl->setCurrentBlock("tbl_content");
157  $this->css_row = ($this->css_row !== "tblrow1")
158  ? "tblrow1"
159  : "tblrow2";
160  $this->tpl->setVariable("CSS_ROW", $this->css_row);
161 
162  $this->fillRowFromObject($set);
163  $this->tpl->setCurrentBlock("tbl_content");
164  $this->tpl->parseCurrentBlock();
165  }
166  } else {
167  // add standard no items text (please tell me, if it messes something up, alex, 29.8.2008)
168  $no_items_text = (trim($this->getNoEntriesText()) != '')
169  ? $this->getNoEntriesText()
170  : $lng->txt("no_items");
171 
172  $this->css_row = ($this->css_row !== "tblrow1")
173  ? "tblrow1"
174  : "tblrow2";
175 
176  $this->tpl->setCurrentBlock("tbl_no_entries");
177  $this->tpl->setVariable('TBL_NO_ENTRY_CSS_ROW', $this->css_row);
178  $this->tpl->setVariable('TBL_NO_ENTRY_COLUMN_COUNT', $this->column_count);
179  $this->tpl->setVariable('TBL_NO_ENTRY_TEXT', trim($no_items_text));
180  $this->tpl->parseCurrentBlock();
181  }
182 
183  if (!$this->getPrintMode()) {
184  $this->fillFooter();
185 
186  $this->fillHiddenRow();
187 
188  $this->fillActionRow();
189 
190  $this->storeNavParameter();
191  }
192 
193  return $this->render();
194  }
195 
199  public function fillRowFromObject(object $a_set): void
200  {
201  $field = $a_set->getFieldObject();
202  if ($field->getId() == 'comments' && !$this->parent_obj->table->getPublicCommentsEnabled()) {
203  return;
204  }
205 
206  $this->tpl->setVariable('FIELD_TITLE', $field->getTitle());
207  $this->tpl->setVariable('ID', $a_set->getId());
208  $this->tpl->setVariable('FIELD_ID', $a_set->getField());
209  $this->tpl->setVariable('VISIBLE', $a_set->isVisibleInList() ? 'checked' : '');
210  if ($field->allowFilterInListView()) {
211  $this->tpl->setVariable('IN_FILTER', $a_set->isInFilter() ? 'checked' : '');
212  $this->tpl->setVariable('FILTER_VALUE', $this->getStandardFilterHTML($field, $a_set->getFilterValue()));
213  $this->tpl->setVariable('FILTER_CHANGEABLE', $a_set->isFilterChangeable() ? 'checked' : '');
214  } else {
215  $this->tpl->setVariable('NO_FILTER');
216  }
217  }
218 
222  protected function getStandardFilterHTML(ilDclBaseFieldModel $field, array $value): string
223  {
224  $field_representation = ilDclFieldFactory::getFieldRepresentationInstance($field);
225  $field_representation->addFilterInputFieldToTable($this);
226  $filter = end($this->filters);
227  $this->filters = [];
228  $filter->setValueByArray($value);
229 
230  return $filter->render();
231  }
232 }
setData(array $a_data)
numericOrdering(string $a_field)
Should this field be sorted numeric?
prepareOutput()
Anything that must be done before HTML is generated.
setTopCommands(bool $a_val)
ilDclTableViewEditGUI: ilDclDetailedViewDefinitionGUI ilDclTableViewEditGUI: ilDclCreateViewDefiniti...
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)
static getFieldRepresentationInstance(ilDclBaseFieldModel $field)
addCommandButton(string $a_cmd, string $a_text, string $a_onclick='', string $a_id="", string $a_class="")
setShowTemplates(bool $a_value)
ilLanguage $lng
setId(string $a_val)
exportData(int $format, bool $send=false)
Export and optionally send current table data.
global $DIC
Definition: feed.php:28
setExternalSorting(bool $a_val)
setShowRowsSelector(bool $a_value)
Toggle rows-per-page selector.
__construct(VocabulariesInterface $vocabularies)
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
string $key
Consumer key/client ID value.
Definition: System.php:193
setDefaultOrderDirection(string $a_defaultorderdirection)
getStandardFilterHTML(ilDclBaseFieldModel $field, array $value)
__construct(ilDclTableViewEditGUI $a_parent_obj)
setTitle(string $a_title, string $a_icon="", string $a_icon_alt="")
setFooter(string $a_style, string $a_previous="", string $a_next="")
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
determineOffsetAndOrder(bool $a_omit_offset=false)
setEnableHeader(bool $a_enableheader)
setMaxCount(int $a_max_count)
set max.
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)