ILIAS  release_8 Revision v8.24
class.ilDclTableViewEditGUI.php
Go to the documentation of this file.
1<?php
2
25{
27 protected ilCtrl $ctrl;
28 protected ilLanguage $lng;
37
39 {
40 global $DIC;
41 $lng = $DIC['lng'];
42 $ilCtrl = $DIC['ilCtrl'];
43 $tpl = $DIC['tpl'];
44 $ilTabs = $DIC['ilTabs'];
45 $locator = $DIC['ilLocator'];
46 $this->table = $table;
47 $this->tpl = $tpl;
48 $this->lng = $lng;
49 $this->ctrl = $ilCtrl;
50 $this->parent_obj = $parent_obj;
51 $this->tableview = $tableview;
52 $this->tabs_gui = $ilTabs;
53 $this->http = $DIC->http();
54 $this->refinery = $DIC->refinery();
55
56 $this->ctrl->saveParameterByClass('ilDclTableEditGUI', 'table_id');
57 $this->ctrl->saveParameter($this, 'tableview_id');
58 if ($this->tableview->getTitle()) {
59 $locator->addItem($this->tableview->getTitle(), $this->ctrl->getLinkTarget($this, 'show'));
60 }
61 $this->tpl->setLocator();
62 }
63
64 public function executeCommand(): void
65 {
66 $cmd = $this->ctrl->getCmd('show');
67 $next_class = $this->ctrl->getNextClass($this);
68
69 if (!$this->checkAccess($cmd)) {
70 $this->permissionDenied();
71 }
72
73 $this->tabs_gui->clearTargets();
74 $this->tabs_gui->clearSubTabs();
75 $this->tabs_gui->setBackTarget(
76 $this->lng->txt('dcl_tableviews'),
77 $this->ctrl->getLinkTarget($this->parent_obj)
78 );
79 $this->tabs_gui->setBack2Target(
80 $this->lng->txt('dcl_tables'),
81 $this->ctrl->getLinkTarget($this->parent_obj->getParentObj())
82 );
83
84 switch ($next_class) {
85 case 'ildcldetailedviewdefinitiongui':
86 $this->setTabs('detailed_view');
87 $recordedit_gui = new ilDclDetailedViewDefinitionGUI($this->tableview->getId());
88 $ret = $this->ctrl->forwardCommand($recordedit_gui);
89 if ($ret != "") {
90 $this->tpl->setContent($ret);
91 }
92 global $DIC;
93 $ilTabs = $DIC['ilTabs'];
94 $ilTabs->removeTab('edit');
95 $ilTabs->removeTab('history');
96 $ilTabs->removeTab('clipboard'); // Fixme
97 $ilTabs->removeTab('pg');
98 break;
99 case 'ildclcreateviewdefinitiongui':
100 $this->setTabs('create_view');
101 $creation_gui = new ilDclCreateViewDefinitionGUI($this->tableview->getId());
102 $this->ctrl->forwardCommand($creation_gui);
103 global $DIC;
104 $ilTabs = $DIC['ilTabs'];
105 $ilTabs->removeTab('edit');
106 $ilTabs->removeTab('history');
107 $ilTabs->removeTab('clipboard'); // Fixme
108 $ilTabs->removeTab('pg');
109 break;
110 case 'ildcleditviewdefinitiongui':
111 $this->setTabs('edit_view');
112 $edit_gui = new ilDclEditViewDefinitionGUI($this->tableview->getId());
113 $this->ctrl->forwardCommand($edit_gui);
114 global $DIC;
115 $ilTabs = $DIC['ilTabs'];
116 $ilTabs->removeTab('edit');
117 $ilTabs->removeTab('history');
118 $ilTabs->removeTab('clipboard'); // Fixme
119 $ilTabs->removeTab('pg');
120 break;
121 default:
122 switch ($cmd) {
123 case 'show':
124 if ($this->tableview->getId()) {
125 $this->ctrl->redirect($this, 'editGeneralSettings');
126 } else {
127 $this->ctrl->redirect($this, 'add');
128 }
129 break;
130 case 'add':
131 $ilDclTableViewEditFormGUI = new ilDclTableViewEditFormGUI($this, $this->tableview);
132 $this->tpl->setContent($ilDclTableViewEditFormGUI->getHTML());
133 break;
134 case 'editGeneralSettings':
135 $settings_tpl = new ilTemplate("tpl.dcl_settings.html", true, true, 'Modules/DataCollection');
136
137 $this->setTabs('general_settings');
138 $ilDclTableViewEditFormGUI = new ilDclTableViewEditFormGUI($this, $this->tableview);
139
140 global $DIC;
141 $f = $DIC->ui()->factory()->listing()->workflow();
142 $renderer = $DIC->ui()->renderer();
143
144 // Set Workflow flag to true
145 $view = ilDclTableView::getCollection()->where(array("id" => filter_input(
146 INPUT_GET,
147 "tableview_id"
148 )
149 ))->first();
150 if (!is_null($view)) {
151 //setup steps
152 $step = $f->step('', '');
153 $steps = [
154 $f->step($this->lng->txt('dcl_view_settings'))
155 ->withAvailability($step::AVAILABLE)->withStatus(4), //$view->getStepVs() ? 3 : 4
156 $f->step($this->lng->txt('dcl_create_entry_rules'))
157 ->withAvailability($step::AVAILABLE)->withStatus(4), //$view->getStepC() ? 3 : 4
158 $f->step($this->lng->txt('dcl_edit_entry_rules'))
159 ->withAvailability($step::AVAILABLE)->withStatus(4), //$view->getStepE() ? 3 : 4
160 $f->step($this->lng->txt('dcl_list_visibility_and_filter'))
161 ->withAvailability($step::AVAILABLE)->withStatus(4), //$view->getStepO() ? 3 : 4
162 $f->step($this->lng->txt('dcl_detailed_view'))
163 ->withAvailability($step::AVAILABLE)->withStatus(1), //$view->getStepS() ? 3 : 1
164 ];
165
166 //setup linear workflow
167 $wf = $f->linear($this->lng->txt('dcl_view_configuration'), $steps);
168 $settings_tpl->setVariable("WORKFLOW", $renderer->render($wf));
169 }
170
171 $settings_tpl->setVariable("SETTINGS", $ilDclTableViewEditFormGUI->getHTML());
172
173 $this->tpl->setContent($settings_tpl->get());
174 break;
175 case 'editFieldSettings':
176 $this->setTabs('field_settings');
177 $this->initTableGUI();
178 $this->tpl->setContent($this->table_gui->getHTML());
179 break;
180 default:
181 $this->$cmd();
182 break;
183 }
184 break;
185 }
186 }
187
188 protected function setTabs(string $active): void
189 {
190 $this->tabs_gui->addTab(
191 'general_settings',
192 $this->lng->txt('dcl_view_settings'),
193 $this->ctrl->getLinkTarget($this, 'editGeneralSettings')
194 );
195 $this->tabs_gui->addTab(
196 'create_view',
197 $this->lng->txt('dcl_create_entry_rules'),
198 $this->ctrl->getLinkTargetByClass('ilDclCreateViewDefinitionGUI', 'presentation')
199 );
200 $this->tabs_gui->addTab(
201 'edit_view',
202 $this->lng->txt('dcl_edit_entry_rules'),
203 $this->ctrl->getLinkTargetByClass('ilDclEditViewDefinitionGUI', 'presentation')
204 );
205 $this->tabs_gui->addTab(
206 'field_settings',
207 $this->lng->txt('dcl_list_visibility_and_filter'),
208 $this->ctrl->getLinkTarget($this, 'editFieldSettings')
209 );
210 $this->tabs_gui->addTab(
211 'detailed_view',
212 $this->lng->txt('dcl_detailed_view'),
213 $this->ctrl->getLinkTargetByClass('ilDclDetailedViewDefinitionGUI', 'edit')
214 );
215 $this->tabs_gui->setTabActive($active);
216 }
217
218 public function update(): void
219 {
220 $ilDclTableViewEditFormGUI = new ilDclTableViewEditFormGUI($this, $this->tableview);
221 $ilDclTableViewEditFormGUI->setValuesByPost();
222 if ($ilDclTableViewEditFormGUI->checkInput()) {
223 $ilDclTableViewEditFormGUI->updateTableView();
224 $this->ctrl->redirect($this, 'editGeneralSettings');
225 } else {
226 $this->setTabs('general_settings');
227 $this->tpl->setContent($ilDclTableViewEditFormGUI->getHTML());
228 }
229 }
230
231 public function create(): void
232 {
233 $ilDclTableViewEditFormGUI = new ilDclTableViewEditFormGUI($this, $this->tableview, $this->table);
234 $ilDclTableViewEditFormGUI->setValuesByPost();
235 if ($ilDclTableViewEditFormGUI->checkInput()) {
236 $ilDclTableViewEditFormGUI->createTableView();
237 $this->ctrl->redirect($this, 'editGeneralSettings');
238 } else {
239 $this->tpl->setContent($ilDclTableViewEditFormGUI->getHTML());
240 }
241 }
242
243 public function saveTable(): void
244 {
248 foreach ($this->tableview->getFieldSettings() as $setting) {
249 //Checkboxes
250 foreach (array("Visible", "InFilter", "FilterChangeable") as $attribute) {
251 $key = $attribute . '_' . $setting->getField();
252 if ($this->http->wrapper()->post()->has($key)) {
253 $checkbox_value = $this->http->wrapper()->post()->retrieve(
254 $key,
255 $this->refinery->kindlyTo()->string()
256 );
257 $setting->{'set' . $attribute}($checkbox_value === 'on');
258 } else {
259 $setting->{'set' . $attribute}(false);
260 }
261 }
262
263 //Filter Value
264 $key = 'filter_' . $setting->getField();
265 if ($this->http->wrapper()->post()->has($key)) {
266 $setting->setFilterValue($this->http->wrapper()->post()->retrieve(
267 $key,
268 $this->refinery->kindlyTo()->string()
269 ));
270 } elseif ($this->http->wrapper()->post()->has($key . '_from') && $this->http->wrapper()->post()->has($key . '_to')) {
271 $setting->setFilterValue(array("from" => $this->http->wrapper()->post()->retrieve(
272 $key . '_from',
273 $this->refinery->kindlyTo()->string()
274 ),
275 "to" => $this->http->wrapper()->post()->retrieve(
276 $key . '_to',
277 $this->refinery->kindlyTo()->string()
278 )
279 ));
280 } else {
281 $setting->setFilterValue(null);
282 }
283
284 $setting->update();
285 }
286
287 // Set Workflow flag to true
288 $view = ilDclTableView::getCollection()->where(array("id" => filter_input(INPUT_GET, "tableview_id")))->first();
289 if (!is_null($view)) {
290 $view->setStepO(true);
291 $view->save();
292 }
293
294 $this->tpl->setOnScreenMessage('success', $this->lng->txt('dcl_msg_tableview_updated'), true);
295 $this->ctrl->saveParameter($this->parent_obj, 'tableview_id');
296 $this->ctrl->redirect($this, 'editFieldSettings');
297 }
298
299 protected function initTableGUI(): void
300 {
301 $table = new ilDclTableViewEditFieldsTableGUI($this);
302 $this->table_gui = $table;
303 }
304
305 protected function cancel(): void
306 {
307 $this->ctrl->setParameter($this->parent_obj, 'table_id', $this->table->getId());
308 $this->ctrl->redirect($this->parent_obj);
309 }
310
311 public function confirmDelete(): void
312 {
313 //at least one view must exist
314 $this->parent_obj->checkViewsLeft(1);
315
316 $conf = new ilConfirmationGUI();
317 $conf->setFormAction($this->ctrl->getFormAction($this));
318 $conf->setHeaderText($this->lng->txt('dcl_tableview_confirm_delete'));
319
320 $conf->addItem('tableview_id', (int) $this->tableview->getId(), $this->tableview->getTitle());
321
322 $conf->setConfirm($this->lng->txt('delete'), 'delete');
323 $conf->setCancel($this->lng->txt('cancel'), 'cancel');
324
325 $this->tpl->setContent($conf->getHTML());
326 }
327
328 protected function delete(): void
329 {
330 $this->tableview->delete();
331 $this->table->sortTableViews();
332 $this->tpl->setOnScreenMessage('success', $this->lng->txt('dcl_msg_tableview_deleted'), true);
333 $this->cancel();
334 }
335
336 public function permissionDenied(): void
337 {
338 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('permission_denied'), true);
339 $this->ctrl->redirectByClass(
340 [ilObjDataCollectionGUI::class, ilDclRecordListGUI::class],
342 );
343 }
344
345 protected function checkAccess(string $cmd): bool
346 {
347 if (in_array($cmd, ['add', 'create'])) {
349 $this->parent_obj->getParentObj()->getDataCollectionObject()->getRefId(),
350 $this->table->getId()
351 );
352 } else {
353 return ilObjDataCollectionAccess::hasAccessTo(
354 $this->parent_obj->getParentObj()->getDataCollectionObject()->getRefId(),
355 $this->table->getId(),
356 $this->tableview->getId()
357 );
358 }
359 }
360
361 public function copy(): void
362 {
363 $new_tableview = new ilDclTableView();
364 $new_tableview->setTableId($this->table->getId());
365 $new_tableview->cloneStructure($this->tableview, array());
366 $this->table->sortTableViews();
367 $this->tpl->setOnScreenMessage('success', $this->lng->txt("dcl_tableview_copy"), true);
368 $this->cancel();
369 }
370}
Builds data types.
Definition: Factory.php:21
Class Services.
Definition: Services.php:38
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilCtrl provides processing control methods.
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...
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...
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...
__construct(ilDclTableViewGUI $parent_obj, ilDclTable $table, ilDclTableView $tableview)
ilDclTableViewEditFieldsTableGUI $table_gui
ILIAS Refinery Factory $refinery
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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
language handling
static hasAccessToEditTable(int $ref_id, int $table_id)
This class represents a property form user interface.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
special template class to simplify handling of ITX/PEAR
global $DIC
Definition: feed.php:28
$steps
Definition: latex.php:3
static http()
Fetches the global http state from ILIAS.
string $key
Consumer key/client ID value.
Definition: System.php:193