ILIAS  release_8 Revision v8.24
class.ilDclTableListGUI.php
Go to the documentation of this file.
1<?php
2
23{
24 protected ilCtrl $ctrl;
25 protected ilLanguage $lng;
27 protected ilTabsGUI $tabs;
32 protected int $obj_id;
33
38 public function __construct(ilObjDataCollectionGUI $a_parent_obj)
39 {
40 global $DIC;
41 $main_tpl = $DIC->ui()->mainTemplate();
42 $ilCtrl = $DIC['ilCtrl'];
43 $lng = $DIC['lng'];
44 $tpl = $DIC['tpl'];
45 $ilTabs = $DIC['ilTabs'];
46 $ilToolbar = $DIC['ilToolbar'];
47
48 $this->parent_obj = $a_parent_obj;
49 $this->obj_id = 0;
50 if ($a_parent_obj->getRefId() >= 0) {
51 $this->obj_id = ilObject::_lookupObjectId($a_parent_obj->getRefId());
52 }
53
54 $this->ctrl = $ilCtrl;
55 $this->lng = $lng;
56 $this->tpl = $tpl;
57 $this->tabs = $ilTabs;
58 $this->toolbar = $ilToolbar;
59 $this->http = $DIC->http();
60 $this->refinery = $DIC->refinery();
61
62 if (!$this->checkAccess()) {
63 $main_tpl->setOnScreenMessage('failure', $this->lng->txt('permission_denied'), true);
64 $this->ctrl->redirectByClass('ildclrecordlistgui', 'listRecords');
65 }
66 }
67
68 public function getObjId(): int
69 {
70 return $this->parent_obj->getObjectId();
71 }
72
73 public function getRefId(): int
74 {
75 return $this->parent_obj->getRefId();
76 }
77
81 public function executeCommand(): void
82 {
83 global $DIC;
84 $cmd = $this->ctrl->getCmd('listTables');
85
86 $next_class = $this->ctrl->getNextClass($this);
87
88 /*
89 * see https://www.ilias.de/mantis/view.php?id=22775
90 */
91 $ref_id = $this->http->wrapper()->query()->retrieve('ref_id', $this->refinery->kindlyTo()->int());
92
93 $tableHelper = new ilDclTableHelper(
94 $this->obj_id,
95 $ref_id,
96 $DIC->rbac()->review(),
97 $DIC->user(),
98 $DIC->database()
99 );
100 // send a warning if there are roles with rbac read access on the data collection but without read access on any standard view
101 $role_titles = $tableHelper->getRoleTitlesWithoutReadRightOnAnyStandardView();
102
103 if (count($role_titles) > 0) {
104 $this->tpl->setOnScreenMessage(
105 'info',
106 $DIC->language()->txt('dcl_rbac_roles_without_read_access_on_any_standard_view') . " " . implode(
107 ", ",
108 $role_titles
109 )
110 );
111 }
112
113 switch ($next_class) {
114 case 'ildcltableeditgui':
115 $this->tabs->clearTargets();
116 if ($cmd != 'create') {
117 $this->setTabs('settings');
118 } else {
119 $this->tabs->setBackTarget(
120 $this->lng->txt('back'),
121 $this->ctrl->getLinkTarget($this, 'listTables')
122 );
123 }
124 $ilDclTableEditGUI = new ilDclTableEditGUI($this);
125 $this->ctrl->forwardCommand($ilDclTableEditGUI);
126 break;
127
128 case 'ildclfieldlistgui':
129 $this->tabs->clearTargets();
130 $this->setTabs('fields');
131 $ilDclFieldListGUI = new ilDclFieldListGUI($this);
132 $this->ctrl->forwardCommand($ilDclFieldListGUI);
133 break;
134
135 case "ildclfieldeditgui":
136 $this->tabs->clearTargets();
137 $this->setTabs("fields");
138 $ilDclFieldEditGUI = new ilDclFieldEditGUI($this);
139 $this->ctrl->forwardCommand($ilDclFieldEditGUI);
140 break;
141
142 case 'ildcltableviewgui':
143 $this->tabs->clearTargets();
144 $this->setTabs('tableviews');
145 $ilDclTableViewGUI = new ilDclTableViewGUI($this);
146 $this->ctrl->forwardCommand($ilDclTableViewGUI);
147 break;
148
149 default:
150 $this->$cmd();
151 }
152 }
153
154 public function listTables(): void
155 {
156 $add_new = ilLinkButton::getInstance();
157 $add_new->setPrimary(true);
158 $add_new->setCaption("dcl_add_new_table");
159 $add_new->setUrl($this->ctrl->getLinkTargetByClass('ilDclTableEditGUI', 'create'));
160 $this->toolbar->addStickyItem($add_new);
161
162 $table_gui = new ilDclTableListTableGUI($this);
163 $this->tpl->setContent($table_gui->getHTML());
164 }
165
166 protected function setTabs(string $active): void
167 {
168 $this->tabs->setBackTarget($this->lng->txt('dcl_tables'), $this->ctrl->getLinkTarget($this, 'listTables'));
169 $this->tabs->addTab(
170 'settings',
171 $this->lng->txt('settings'),
172 $this->ctrl->getLinkTargetByClass('ilDclTableEditGUI', 'edit')
173 );
174 $this->tabs->addTab(
175 'fields',
176 $this->lng->txt('dcl_list_fields'),
177 $this->ctrl->getLinkTargetByClass('ilDclFieldListGUI', 'listFields')
178 );
179 $this->tabs->addTab(
180 'tableviews',
181 $this->lng->txt('dcl_tableviews'),
182 $this->ctrl->getLinkTargetByClass('ilDclTableViewGUI')
183 );
184 $this->tabs->activateTab($active);
185 }
186
187 protected function save(): void
188 {
189 if ($this->http->wrapper()->post()->has("comments")) {
190 $comments = $this->http->wrapper()->post()->retrieve(
191 'comments',
192 $this->refinery->kindlyTo()->dictOf($this->refinery->kindlyTo()->string())
193 );
194 }
195 if ($this->http->wrapper()->post()->has("visible")) {
196 $visible = $this->http->wrapper()->post()->retrieve(
197 'visible',
198 $this->refinery->kindlyTo()->dictOf($this->refinery->kindlyTo()->string())
199 );
200 }
201 $orders = $this->http->wrapper()->post()->retrieve(
202 'order',
203 $this->refinery->kindlyTo()->dictOf($this->refinery->kindlyTo()->string())
204 );
205 asort($orders);
206 $order = 10;
207 foreach (array_keys($orders) as $table_id) {
208 $table = ilDclCache::getTableCache($table_id);
209 $table->setOrder($order);
210 $table->setPublicCommentsEnabled(isset($comments[$table_id]));
211 $table->setIsVisible(isset($visible[$table_id]));
212 $table->doUpdate();
213 $order += 10;
214 }
215 $this->ctrl->redirect($this);
216 }
217
218 public function confirmDeleteTables(): void
219 {
220 //at least one table must exist
221 $tables = [];
222 $has_dcl_table_ids = $this->http->wrapper()->post()->has('dcl_table_ids');
223 if (!$has_dcl_table_ids) {
224 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('dcl_delete_tables_no_selection'), true);
225 $this->ctrl->redirect($this, 'listTables');
226 }
227
228 $tables = $this->http->wrapper()->post()->retrieve(
229 'dcl_table_ids',
230 $this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->int())
231 );
232 $this->checkTablesLeft(count($tables));
233
234 $this->tabs->clearSubTabs();
235 $conf = new ilConfirmationGUI();
236 $conf->setFormAction($this->ctrl->getFormAction($this));
237 $conf->setHeaderText($this->lng->txt('dcl_tables_confirm_delete'));
238
239 foreach ($tables as $table_id) {
240 $conf->addItem('dcl_table_ids[]', $table_id, ilDclCache::getTableCache($table_id)->getTitle());
241 }
242 $conf->setConfirm($this->lng->txt('delete'), 'deleteTables');
243 $conf->setCancel($this->lng->txt('cancel'), 'listTables');
244 $this->tpl->setContent($conf->getHTML());
245 }
246
247 protected function deleteTables(): void
248 {
249 $has_dcl_table_ids = $this->http->wrapper()->post()->has('dcl_table_ids');
250 if ($has_dcl_table_ids) {
251 $tables = $this->http->wrapper()->post()->retrieve(
252 'dcl_table_ids',
253 $this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->int())
254 );
255 foreach ($tables as $table_id) {
256 ilDclCache::getTableCache($table_id)->doDelete();
257 }
258 }
259 $this->tpl->setOnScreenMessage('success', $this->lng->txt('dcl_msg_tables_deleted'), true);
260 $this->ctrl->clearParameterByClass("ilobjdatacollectiongui", "table_id");
261 $this->ctrl->redirect($this, 'listTables');
262 }
263
268 public function checkTablesLeft(int $delete_count): void
269 {
270 if ($delete_count >= count($this->getDataCollectionObject()->getTables())) {
271 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('dcl_msg_tables_delete_all'), true);
272 $this->ctrl->redirect($this, 'listTables');
273 }
274 }
275
276 protected function checkAccess(): bool
277 {
278 $ref_id = $this->parent_obj->getRefId();
279
281 }
282
284 {
285 return $this->parent_obj->getDataCollectionObject();
286 }
287}
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.
static getTableCache(int $table_id=null)
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...
checkTablesLeft(int $delete_count)
redirects if there are no tableviews left after deletion of {$delete_count} tableviews
executeCommand()
execute command
__construct(ilObjDataCollectionGUI $a_parent_obj)
ilDclTableListGUI constructor.
ILIAS Refinery Factory $refinery
ilGlobalPageTemplate $tpl
ilObjDataCollectionGUI $parent_obj
ILIAS HTTP Services $http
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 hasWriteAccess(int $ref, ?int $user_id=0)
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...
static _lookupObjectId(int $ref_id)
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...
global $DIC
Definition: feed.php:28
$ref_id
Definition: ltiauth.php:67
static http()
Fetches the global http state from ILIAS.
$comments