ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
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('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->setEnableHeader(true);
53  $this->setEnableTitle(true);
54  $this->setDefaultOrderDirection('asc');
55 
56  $this->parseData($a_parent_obj->tableview->getFieldSettings());
57  }
58 
59  public function parseData(array $data): void
60  {
61  $this->setData($data);
62  }
63 
67  public function getHTML(): string
68  {
69  $lng = $this->lng;
70  $ilCtrl = $this->ctrl;
71 
72  if ($this->getExportMode()) {
73  $this->exportData($this->getExportMode(), true);
74  }
75  $this->prepareOutput();
76  if (is_object($this->getParentObject()) && $this->getId() == "") {
77  $ilCtrl->saveParameter($this->getParentObject(), $this->getNavParameter());
78  }
79  if (!$this->getPrintMode()) {
80  // set form action
81  if ($this->form_action != "" && $this->getOpenFormTag()) {
82  $hash = "";
83 
84  if ($this->form_multipart) {
85  $this->tpl->touchBlock("form_multipart_bl");
86  }
87 
88  if ($this->getPreventDoubleSubmission()) {
89  $this->tpl->touchBlock("pdfs");
90  }
91 
92  $this->tpl->setCurrentBlock("tbl_form_header");
93  $this->tpl->setVariable("FORMACTION", $this->getFormAction() . $hash);
94  $this->tpl->setVariable("FORMNAME", $this->getFormName());
95  $this->tpl->parseCurrentBlock();
96  }
97 
98  if ($this->form_action != "" && $this->getCloseFormTag()) {
99  $this->tpl->touchBlock("tbl_form_footer");
100  }
101  }
102  if (!$this->enabled['content']) {
103  return $this->render();
104  }
105  if (!$this->getExternalSegmentation()) {
106  $this->setMaxCount(count($this->row_data));
107  }
108  $this->determineOffsetAndOrder();
109  $this->setFooter("tblfooter", $this->lng->txt("previous"), $this->lng->txt("next"));
110 
111  $data = $this->getData();
112  if ($this->dataExists()) {
113  // sort
114  if (!$this->getExternalSorting() && $this->enabled["sort"]) {
115  $data = ilArrayUtil::sortArray(
116  $data,
117  $this->getOrderField(),
118  $this->getOrderDirection(),
119  $this->numericOrdering($this->getOrderField())
120  );
121  }
122  // slice
123  if (!$this->getExternalSegmentation()) {
124  $data = array_slice($data, $this->getOffset(), $this->getLimit());
125  }
126  }
127 
128  // fill rows
129  if ($this->dataExists()) {
130  if ($this->getPrintMode()) {
132  }
133  $this->tpl->addBlockFile(
134  "TBL_CONTENT",
135  "tbl_content",
136  $this->row_template,
137  $this->row_template_dir
138  );
139  foreach ($data as $set) {
140  $this->tpl->setCurrentBlock("tbl_content");
141  $this->css_row = ($this->css_row !== "tblrow1")
142  ? "tblrow1"
143  : "tblrow2";
144  $this->tpl->setVariable("CSS_ROW", $this->css_row);
145  $this->fillRowFromObject($set);
146  $this->tpl->setCurrentBlock("tbl_content");
147  $this->tpl->parseCurrentBlock();
148  }
149  } else {
150  // add standard no items text (please tell me, if it messes something up, alex, 29.8.2008)
151  $no_items_text = (trim($this->getNoEntriesText()) != '')
152  ? $this->getNoEntriesText()
153  : $lng->txt("no_items");
154  $this->css_row = ($this->css_row !== "tblrow1")
155  ? "tblrow1"
156  : "tblrow2";
157  $this->tpl->setCurrentBlock("tbl_no_entries");
158  $this->tpl->setVariable('TBL_NO_ENTRY_CSS_ROW', $this->css_row);
159  $this->tpl->setVariable('TBL_NO_ENTRY_COLUMN_COUNT', $this->column_count);
160  $this->tpl->setVariable('TBL_NO_ENTRY_TEXT', trim($no_items_text));
161  $this->tpl->parseCurrentBlock();
162  }
163 
164  if (!$this->getPrintMode()) {
165  $this->fillFooter();
166  $this->fillHiddenRow();
167  $this->fillActionRow();
168  $this->storeNavParameter();
169  }
170  return $this->render();
171  }
172 
173  public function fillRowFromObject(ilDclTableViewFieldSetting $a_set): void
174  {
175  $lng = $this->lng;
176  $field = $a_set->getFieldObject();
177  $match = ilDclTableViewBaseDefaultValue::findSingle($field->getDatatypeId(), $a_set->getId());
178 
180  $item = ilDclCache::getFieldRepresentation($field)->getInputField(new ilPropertyFormGUI());
181 
182  if (!is_null($match)) {
183  if ($item instanceof ilDclCheckboxInputGUI) {
184  $item->setChecked((bool) $match->getValue());
185  } else {
186  $item->setValue((string) $match->getValue());
187  }
188  }
189 
190  if (!$field->isStandardField()) {
191  $this->tpl->setVariable('TEXT_VISIBLE', $lng->txt('dcl_tableview_visible'));
192  $this->tpl->setVariable('TEXT_REQUIRED_VISIBLE', $lng->txt('dcl_tableview_required_visible'));
193  $this->tpl->setVariable('TEXT_LOCKED_VISIBLE', $lng->txt('dcl_tableview_locked_visible'));
194  $this->tpl->setVariable('TEXT_NOT_VISIBLE', $lng->txt('dcl_tableview_not_visible'));
195  $this->tpl->setVariable('IS_LOCKED', $a_set->isLockedCreate() ? 'checked' : '');
196  $this->tpl->setVariable('IS_REQUIRED', $a_set->isRequiredCreate() ? 'checked' : '');
197  $this->tpl->setVariable('DEFAULT_VALUE', $a_set->getDefaultValue());
198  $this->tpl->setVariable('IS_VISIBLE', $a_set->isVisibleCreate() ? 'checked' : '');
199  $this->tpl->setVariable('IS_NOT_VISIBLE', !$a_set->isVisibleCreate() ? 'checked' : '');
200  if (!is_null($item) && in_array($field->getDatatypeId(), self::VALID_DEFAULT_VALUE_TYPES)) {
201  $name = "default_" . $a_set->getId() . "_" . $field->getDatatypeId();
202  $item->setPostVar($name);
203  if ($item instanceof ilTextAreaInputGUI) {
204  $replacement_box = new ilTextInputGUI();
205  $replacement_box->setPostVar($item->getPostVar());
206  $replacement_box->setValue($item->getValue());
207  $this->tpl->setVariable('INPUT', $replacement_box->render());
208  } else {
209  $this->tpl->setVariable('INPUT', $item->render());
210  }
211 
212  // Workaround as empty checkboxes do not get posted
213  if ($item instanceof ilDclCheckboxInputGUI) {
214  $this->tpl->setVariable('EXTRA_INPUT', "<input type=\"hidden\" name=\"$name\" value=\"0\" />");
215  }
216  }
217  } else {
218  $this->tpl->setVariable('HIDDEN', 'hidden');
219  }
220 
221  $this->tpl->setVariable('FIELD_ID', $a_set->getField());
222  $this->tpl->setVariable('TITLE', $field->getTitle());
223  $this->tpl->parseCurrentBlock();
224  }
225 }
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="")
__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)