ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilDclTableViewTableGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 {
23  protected ilDclTable $table;
24 
25  protected \ILIAS\UI\Renderer $renderer;
26  protected \ILIAS\UI\Factory $ui_factory;
27 
28  public function __construct(object $a_parent_obj, string $a_parent_cmd, ilDclTable $table, int $ref_id)
29  {
30  global $DIC;
31 
32  $this->ui_factory = $DIC->ui()->factory();
33  $this->renderer = $DIC->ui()->renderer();
34 
35  parent::__construct($a_parent_obj, $a_parent_cmd);
36 
37  $this->parent_obj = $a_parent_obj;
38  $this->table = $table;
39  $this->ctrl = $DIC->ctrl();
40  $this->lng = $DIC->language();
41 
42  $this->setExternalSegmentation(true);
43  $this->setExternalSorting(true);
44 
45  if ($this->parent_obj instanceof ilDclTableViewGUI) {
46  $this->ctrl->setParameterByClass(ilDclTableViewGUI::class, 'table_id', $table->getId());
47  $this->setFormAction($this->ctrl->getFormActionByClass(ilDclTableViewGUI::class));
48  $this->addMultiCommand('confirmDeleteTableviews', $this->lng->txt('dcl_delete_views'));
49  $this->addCommandButton('saveTableViewOrder', $this->lng->txt('dcl_save_order'));
50 
51  $this->setFormAction($this->ctrl->getFormAction($a_parent_obj));
52  $this->setFormName('tableview_list');
53 
54  $this->addColumn('', '', '1', true);
55  $this->addColumn($this->lng->txt('dcl_order'), '', '30px');
56 
57  $this->setRowTemplate('tpl.tableview_list_row.html', 'Modules/DataCollection');
58  $this->setData($this->table->getTableViews());
59  } elseif ($this->parent_obj instanceof ilDclDetailedViewGUI) {
60  $this->setRowTemplate('tpl.detailview_list_row.html', 'Modules/DataCollection');
61  $this->setData($this->table->getVisibleTableViews(0, true));
62  }
63 
64  $this->addColumn($this->lng->txt('title'), '', 'auto');
65  $this->addColumn($this->lng->txt('description'), '', 'auto');
66  $this->addColumn($this->lng->txt('actions'), '', '30px');
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->setDefaultOrderDirection('asc');
75  $this->setLimit();
76 
77  $this->setId('dcl_tableviews');
78  $this->setTitle($this->table->getTitle());
79  $this->setStyle('table', $this->getStyle('table') . ' ' . 'dcl_record_list');
80  }
81 
85  public function getHTML(): string
86  {
87  if ($this->getExportMode()) {
88  $this->exportData($this->getExportMode(), true);
89  }
90 
91  $this->prepareOutput();
92 
93  if (is_object($this->getParentObject()) && $this->getId() == "") {
94  $this->ctrl->saveParameter($this->getParentObject(), $this->getNavParameter());
95  }
96 
97  if (!$this->getPrintMode()) {
98  // set form action
99  if ($this->form_action != "" && $this->getOpenFormTag()) {
100  $hash = "";
101 
102  if ($this->form_multipart) {
103  $this->tpl->touchBlock("form_multipart_bl");
104  }
105 
106  if ($this->getPreventDoubleSubmission()) {
107  $this->tpl->touchBlock("pdfs");
108  }
109 
110  $this->tpl->setCurrentBlock("tbl_form_header");
111  $this->tpl->setVariable("FORMACTION", $this->getFormAction() . $hash);
112  $this->tpl->setVariable("FORMNAME", $this->getFormName());
113  $this->tpl->parseCurrentBlock();
114  }
115 
116  if ($this->form_action != "" && $this->getCloseFormTag()) {
117  $this->tpl->touchBlock("tbl_form_footer");
118  }
119  }
120 
121  if (!$this->enabled['content']) {
122  return $this->render();
123  }
124 
125  if (!$this->getExternalSegmentation()) {
126  $this->setMaxCount(count($this->row_data));
127  }
128 
129  $this->determineOffsetAndOrder();
130 
131  $this->setFooter("tblfooter", $this->lng->txt("previous"), $this->lng->txt("next"));
132 
133  $data = $this->getData();
134  if ($this->dataExists()) {
135  // sort
136  if (!$this->getExternalSorting() && $this->enabled["sort"]) {
137  $data = ilArrayUtil::sortArray(
138  $data,
139  $this->getOrderField(),
140  $this->getOrderDirection(),
141  $this->numericOrdering($this->getOrderField())
142  );
143  }
144 
145  // slice
146  if (!$this->getExternalSegmentation()) {
147  $data = array_slice($data, $this->getOffset(), $this->getLimit());
148  }
149  }
150 
151  // fill rows
152  if ($this->dataExists()) {
153  if ($this->getPrintMode()) {
155  }
156 
157  $this->tpl->addBlockFile(
158  "TBL_CONTENT",
159  "tbl_content",
160  $this->row_template,
161  $this->row_template_dir
162  );
163 
164  foreach ($data as $set) {
165  $this->tpl->setCurrentBlock("tbl_content");
166  $this->css_row = ($this->css_row !== "tblrow1")
167  ? "tblrow1"
168  : "tblrow2";
169  $this->tpl->setVariable("CSS_ROW", $this->css_row);
170 
171  $this->fillRowFromObject($set);
172  $this->tpl->setCurrentBlock("tbl_content");
173  $this->tpl->parseCurrentBlock();
174  }
175  } else {
176  // add standard no items text (please tell me, if it messes something up, alex, 29.8.2008)
177  $no_items_text = (trim($this->getNoEntriesText()) != '')
178  ? $this->getNoEntriesText()
179  : $this->lng->txt("no_items");
180 
181  $this->css_row = ($this->css_row !== "tblrow1")
182  ? "tblrow1"
183  : "tblrow2";
184 
185  $this->tpl->setCurrentBlock("tbl_no_entries");
186  $this->tpl->setVariable('TBL_NO_ENTRY_CSS_ROW', $this->css_row);
187  $this->tpl->setVariable('TBL_NO_ENTRY_COLUMN_COUNT', $this->column_count);
188  $this->tpl->setVariable('TBL_NO_ENTRY_TEXT', trim($no_items_text));
189  $this->tpl->parseCurrentBlock();
190  }
191 
192  if (!$this->getPrintMode()) {
193  $this->fillFooter();
194 
195  $this->fillHiddenRow();
196 
197  $this->fillActionRow();
198 
199  $this->storeNavParameter();
200  }
201 
202  return $this->render();
203  }
204 
208  public function fillRowFromObject(ilDclTableView $a_set): void
209  {
210  if ($this->parent_obj instanceof ilDclTableViewGUI) {
211  $this->tpl->setVariable("ID", $a_set->getId());
212  $this->tpl->setVariable("ORDER_NAME", "order[{$a_set->getId()}]");
213  $this->tpl->setVariable("ORDER_VALUE", $a_set->getOrder());
214  }
215  $this->tpl->setVariable("TITLE", $a_set->getTitle());
216  $this->ctrl->setParameterByClass(ilDclTableViewEditGUI::class, 'tableview_id', $a_set->getId());
217  $this->tpl->setVariable("TITLE_LINK", $this->ctrl->getLinkTargetByClass(
218  [ilDclTableListGUI::class, ilDclTableViewGUI::class, ilDclTableViewEditGUI::class]
219  ));
220  $this->tpl->setVariable("DESCRIPTION", $a_set->getDescription());
221  $this->tpl->setVariable('ACTIONS', $this->buildAction($a_set->getId()));
222  }
223 
227  protected function buildAction(int $id): string
228  {
229  if ($this->parent_obj instanceof ilDclTableViewGUI) {
230  $dropdown_items = [];
231 
232  $this->ctrl->setParameterByClass(ilDclTableViewGUI::class, 'tableview_id', $id);
233  $this->ctrl->setParameterByClass(ilDclDetailedViewDefinitionGUI::class, 'tableview_id', $id);
234 
235  $dropdown_items[] = $this->ui_factory->link()->standard(
236  $this->lng->txt('edit'),
237  $this->ctrl->getLinkTargetByClass(ilDclTableViewEditGUI::class, 'editGeneralSettings')
238  );
239  $dropdown_items[] = $this->ui_factory->link()->standard(
240  $this->lng->txt('copy'),
241  $this->ctrl->getLinkTargetByClass(ilDclTableViewEditGUI::class, 'copy')
242  );
243  $dropdown_items[] = $this->ui_factory->link()->standard(
244  $this->lng->txt('delete'),
245  $this->ctrl->getLinkTargetByClass(ilDclTableViewEditGUI::class, 'confirmDelete')
246  );
247  $dropdown = $this->ui_factory->dropdown()->standard($dropdown_items)->withLabel($this->lng->txt('actions'));
248 
249  return $this->renderer->render($dropdown);
250  } elseif ($this->parent_obj instanceof ilDclDetailedViewGUI) {
251  $this->ctrl->setParameterByClass(ilDclDetailedViewGUI::class, 'tableview_id', $id);
252  $this->ctrl->saveParameterByClass(ilDclDetailedViewGUI::class, 'record_id');
253  $link = $this->ui_factory->link()->standard(
254  $this->lng->txt('view'),
255  $this->ctrl->getLinkTargetByClass(ilDclDetailedViewGUI::class, 'renderRecord')
256  );
257  return $this->renderer->render($link);
258  }
259  return "";
260  }
261 }
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)
ilDclTableViewGUI: ilDclTableViewEditGUI
setEnableTitle(bool $a_enabletitle)
addCommandButton(string $a_cmd, string $a_text, string $a_onclick='', string $a_id="", string $a_class="")
__construct(object $a_parent_obj, string $a_parent_cmd, ilDclTable $table, int $ref_id)
setShowTemplates(bool $a_value)
fillRowFromObject(ilDclTableView $a_set)
getId()
Get table id.
setFormName(string $a_name="")
buildAction(int $id)
build either actions menu or view button
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.
$ref_id
Definition: ltiauth.php:67
__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="")
setFooter(string $a_style, string $a_previous="", string $a_next="")
setLimit(int $a_limit=0, int $a_default_limit=0)
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.
ilDclDetailedViewGUI: ilDclDetailedViewDefinitionGUI, ilEditClipboardGUI, ilCommentGUI ...
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)