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