ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilDclTableListTableGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 {
23  protected \ILIAS\UI\Factory $ui_factory;
24  protected \ILIAS\UI\Renderer $renderer;
25 
30  {
31  global $DIC;
32 
33  $this->ui_factory = $DIC->ui()->factory();
34  $this->renderer = $DIC->ui()->renderer();
35 
36  parent::__construct($parent_obj);
37 
38  $this->parent_obj = $parent_obj;
39 
40  $this->setId('dcl_table_list');
41  $this->addColumn('', '', '1', true);
42  $this->addColumn($this->lng->txt('dcl_order'), "", '30px');
43  $this->addColumn($this->lng->txt('title'), "", 'auto');
44  $this->addColumn($this->lng->txt('dcl_visible'), "", '250px', false, '', $this->lng->txt('dcl_visible_desc'));
45  $this->addColumn(
46  $this->lng->txt('dcl_comments'),
47  "",
48  '200px',
49  false,
50  '',
51  $this->lng->txt('dcl_public_comments_desc')
52  );
53  $this->addColumn($this->lng->txt('actions'), "", '');
54 
55  $this->setSelectAllCheckbox('dcl_table_ids[]');
56  $this->addMultiCommand('confirmDeleteTables', $this->lng->txt('dcl_delete_tables'));
57 
58  $this->setFormAction($this->ctrl->getFormActionByClass(ilDclTableListGUI::class));
59  $this->addCommandButton('save', $this->lng->txt('dcl_save'));
60 
61  $this->setFormAction($this->ctrl->getFormAction($parent_obj));
62  $this->setFormName('table_list');
63 
64  //those two are important as we get our data as objects not as arrays.
65  $this->setExternalSegmentation(true);
66  $this->setExternalSorting(true);
67 
68  $this->setTopCommands(true);
69  $this->setEnableHeader(true);
70  $this->setShowRowsSelector(false);
71  $this->setShowTemplates(false);
72  $this->setEnableHeader(true);
73  $this->setEnableTitle(true);
74  $this->setTitle($this->lng->txt('dcl_table_list_tables'));
75  $this->setDefaultOrderDirection('asc');
76 
77  $this->setRowTemplate('tpl.table_list_row.html', 'Modules/DataCollection');
78  $this->setStyle('table', $this->getStyle('table') . ' ' . 'dcl_record_list');
79 
80  $tables = $this->parent_obj->getDataCollectionObject()->getTables();
81  $this->setData($tables);
82  }
83 
87  public function getHTML(): string
88  {
89  if ($this->getExportMode()) {
90  $this->exportData($this->getExportMode(), true);
91  }
92 
93  $this->prepareOutput();
94 
95  if (is_object($this->getParentObject()) && $this->getId() == "") {
96  $this->ctrl->saveParameter($this->getParentObject(), $this->getNavParameter());
97  }
98 
99  if (!$this->getPrintMode()) {
100  // set form action
101  if ($this->form_action != "" && $this->getOpenFormTag()) {
102  $hash = "";
103 
104  if ($this->form_multipart) {
105  $this->tpl->touchBlock("form_multipart_bl");
106  }
107 
108  if ($this->getPreventDoubleSubmission()) {
109  $this->tpl->touchBlock("pdfs");
110  }
111 
112  $this->tpl->setCurrentBlock("tbl_form_header");
113  $this->tpl->setVariable("FORMACTION", $this->getFormAction() . $hash);
114  $this->tpl->setVariable("FORMNAME", $this->getFormName());
115  $this->tpl->parseCurrentBlock();
116  }
117 
118  if ($this->form_action != "" && $this->getCloseFormTag()) {
119  $this->tpl->touchBlock("tbl_form_footer");
120  }
121  }
122 
123  if (!$this->enabled['content']) {
124  return $this->render();
125  }
126 
127  if (!$this->getExternalSegmentation()) {
128  $this->setMaxCount(count($this->row_data));
129  }
130 
131  $this->determineOffsetAndOrder();
132 
133  $this->setFooter("tblfooter", $this->lng->txt("previous"), $this->lng->txt("next"));
134 
135  $data = $this->getData();
136  if ($this->dataExists()) {
137  // sort
138  if (!$this->getExternalSorting() && $this->enabled["sort"]) {
139  $data = ilArrayUtil::sortArray(
140  $data,
141  $this->getOrderField(),
142  $this->getOrderDirection(),
143  $this->numericOrdering($this->getOrderField())
144  );
145  }
146 
147  // slice
148  if (!$this->getExternalSegmentation()) {
149  $data = array_slice($data, $this->getOffset(), $this->getLimit());
150  }
151  }
152 
153  // fill rows
154  if ($this->dataExists()) {
155  if ($this->getPrintMode()) {
157  }
158 
159  $this->tpl->addBlockFile(
160  "TBL_CONTENT",
161  "tbl_content",
162  $this->row_template,
163  $this->row_template_dir
164  );
165 
166  foreach ($data as $set) {
167  $this->tpl->setCurrentBlock("tbl_content");
168  $this->css_row = ($this->css_row !== "tblrow1")
169  ? "tblrow1"
170  : "tblrow2";
171  $this->tpl->setVariable("CSS_ROW", $this->css_row);
172 
173  $this->fillRowFromObject($set);
174  $this->tpl->setCurrentBlock("tbl_content");
175  $this->tpl->parseCurrentBlock();
176  }
177  } else {
178  // add standard no items text (please tell me, if it messes something up, alex, 29.8.2008)
179  $no_items_text = (trim($this->getNoEntriesText()) != '')
180  ? $this->getNoEntriesText()
181  : $this->lng->txt("no_items");
182 
183  $this->css_row = ($this->css_row !== "tblrow1")
184  ? "tblrow1"
185  : "tblrow2";
186 
187  $this->tpl->setCurrentBlock("tbl_no_entries");
188  $this->tpl->setVariable('TBL_NO_ENTRY_CSS_ROW', $this->css_row);
189  $this->tpl->setVariable('TBL_NO_ENTRY_COLUMN_COUNT', $this->column_count);
190  $this->tpl->setVariable('TBL_NO_ENTRY_TEXT', trim($no_items_text));
191  $this->tpl->parseCurrentBlock();
192  }
193 
194  if (!$this->getPrintMode()) {
195  $this->fillFooter();
196 
197  $this->fillHiddenRow();
198 
199  $this->fillActionRow();
200 
201  $this->storeNavParameter();
202  }
203 
204  return $this->render();
205  }
206 
207  public function fillRowFromObject(ilDclTable $a_set): void
208  {
209  $this->tpl->setVariable("ID", $a_set->getId());
210  $this->tpl->setVariable("ORDER_NAME", "order[{$a_set->getId()}]");
211  $this->tpl->setVariable("ORDER_VALUE", $a_set->getOrder());
212  $this->tpl->setVariable("TITLE", $a_set->getTitle());
213 
214  $this->ctrl->setParameterByClass(ilDclFieldListGUI::class, 'table_id', $a_set->getId());
215  $this->tpl->setVariable("TITLE_LINK", $this->ctrl->getLinkTargetByClass(ilDclFieldListGUI::class));
216 
217  $this->tpl->setVariable("CHECKBOX_NAME_VISIBLE", 'visible[' . $a_set->getId() . ']');
218  if ($a_set->getIsVisible()) {
219  $this->tpl->setVariable("CHECKBOX_CHECKED_VISIBLE", 'checked');
220  }
221  $this->tpl->setVariable("CHECKBOX_NAME_COMMENTS", 'comments[' . $a_set->getId() . ']');
222  if ($a_set->getPublicCommentsEnabled()) {
223  $this->tpl->setVariable("CHECKBOX_CHECKED_COMMENTS", 'checked');
224  }
225  $this->tpl->setVariable('ACTIONS', $this->buildActions($a_set->getId()));
226  }
227 
228  protected function buildActions(int $id): string
229  {
230  $dropdown_items = [];
231 
232  $this->ctrl->setParameterByClass(ilDclFieldListGUI::class, 'table_id', $id);
233  $this->ctrl->setParameterByClass(ilDclTableViewGUI::class, 'table_id', $id);
234  $this->ctrl->setParameterByClass(ilDclTableEditGUI::class, 'table_id', $id);
235 
236  $dropdown_items[] = $this->ui_factory->link()->standard(
237  $this->lng->txt('settings'),
238  $this->ctrl->getLinkTargetByClass(ilDclTableEditGUI::class, 'edit')
239  );
240  $dropdown_items[] = $this->ui_factory->link()->standard(
241  $this->lng->txt('dcl_list_fields'),
242  $this->ctrl->getLinkTargetByClass(ilDclFieldListGUI::class, 'listFields')
243  );
244  $dropdown_items[] = $this->ui_factory->link()->standard(
245  $this->lng->txt('dcl_tableviews'),
246  $this->ctrl->getLinkTargetByClass(ilDclTableViewGUI::class)
247  );
248  $dropdown_items[] = $this->ui_factory->link()->standard(
249  $this->lng->txt('delete'),
250  $this->ctrl->getLinkTargetByClass(ilDclTableEditGUI::class, 'confirmDelete')
251  );
252 
253  $dropdown = $this->ui_factory->dropdown()->standard($dropdown_items)->withLabel($this->lng->txt('actions'));
254 
255  return $this->renderer->render($dropdown);
256  }
257 }
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)
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)
ilDclTableListGUI: ilDclFieldListGUI, ilDclFieldEditGUI, ilDclTableViewGUI, ilDclTableEditGUI ...
getId()
Get table id.
setFormName(string $a_name="")
setId(string $a_val)
exportData(int $format, bool $send=false)
Export and optionally send current table data.
global $DIC
Definition: feed.php:28
setStyle(string $a_element, string $a_style)
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.
setDefaultOrderDirection(string $a_defaultorderdirection)
setTitle(string $a_title, string $a_icon="", string $a_icon_alt="")
__construct(ilDclTableListGUI $parent_obj)
ilDclTableListTableGUI constructor.
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
addMultiCommand(string $a_cmd, string $a_text)
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)