ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilDclTableViewGUI.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;
32  protected ilTabsGUI $tabs;
33  protected ilDclTable $table;
37 
43  public function __construct(ilDclTableListGUI $a_parent_obj, int $table_id = 0)
44  {
45  global $DIC;
46 
47  $locator = $DIC['ilLocator'];
48  $this->parent_obj = $a_parent_obj;
49  $this->ctrl = $DIC->ctrl();
50  $this->lng = $DIC->language();
51  $this->tpl = $DIC->ui()->mainTemplate();
52  $this->tabs = $DIC->tabs();
53  $this->toolbar = $DIC->toolbar();
54  $this->http = $DIC->http();
55  $this->refinery = $DIC->refinery();
56  $this->ui_factory = $DIC->ui()->factory();
57  $this->renderer = $DIC->ui()->renderer();
58 
59  $DIC->help()->setScreenId('dcl_views');
60 
61  if ($table_id == 0) {
62  $table_id = $this->http->wrapper()->query()->retrieve('table_id', $this->refinery->kindlyTo()->int());
63  }
64 
65  $this->table = ilDclCache::getTableCache($table_id);
66 
67  $this->ctrl->saveParameterByClass('ilDclTableEditGUI', 'table_id');
68  $locator->addItem($this->table->getTitle(), $this->ctrl->getLinkTargetByClass('ilDclTableEditGUI', 'edit'));
69  $this->tpl->setLocator();
70 
71  if (!$this->checkAccess()) {
72  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('permission_denied'), true);
73  $this->ctrl->redirectByClass(ilDclRecordListGUI::class, 'listRecords');
74  }
75  }
76 
77  public function executeCommand(): void
78  {
79  $this->ctrl->saveParameter($this, 'table_id');
80  $cmd = $this->ctrl->getCmd("show");
81  $next_class = $this->ctrl->getNextClass($this);
82 
83  switch ($next_class) {
84  case strtolower(ilDclTableViewEditGUI::class):
85  if ($this->http->wrapper()->query()->has('tableview_id')) {
86  $tableview_id = $this->http->wrapper()->query()->retrieve(
87  'tableview_id',
88  $this->refinery->kindlyTo()->int()
89  );
90  } else {
91  $tableview_id = 0;
92  }
93 
94  $edit_gui = new ilDclTableViewEditGUI(
95  $this,
96  $this->table,
98  );
99  $this->ctrl->saveParameter($edit_gui, 'tableview_id');
100  $this->ctrl->forwardCommand($edit_gui);
101  break;
102  default:
103  $this->$cmd();
104  break;
105  }
106  }
107 
108  public function getParentObj(): ilDclTableListGUI
109  {
110  return $this->parent_obj;
111  }
112 
113  protected function checkAccess(): bool
114  {
116  $this->parent_obj->getDataCollectionObject()->getRefId(),
117  $this->table->getId()
118  );
119  }
120 
121  public function show(): void
122  {
123  $add_new = $this->ui_factory->button()->primary(
124  $this->lng->txt("dcl_add_new_view"),
125  $this->ctrl->getLinkTargetByClass(ilDclTableViewEditGUI::class, 'add')
126  );
127  $this->toolbar->addStickyItem($add_new);
128 
129  $this->toolbar->addSeparator();
130 
131  $switcher = new ilDclSwitcher($this->toolbar, $this->ui_factory, $this->ctrl, $this->lng);
132  $switcher->addTableSwitcherToToolbar(
133  $this->parent_obj->getDataCollectionObject()->getTables(),
134  self::class,
135  'show'
136  );
137 
138  $table_gui = new ilDclTableViewTableGUI($this, 'show', $this->table, $this->getParentObj()->getRefId());
139  $this->tpl->setContent($table_gui->getHTML());
140  }
141 
145  public function confirmDeleteTableviews(): void
146  {
147  //at least one view must exist
148  $has_dcl_tableview_ids = $this->http->wrapper()->post()->has('dcl_tableview_ids');
149  if (!$has_dcl_tableview_ids) {
150  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('dcl_delete_views_no_selection'), true);
151  $this->ctrl->redirect($this, 'show');
152  }
153 
154  $tableviews = $this->http->wrapper()->post()->retrieve(
155  'dcl_tableview_ids',
156  $this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->int())
157  );
158  $this->checkViewsLeft(count($tableviews));
159 
160  $this->tabs->clearSubTabs();
161  $conf = new ilConfirmationGUI();
162  $conf->setFormAction($this->ctrl->getFormAction($this));
163  $conf->setHeaderText($this->lng->txt('dcl_tableviews_confirm_delete'));
164 
165  foreach ($tableviews as $tableview_id) {
166  $conf->addItem('dcl_tableview_ids[]', (string) $tableview_id, ilDclTableView::find($tableview_id)->getTitle());
167  }
168  $conf->setConfirm($this->lng->txt('delete'), 'deleteTableviews');
169  $conf->setCancel($this->lng->txt('cancel'), 'show');
170  $this->tpl->setContent($conf->getHTML());
171  }
172 
173  protected function deleteTableviews(): void
174  {
175  $has_dcl_tableview_ids = $this->http->wrapper()->post()->has('dcl_tableview_ids');
176  if ($has_dcl_tableview_ids) {
177  $tableviews = $this->http->wrapper()->post()->retrieve(
178  'dcl_tableview_ids',
179  $this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->int())
180  );
181  foreach ($tableviews as $tableview_id) {
182  ilDclTableView::find($tableview_id)->delete();
183  }
184  }
185 
186  $this->table->sortTableViews();
187  $this->tpl->setOnScreenMessage('success', $this->lng->txt('dcl_msg_tableviews_deleted'), true);
188  $this->ctrl->redirect($this, 'show');
189  }
190 
195  public function checkViewsLeft(int $delete_count): void
196  {
197  if ($delete_count >= count($this->table->getTableViews())) {
198  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('dcl_msg_tableviews_delete_all'), true);
199  $this->ctrl->redirect($this, 'show');
200  }
201  }
202 
206  public function saveTableViewOrder(): void
207  {
208  $orders = $this->http->wrapper()->post()->retrieve(
209  'order',
210  $this->refinery->kindlyTo()->dictOf($this->refinery->kindlyTo()->string())
211  );
212  asort($orders);
213  $tableviews = [];
214  foreach (array_keys($orders) as $tableview_id) {
215  $tableviews[] = ilDclTableView::find($tableview_id);
216  }
217  $this->table->sortTableViews($tableviews);
218  $this->tpl->setOnScreenMessage('success', $this->lng->txt('dcl_msg_tableviews_order_updated'));
219  $this->ctrl->redirect($this);
220  }
221 }
ilDclTableListGUI $parent_obj
ilGlobalTemplateInterface $tpl
ilDclTableViewEditGUI: ilDclDetailedViewDefinitionGUI ilDclTableViewEditGUI: ilDclCreateViewDefiniti...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static findOrGetInstance($primary_key, array $add_constructor_args=[])
saveTableViewOrder()
invoked by ilDclTableViewTableGUI
ilDclTableViewGUI: ilDclTableViewEditGUI
__construct(ilDclTableListGUI $a_parent_obj, int $table_id=0)
Constructor.
ilDclTableListGUI: ilDclFieldListGUI, ilDclFieldEditGUI, ilDclTableViewGUI, ilDclTableEditGUI ...
confirmDeleteTableviews()
Confirm deletion of multiple fields.
global $DIC
Definition: feed.php:28
checkViewsLeft(int $delete_count)
redirects if there are no tableviews left after deletion of {$delete_count} tableviews ...
static http()
Fetches the global http state from ILIAS.
static getTableCache(int $table_id=null)
ILIAS Refinery Factory $refinery
ILIAS UI Factory $ui_factory
static hasAccessToEditTable(int $ref_id, int $table_id)
ILIAS UI Renderer $renderer
ILIAS HTTP Services $http