ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilDclTableViewGUI.php
Go to the documentation of this file.
1 <?php
2 
23 {
24  protected ilCtrl $ctrl;
25  protected ilLanguage $lng;
28  protected ilTabsGUI $tabs;
29  protected ilDclTable $table;
33 
39  public function __construct(ilDclTableListGUI $a_parent_obj, int $table_id = 0)
40  {
41  global $DIC;
42 
43  $locator = $DIC['ilLocator'];
44  $this->parent_obj = $a_parent_obj;
45  $this->ctrl = $DIC->ctrl();
46  $this->lng = $DIC->language();
47  $this->tpl = $DIC->ui()->mainTemplate();
48  $this->tabs = $DIC->tabs();
49  $this->toolbar = $DIC->toolbar();
50  $this->http = $DIC->http();
51  $this->refinery = $DIC->refinery();
52 
53  if ($table_id == 0) {
54  $table_id = $this->http->wrapper()->query()->retrieve('table_id', $this->refinery->kindlyTo()->int());
55  }
56 
57  $this->table = ilDclCache::getTableCache($table_id);
58 
59  $this->ctrl->saveParameterByClass('ilDclTableEditGUI', 'table_id');
60  $locator->addItem($this->table->getTitle(), $this->ctrl->getLinkTargetByClass('ilDclTableEditGUI', 'edit'));
61  $this->tpl->setLocator();
62 
63  if (!$this->checkAccess()) {
64  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('permission_denied'), true);
65  $this->ctrl->redirectByClass('ildclrecordlistgui', 'listRecords');
66  }
67  }
68 
69  public function executeCommand(): void
70  {
71  $this->ctrl->saveParameter($this, 'table_id');
72  $cmd = $this->ctrl->getCmd("show");
73  $next_class = $this->ctrl->getNextClass($this);
74 
75  switch ($next_class) {
76  case 'ildcltablevieweditgui':
77  if ($this->http->wrapper()->query()->has('tableview_id')) {
78  $tableview_id = $this->http->wrapper()->query()->retrieve(
79  'tableview_id',
80  $this->refinery->kindlyTo()->int()
81  );
82  } else {
83  $tableview_id = 0;
84  }
85 
86  $edit_gui = new ilDclTableViewEditGUI(
87  $this,
88  $this->table,
90  );
91  $this->ctrl->saveParameter($edit_gui, 'tableview_id');
92  $this->ctrl->forwardCommand($edit_gui);
93  break;
94  default:
95  $this->$cmd();
96  break;
97  }
98  }
99 
100  public function getParentObj(): ilDclTableListGUI
101  {
102  return $this->parent_obj;
103  }
104 
105  protected function checkAccess(): bool
106  {
108  $this->parent_obj->getDataCollectionObject()->getRefId(),
109  $this->table->getId()
110  );
111  }
112 
113  public function show(): void
114  {
115  $add_new = ilLinkButton::getInstance();
116  $add_new->setPrimary(true);
117  $add_new->setCaption("dcl_add_new_view");
118  $add_new->setUrl($this->ctrl->getLinkTargetByClass('ilDclTableViewEditGUI', 'add'));
119  $this->toolbar->addStickyItem($add_new);
120 
121  $this->toolbar->addSeparator();
122 
123  // Show tables
124  $tables = $this->parent_obj->getDataCollectionObject()->getTables();
125 
126  foreach ($tables as $table) {
127  $options[$table->getId()] = $table->getTitle();
128  }
129  $table_selection = new ilSelectInputGUI('', 'table_id');
130  $table_selection->setOptions($options);
131  $table_selection->setValue($this->table->getId());
132 
133  $this->toolbar->setFormAction($this->ctrl->getFormActionByClass("ilDclTableViewGUI", "doTableSwitch"));
134  $this->toolbar->addText($this->lng->txt("dcl_select"));
135  $this->toolbar->addInputItem($table_selection);
136  $button = ilSubmitButton::getInstance();
137  $button->setCommand("doTableSwitch");
138  $button->setCaption('change');
139  $this->toolbar->addButtonInstance($button);
140 
141  $table_gui = new ilDclTableViewTableGUI($this, 'show', $this->table, $this->getParentObj()->getRefId());
142  $this->tpl->setContent($table_gui->getHTML());
143  }
144 
145  public function doTableSwitch(): void
146  {
147  $this->ctrl->setParameterByClass(
148  "ilDclTableViewGUI",
149  "table_id",
150  $this->http->wrapper()->post()->retrieve('table_id', $this->refinery->kindlyTo()->int())
151  );
152  $this->ctrl->redirectByClass("ilDclTableViewGUI", "show");
153  }
154 
158  public function confirmDeleteTableviews(): void
159  {
160  //at least one view must exist
161  $tableviews = [];
162  $has_dcl_tableview_ids = $this->http->wrapper()->post()->has('dcl_tableview_ids');
163  if (!$has_dcl_tableview_ids) {
164  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('dcl_delete_views_no_selection'), true);
165  $this->ctrl->redirect($this, 'show');
166  }
167 
168  $tableviews = $this->http->wrapper()->post()->retrieve(
169  'dcl_tableview_ids',
170  $this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->int())
171  );
172  $this->checkViewsLeft(count($tableviews));
173 
174  $this->tabs->clearSubTabs();
175  $conf = new ilConfirmationGUI();
176  $conf->setFormAction($this->ctrl->getFormAction($this));
177  $conf->setHeaderText($this->lng->txt('dcl_tableviews_confirm_delete'));
178 
179  foreach ($tableviews as $tableview_id) {
180  $conf->addItem('dcl_tableview_ids[]', $tableview_id, ilDclTableView::find($tableview_id)->getTitle());
181  }
182  $conf->setConfirm($this->lng->txt('delete'), 'deleteTableviews');
183  $conf->setCancel($this->lng->txt('cancel'), 'show');
184  $this->tpl->setContent($conf->getHTML());
185  }
186 
187  protected function deleteTableviews(): void
188  {
189  $tableviews = [];
190  $has_dcl_tableview_ids = $this->http->wrapper()->post()->has('dcl_tableview_ids');
191  if ($has_dcl_tableview_ids) {
192  $tableviews = $this->http->wrapper()->post()->retrieve(
193  'dcl_tableview_ids',
194  $this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->int())
195  );
196  foreach ($tableviews as $tableview_id) {
197  ilDclTableView::find($tableview_id)->delete();
198  }
199  }
200 
201  $this->table->sortTableViews();
202  $this->tpl->setOnScreenMessage('success', $this->lng->txt('dcl_msg_tableviews_deleted'), true);
203  $this->ctrl->redirect($this, 'show');
204  }
205 
210  public function checkViewsLeft(int $delete_count): void
211  {
212  if ($delete_count >= count($this->table->getTableViews())) {
213  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('dcl_msg_tableviews_delete_all'), true);
214  $this->ctrl->redirect($this, 'show');
215  }
216  }
217 
221  public function saveTableViewOrder(): void
222  {
223  $orders = $this->http->wrapper()->post()->retrieve(
224  'order',
225  $this->refinery->kindlyTo()->dictOf($this->refinery->kindlyTo()->string())
226  );
227  asort($orders);
228  $tableviews = array();
229  foreach (array_keys($orders) as $tableview_id) {
230  $tableviews[] = ilDclTableView::find($tableview_id);
231  }
232  $this->table->sortTableViews($tableviews);
233  $this->tpl->setOnScreenMessage('success', $this->lng->txt('dcl_msg_tableviews_order_updated'));
234  $this->ctrl->redirect($this);
235  }
236 }
ilDclTableListGUI $parent_obj
ilGlobalTemplateInterface $tpl
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...
saveTableViewOrder()
invoked by ilDclTableViewTableGUI
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(ilDclTableListGUI $a_parent_obj, int $table_id=0)
Constructor.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
confirmDeleteTableviews()
Confirm deletion of multiple fields.
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...
global $DIC
Definition: feed.php:28
checkViewsLeft(int $delete_count)
redirects if there are no tableviews left after deletion of {$delete_count} tableviews ...
static findOrGetInstance($primary_key, array $add_constructor_args=array())
static http()
Fetches the global http state from ILIAS.
static getTableCache(int $table_id=null)
ILIAS Refinery Factory $refinery
static hasAccessToEditTable(int $ref_id, int $table_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ILIAS HTTP Services $http