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