ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
class.ilDclTableViewEditGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
24
31{
33 protected ilCtrl $ctrl;
34 protected ilLanguage $lng;
41 protected ilHelpGUI $help;
49 private array $available_roles = [];
50
52 {
53 global $DIC;
54 $lng = $DIC['lng'];
55 $ilCtrl = $DIC['ilCtrl'];
56 $tpl = $DIC['tpl'];
57 $ilTabs = $DIC['ilTabs'];
58 $locator = $DIC['ilLocator'];
59 $this->table = $table;
60 $this->tpl = $tpl;
61 $this->lng = $lng;
62 $this->ctrl = $ilCtrl;
63 $this->parent_obj = $parent_obj;
64 $this->tableview = $tableview;
65 $this->tabs_gui = $ilTabs;
66 $this->help = $DIC->help();
67 $this->http = $DIC->http();
68 $this->refinery = $DIC->refinery();
69 $this->ui_factory = $DIC->ui()->factory();
70 $this->ui_renderer = $DIC->ui()->renderer();
71 $ref_id = $this->table->getCollectionObject()->getRefId();
72 foreach ($DIC->rbac()->review()->getParentRoleIds($ref_id) as $role) {
73 if (
74 $role['obj_id'] !== SYSTEM_ROLE_ID &&
75 $DIC->rbac()->system()->checkPermission($ref_id, $role['obj_id'], 'visible')
76 ) {
77 $this->available_roles[$role['obj_id']] = ilObjRole::_getTranslation($role['title']);
78 }
79 }
80
81 $this->ctrl->saveParameterByClass('ilDclTableEditGUI', 'table_id');
82 $this->ctrl->saveParameter($this, 'tableview_id');
83 if ($this->tableview->getTitle()) {
84 $locator->addItem($this->tableview->getTitle(), $this->ctrl->getLinkTarget($this, 'show'));
85 }
86 $this->tpl->setLocator();
87 }
88
89 public function executeCommand(): void
90 {
91 $cmd = $this->ctrl->getCmd('show');
92 $next_class = $this->ctrl->getNextClass($this);
93
94 if (!$this->checkAccess($cmd)) {
95 $this->permissionDenied();
96 }
97
98 $this->tabs_gui->clearTargets();
99 $this->tabs_gui->clearSubTabs();
100 $this->tabs_gui->setBackTarget(
101 $this->lng->txt('dcl_tableviews'),
102 $this->ctrl->getLinkTarget($this->parent_obj)
103 );
104 $this->tabs_gui->setBack2Target(
105 $this->lng->txt('dcl_tables'),
106 $this->ctrl->getLinkTarget($this->parent_obj->getParentObj())
107 );
108
109 switch ($next_class) {
110 case 'ildcldetailedviewdefinitiongui':
111 $this->help->setSubScreenId('detailed_view');
112 $this->setTabs('detailed_view');
113 $recordedit_gui = new ilDclDetailedViewDefinitionGUI($this->tableview->getId());
114 $ret = $this->ctrl->forwardCommand($recordedit_gui);
115 if ($ret != "") {
116 $this->tpl->setContent($ret);
117 }
118 break;
119 case 'ildclcreateviewdefinitiongui':
120 $this->help->setSubScreenId('record_create');
121 $this->setTabs('create_view');
122 $creation_gui = new ilDclCreateViewDefinitionGUI($this->tableview->getId());
123 $this->ctrl->forwardCommand($creation_gui);
124 break;
125 case 'ildcleditviewdefinitiongui':
126 $this->help->setSubScreenId('record_edit');
127 $this->setTabs('edit_view');
128 $edit_gui = new ilDclEditViewDefinitionGUI($this->tableview->getId());
129 $this->ctrl->forwardCommand($edit_gui);
130 break;
131 default:
132 switch ($cmd) {
133 case 'show':
134 if ($this->tableview->getId()) {
135 $this->ctrl->redirect($this, 'editGeneralSettings');
136 } else {
137 $this->ctrl->redirect($this, 'add');
138 }
139 break;
140 case 'add':
141 $this->help->setSubScreenId('create');
142 $this->tpl->setContent(
143 $this->lng->txt('dcl_new_view') . $this->ui_renderer->render($this->initForm(true))
144 );
145 break;
146 case 'editGeneralSettings':
147 $this->help->setSubScreenId('edit');
148 $this->setTabs('general_settings');
149 $this->tpl->setContent(
150 sprintf($this->lng->txt('dcl_edit_view'), $this->tableview->getTitle()) .
151 $this->ui_renderer->render($this->initForm())
152 );
153 break;
154 case 'editFieldSettings':
155 $this->help->setSubScreenId('overview');
156 $this->setTabs('field_settings');
157 $this->initTableGUI();
158 $this->tpl->setContent($this->table_gui->getHTML());
159 break;
160 default:
161 if ($cmd === 'create' || $cmd === 'update') {
162 $this->save($cmd === 'create');
163 } else {
164 $this->$cmd();
165 }
166 break;
167 }
168 break;
169 }
170 }
171
172 protected function initForm(bool $create = false): Form
173 {
174 $settings['title'] = $this->ui_factory->input()->field()->text($this->lng->txt('title'))->withRequired(true);
175 $settings['description'] = $this->ui_factory->input()->field()->textarea($this->lng->txt('description'));
176 $roles = [];
177 $settings['role_limitation'] = $this->ui_factory->input()->field()->optionalGroup(
178 [
179 'roles' => $this->ui_factory->input()->field()->multiSelect(
180 $this->lng->txt('roles'),
181 $this->available_roles,
182 $this->lng->txt('roles_desc')
183 )
184 ],
185 $this->lng->txt('role_limitation')
186 )->withValue(null);
187
188 $inputs['settings'] = $this->ui_factory->input()->field()->section($settings, $this->lng->txt('general_settings'));
189
190 if (!$create) {
191 $inputs = $this->setValues($inputs);
192 }
193
194 return $this->ui_factory->input()->container()->form()->standard(
195 $this->ctrl->getFormAction($this, $create ? 'create' : 'update'),
196 $inputs
197 );
198 }
199
200 protected function setValues(array $inputs): array
201 {
202 $roles = [];
203 foreach ($this->tableview->getRoles() as $role) {
204 $role = (int) $role;
205 if (in_array($role, array_keys($this->available_roles), true)) {
206 $roles[] = $role;
207 }
208 }
209 $inputs['settings'] = $inputs['settings']->withValue([
210 'title' => $this->tableview->getTitle(),
211 'description' => $this->tableview->getDescription(),
212 'role_limitation' => $this->tableview->getRoleLimitation() ? ['roles' => $roles] : null
213 ]);
214
215 return $inputs;
216 }
217
218 protected function setTabs(string $active): void
219 {
220 $this->tabs_gui->addTab(
221 'general_settings',
222 $this->lng->txt('settings'),
223 $this->ctrl->getLinkTarget($this, 'editGeneralSettings')
224 );
225 $this->tabs_gui->addTab(
226 'create_view',
227 $this->lng->txt('dcl_create_entry_rules'),
228 $this->ctrl->getLinkTargetByClass('ilDclCreateViewDefinitionGUI', 'presentation')
229 );
230 $this->tabs_gui->addTab(
231 'edit_view',
232 $this->lng->txt('dcl_edit_entry_rules'),
233 $this->ctrl->getLinkTargetByClass('ilDclEditViewDefinitionGUI', 'presentation')
234 );
235 $this->tabs_gui->addTab(
236 'field_settings',
237 $this->lng->txt('dcl_list_visibility_and_filter'),
238 $this->ctrl->getLinkTarget($this, 'editFieldSettings')
239 );
240 $this->tabs_gui->addTab(
241 'detailed_view',
242 $this->lng->txt('dcl_detailed_view'),
243 $this->ctrl->getLinkTargetByClass('ilDclDetailedViewDefinitionGUI', 'edit')
244 );
245 $this->tabs_gui->setTabActive($active);
246 }
247
248 public function save(bool $create = false): void
249 {
250 $form = $this->initForm($create)->withRequest($this->http->request());
251 $data = $form->getData();
252 if ($data !== null) {
253 $this->tableview->setTitle($data['settings']['title']);
254 $this->tableview->setDescription($data['settings']['description']);
255 $this->tableview->setRoleLimitation($data['settings']['role_limitation'] !== null);
256 $this->tableview->setRoles($data['settings']['role_limitation']['roles'] ?? []);
257 if ($create) {
258 $this->tableview->setTableId($this->table->getId());
259 $this->tpl->setOnScreenMessage($this->tpl::MESSAGE_TYPE_SUCCESS, $this->lng->txt('dcl_msg_tableview_created'), true);
260 $this->tableview->create();
261 $this->ctrl->setParameter($this, 'tableview_id', $this->tableview->getId());
262 } else {
263 $this->tpl->setOnScreenMessage($this->tpl::MESSAGE_TYPE_SUCCESS, $this->lng->txt('dcl_msg_tableview_updated'), true);
264 $this->tableview->update();
265 }
266 $this->ctrl->redirect($this, 'editGeneralSettings');
267 }
268
269 if ($create) {
270 $this->help->setSubScreenId('create');
271 $this->tpl->setContent($this->lng->txt('dcl_new_view') . $this->ui_renderer->render($form));
272 } else {
273 $this->help->setSubScreenId('edit');
274 $this->setTabs('general_settings');
275 $this->tpl->setContent(
276 sprintf($this->lng->txt('dcl_edit_view'), $this->tableview->getTitle()) .
277 $this->ui_renderer->render($form)
278 );
279 }
280 }
281
282 public function saveOverviewSettings(): void
283 {
287 foreach ($this->tableview->getFieldSettings() as $setting) {
288 //Checkboxes
289 foreach (["Visible", "InFilter", "FilterChangeable"] as $attribute) {
290 $key = $attribute . '_' . $setting->getField();
291 if ($this->http->wrapper()->post()->has($key)) {
292 $checkbox_value = $this->http->wrapper()->post()->retrieve(
293 $key,
294 $this->refinery->kindlyTo()->string()
295 );
296 $setting->{'set' . $attribute}($checkbox_value === 'on');
297 } else {
298 $setting->{'set' . $attribute}(false);
299 }
300 }
301
302 //Filter Value
303 $key = 'filter_' . $setting->getField();
304 if ($this->http->wrapper()->post()->has($key)) {
305 $setting->setFilterValue($this->http->wrapper()->post()->retrieve(
306 $key,
307 $this->refinery->kindlyTo()->string()
308 ));
309 } elseif ($this->http->wrapper()->post()->has($key . '_from') && $this->http->wrapper()->post()->has($key . '_to')) {
310 $setting->setFilterValue(["from" => $this->http->wrapper()->post()->retrieve(
311 $key . '_from',
312 $this->refinery->kindlyTo()->string()
313 ),
314 "to" => $this->http->wrapper()->post()->retrieve(
315 $key . '_to',
316 $this->refinery->kindlyTo()->string()
317 )
318 ]);
319 } else {
320 $setting->setFilterValue(null);
321 }
322
323 $setting->update();
324 }
325
326 $this->tpl->setOnScreenMessage('success', $this->lng->txt('dcl_msg_tableview_updated'), true);
327 $this->ctrl->saveParameter($this->parent_obj, 'tableview_id');
328 $this->ctrl->redirect($this, 'editFieldSettings');
329 }
330
331 protected function initTableGUI(): void
332 {
333 $table = new ilDclTableViewEditFieldsTableGUI($this);
334 $this->table_gui = $table;
335 }
336
337 protected function cancel(): void
338 {
339 $this->ctrl->setParameter($this->parent_obj, 'table_id', $this->table->getId());
340 $this->ctrl->redirect($this->parent_obj);
341 }
342
343 public function confirmDelete(): void
344 {
345 //at least one view must exist
346 $this->parent_obj->checkViewsLeft(1);
347
348 $conf = new ilConfirmationGUI();
349 $conf->setFormAction($this->ctrl->getFormAction($this));
350 $conf->setHeaderText($this->lng->txt('dcl_tableview_confirm_delete'));
351
352 $conf->addItem('tableview_id', (string) $this->tableview->getId(), $this->tableview->getTitle());
353
354 $conf->setConfirm($this->lng->txt('delete'), 'delete');
355 $conf->setCancel($this->lng->txt('cancel'), 'cancel');
356
357 $this->tpl->setContent($conf->getHTML());
358 }
359
360 protected function delete(): void
361 {
362 $this->tableview->delete();
363 $this->tpl->setOnScreenMessage('success', $this->lng->txt('dcl_msg_tableview_deleted'), true);
364 $this->cancel();
365 }
366
367 public function permissionDenied(): void
368 {
369 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('permission_denied'), true);
370 $this->ctrl->redirectByClass(
371 [ilObjDataCollectionGUI::class, ilDclRecordListGUI::class],
373 );
374 }
375
376 protected function checkAccess(string $cmd): bool
377 {
378 if (in_array($cmd, ['add', 'create', 'cancel'])) {
380 $this->parent_obj->getParentObj()->getDataCollectionObject()->getRefId(),
381 $this->table->getId()
382 );
383 } else {
384 return ilObjDataCollectionAccess::hasAccessTo(
385 $this->parent_obj->getParentObj()->getDataCollectionObject()->getRefId(),
386 $this->table->getId(),
387 $this->tableview->getId()
388 );
389 }
390 }
391
392 public function copy(): void
393 {
394 $new_tableview = new ilDclTableView();
395 $new_tableview->setTableId($this->table->getId());
396 $new_tableview->cloneStructure($this->tableview, []);
397 $this->tpl->setOnScreenMessage('success', $this->lng->txt("dcl_tableview_copy"), true);
398 $this->cancel();
399 }
400}
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
Builds data types.
Definition: Factory.php:36
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.
@ilCtrl_IsCalledBy ilDclCreateViewDefinitionGUI: ilDclTableViewEditGUI
@ilCtrl_Calls ilDclDetailedViewDefinitionGUI: ilPageEditorGUI, ilEditClipboardGUI,...
@ilCtrl_IsCalledBy ilDclEditViewDefinitionGUI: ilDclTableViewEditGUI
@ilCtrl_Calls ilDclTableViewEditGUI: ilDclDetailedViewDefinitionGUI @ilCtrl_Calls ilDclTableViewEditG...
__construct(ilDclTableViewGUI $parent_obj, ilDclTable $table, ilDclTableView $tableview)
ilDclTableViewEditFieldsTableGUI $table_gui
ILIAS Refinery Factory $refinery
@ilCtrl_Calls ilDclTableViewGUI: ilDclTableViewEditGUI
Help GUI class.
language handling
static hasAccessToEditTable(int $ref_id, int $table_id)
static _getTranslation(string $a_role_title)
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...
const SYSTEM_ROLE_ID
Definition: constants.php:29
This describes commonalities between all forms.
Definition: Form.php:34
This is how the factory for UI elements looks.
Definition: Factory.php:38
An entity that renders components to a string output.
Definition: Renderer.php:31
$ref_id
Definition: ltiauth.php:66
static http()
Fetches the global http state from ILIAS.
global $DIC
Definition: shib_login.php:26