ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilDclCreateViewTableGUI.php
Go to the documentation of this file.
1 <?php
2 
20 {
21  public const VALID_DEFAULT_VALUE_TYPES = [
25  ];
26 
27  public function __construct(ilDclCreateViewDefinitionGUI $a_parent_obj)
28  {
29  parent::__construct($a_parent_obj);
30  $ilCtrl = $this->ctrl;
31  $lng = $this->lng;
32 
33  $this->setId('dcl_tableviews');
34  $this->setTitle($lng->txt('dcl_tableview_fieldsettings'));
35  $this->addColumn($lng->txt('dcl_tableview_fieldtitle'), "", 'auto');
36  $this->addColumn($lng->txt('dcl_tableview_field_access'), "", 'auto');
37  $this->addColumn($lng->txt('dcl_tableview_default_value'), "", 'auto');
38 
39  $ilCtrl->saveParameter($this, 'tableview_id');
40  $this->setFormAction($ilCtrl->getFormActionByClass('ildclcreateviewdefinitiongui'));
41  $this->addCommandButton('saveTable', $lng->txt('dcl_save'));
42 
43  $this->setExternalSegmentation(true);
44  $this->setExternalSorting(true);
45 
46  $this->setRowTemplate('tpl.tableview_create_view.html', 'Modules/DataCollection');
47  $this->setTopCommands(true);
48  $this->setEnableHeader(true);
49  $this->setShowRowsSelector(false);
50  $this->setShowTemplates(false);
51  $this->setEnableHeader(true);
52  $this->setEnableTitle(true);
53  $this->setDefaultOrderDirection('asc');
54 
55  $this->parseData($a_parent_obj->tableview->getFieldSettings());
56  }
57 
58  public function parseData(array $data): void
59  {
60  $this->setData($data);
61  }
62 
66  public function getHTML(): string
67  {
68  $lng = $this->lng;
69  $ilCtrl = $this->ctrl;
70 
71  if ($this->getExportMode()) {
72  $this->exportData($this->getExportMode(), true);
73  }
74  $this->prepareOutput();
75  if (is_object($ilCtrl) && is_object($this->getParentObject()) && $this->getId() == "") {
76  $ilCtrl->saveParameter($this->getParentObject(), $this->getNavParameter());
77  }
78  if (!$this->getPrintMode()) {
79  // set form action
80  if ($this->form_action != "" && $this->getOpenFormTag()) {
81  $hash = "";
82 
83  if ($this->form_multipart) {
84  $this->tpl->touchBlock("form_multipart_bl");
85  }
86 
87  if ($this->getPreventDoubleSubmission()) {
88  $this->tpl->touchBlock("pdfs");
89  }
90 
91  $this->tpl->setCurrentBlock("tbl_form_header");
92  $this->tpl->setVariable("FORMACTION", $this->getFormAction() . $hash);
93  $this->tpl->setVariable("FORMNAME", $this->getFormName());
94  $this->tpl->parseCurrentBlock();
95  }
96 
97  if ($this->form_action != "" && $this->getCloseFormTag()) {
98  $this->tpl->touchBlock("tbl_form_footer");
99  }
100  }
101  if (!$this->enabled['content']) {
102  return $this->render();
103  }
104  if (!$this->getExternalSegmentation()) {
105  $this->setMaxCount(count($this->row_data));
106  }
107  $this->determineOffsetAndOrder();
108  $this->setFooter("tblfooter", $this->lng->txt("previous"), $this->lng->txt("next"));
109 
110  $data = $this->getData();
111  if ($this->dataExists()) {
112  // sort
113  if (!$this->getExternalSorting() && $this->enabled["sort"]) {
114  $data = ilArrayUtil::sortArray(
115  $data,
116  $this->getOrderField(),
117  $this->getOrderDirection(),
118  $this->numericOrdering($this->getOrderField())
119  );
120  }
121  // slice
122  if (!$this->getExternalSegmentation()) {
123  $data = array_slice($data, $this->getOffset(), $this->getLimit());
124  }
125  }
126 
127  // fill rows
128  if ($this->dataExists()) {
129  if ($this->getPrintMode()) {
131  }
132  $this->tpl->addBlockFile(
133  "TBL_CONTENT",
134  "tbl_content",
135  $this->row_template,
136  $this->row_template_dir
137  );
138  foreach ($data as $set) {
139  $this->tpl->setCurrentBlock("tbl_content");
140  $this->css_row = ($this->css_row !== "tblrow1")
141  ? "tblrow1"
142  : "tblrow2";
143  $this->tpl->setVariable("CSS_ROW", $this->css_row);
144  $this->fillRowFromObject($set);
145  $this->tpl->setCurrentBlock("tbl_content");
146  $this->tpl->parseCurrentBlock();
147  }
148  } else {
149  // add standard no items text (please tell me, if it messes something up, alex, 29.8.2008)
150  $no_items_text = (trim($this->getNoEntriesText()) != '')
151  ? $this->getNoEntriesText()
152  : $lng->txt("no_items");
153  $this->css_row = ($this->css_row !== "tblrow1")
154  ? "tblrow1"
155  : "tblrow2";
156  $this->tpl->setCurrentBlock("tbl_no_entries");
157  $this->tpl->setVariable('TBL_NO_ENTRY_CSS_ROW', $this->css_row);
158  $this->tpl->setVariable('TBL_NO_ENTRY_COLUMN_COUNT', $this->column_count);
159  $this->tpl->setVariable('TBL_NO_ENTRY_TEXT', trim($no_items_text));
160  $this->tpl->parseCurrentBlock();
161  }
162 
163  if (!$this->getPrintMode()) {
164  $this->fillFooter();
165  $this->fillHiddenRow();
166  $this->fillActionRow();
167  $this->storeNavParameter();
168  }
169  return $this->render();
170  }
171 
172  public function fillRowFromObject(ilDclTableViewFieldSetting $a_set): void
173  {
174  $lng = $this->lng;
175  $field = $a_set->getFieldObject();
176  $match = ilDclTableViewBaseDefaultValue::findSingle($field->getDataTypeId(), $a_set->getId());
177 
179  $item = ilDclCache::getFieldRepresentation($field)->getInputField(new ilPropertyFormGUI());
180 
181  if (!is_null($match)) {
182  if ($item instanceof ilDclCheckboxInputGUI) {
183  $item->setChecked($match->getValue());
184  } else {
185  $item->setValue($match->getValue());
186  }
187  }
188 
189  if (!$field->isStandardField()) {
190  $this->tpl->setVariable('TEXT_VISIBLE', $lng->txt('dcl_tableview_visible'));
191  $this->tpl->setVariable('TEXT_REQUIRED_VISIBLE', $lng->txt('dcl_tableview_required_visible'));
192  $this->tpl->setVariable('TEXT_LOCKED_VISIBLE', $lng->txt('dcl_tableview_locked_visible'));
193  $this->tpl->setVariable('TEXT_NOT_VISIBLE', $lng->txt('dcl_tableview_not_visible'));
194  $this->tpl->setVariable('IS_LOCKED', $a_set->isLockedCreate() ? 'checked' : '');
195  $this->tpl->setVariable('IS_REQUIRED', $a_set->isRequiredCreate() ? 'checked' : '');
196  $this->tpl->setVariable('DEFAULT_VALUE', $a_set->getDefaultValue());
197  $this->tpl->setVariable('IS_VISIBLE', $a_set->isVisibleCreate() ? 'checked' : '');
198  $this->tpl->setVariable('IS_NOT_VISIBLE', !$a_set->isVisibleCreate() ? 'checked' : '');
199  if (!is_null($item) && in_array($field->getDatatypeId(), self::VALID_DEFAULT_VALUE_TYPES)) {
200  $name = "default_" . $a_set->getId() . "_" . $field->getDatatypeId();
201  $item->setPostVar($name);
202  if ($item instanceof ilTextAreaInputGUI) {
203  $replacement_box = new ilTextInputGUI();
204  $replacement_box->setPostVar($item->getPostVar());
205  $replacement_box->setValue($item->getValue());
206  $this->tpl->setVariable('INPUT', $replacement_box->render());
207  } else {
208  $this->tpl->setVariable('INPUT', $item->render());
209  }
210 
211  // Workaround as empty checkboxes do not get posted
212  if ($item instanceof ilDclCheckboxInputGUI) {
213  $this->tpl->setVariable('EXTRA_INPUT', "<input type=\"hidden\" name=\"$name\" value=\"0\" />");
214  }
215  }
216  } else {
217  $this->tpl->setVariable('HIDDEN', 'hidden');
218  }
219 
220  $this->tpl->setVariable('FIELD_ID', $a_set->getField());
221  $this->tpl->setVariable('TITLE', $field->getTitle());
222  $this->tpl->parseCurrentBlock();
223  }
224 }
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)
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)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addCommandButton(string $a_cmd, string $a_text, string $a_onclick='', string $a_id="", string $a_class="")
setShowTemplates(bool $a_value)
__construct(ilDclCreateViewDefinitionGUI $a_parent_obj)
ilLanguage $lng
setId(string $a_val)
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...
static getFieldRepresentation(ilDclBaseFieldModel $field)
exportData(int $format, bool $send=false)
Export and optionally send current table data.
if($format !==null) $name
Definition: metadata.php:247
setExternalSorting(bool $a_val)
setShowRowsSelector(bool $a_value)
Toggle rows-per-page selector.
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
setDefaultOrderDirection(string $a_defaultorderdirection)
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)
This class represents a text area property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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)