ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
class.ilDclFieldListGUI.php
Go to the documentation of this file.
1 <?php
2 
20 declare(strict_types=1);
21 
23 {
24  protected \ILIAS\UI\Factory $ui_factory;
25  protected \ILIAS\UI\Renderer $renderer;
26  protected ilCtrl $ctrl;
27  protected ilLanguage $lng;
30  protected ilTabsGUI $tabs;
33  protected int $table_id;
35  protected int $obj_id;
36 
37  public function __construct(ilDclTableListGUI $a_parent_obj)
38  {
39  global $DIC;
40 
41  $this->http = $DIC->http();
42  $this->refinery = $DIC->refinery();
43  $this->table_id = $this->http->wrapper()->query()->retrieve('table_id', $this->refinery->kindlyTo()->int());
44  $locator = $DIC['ilLocator'];
45  $this->parent_obj = $a_parent_obj;
46  $this->obj_id = $a_parent_obj->getObjId();
47  $this->ctrl = $DIC->ctrl();
48  $this->lng = $DIC->language();
49  $this->tpl = $DIC->ui()->mainTemplate();
50  $this->tabs = $DIC->tabs();
51  $this->toolbar = $DIC->toolbar();
52  $this->ui_factory = $DIC->ui()->factory();
53  $this->renderer = $DIC->ui()->renderer();
54 
55  $DIC->help()->setScreenId('dcl_fields');
56 
57  $this->ctrl->saveParameterByClass(ilDclTableEditGUI::class, 'table_id');
58  $locator->addItem(
59  ilDclCache::getTableCache($this->table_id)->getTitle(),
60  $this->ctrl->getLinkTargetByClass(ilDclTableEditGUI::class, 'edit')
61  );
62  $this->tpl->setLocator();
63 
64  if (!$this->checkAccess()) {
65  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('permission_denied'), true);
66  $this->ctrl->redirectByClass(ilDclRecordListGUI::class, 'listRecords');
67  }
68  }
69 
70  public function getTableId(): int
71  {
72  return $this->table_id;
73  }
74 
78  public function executeCommand(): void
79  {
80  $cmd = $this->ctrl->getCmd('listFields');
81  $this->$cmd();
82  }
83 
87  public function deleteFields(): void
88  {
89  if ($this->http->wrapper()->post()->has('dcl_field_ids')) {
90  $field_ids = $this->http->wrapper()->post()->retrieve(
91  'dcl_field_ids',
92  $this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->int())
93  );
94  $table = ilDclCache::getTableCache($this->table_id);
95  foreach ($field_ids as $field_id) {
96  $table->deleteField($field_id);
97  }
98  }
99 
100  $this->tpl->setOnScreenMessage('success', $this->lng->txt('dcl_msg_fields_deleted'), true);
101  $this->ctrl->redirect($this, 'listFields');
102  }
103 
107  public function confirmDeleteFields(): void
108  {
109  $this->tabs->clearSubTabs();
110  $conf = new ilConfirmationGUI();
111  $conf->setFormAction($this->ctrl->getFormAction($this));
112  $conf->setHeaderText($this->lng->txt('dcl_confirm_delete_fields'));
113 
114  $has_field_ids = $this->http->wrapper()->post()->has('dcl_field_ids');
115  if (!$has_field_ids) {
116  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('dcl_delete_fields_no_selection'), true);
117  $this->ctrl->redirect($this, 'listFields');
118  }
119 
120  $field_ids = $this->http->wrapper()->post()->retrieve(
121  'dcl_field_ids',
122  $this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->int())
123  );
124  foreach ($field_ids as $field_id) {
126  $field = ilDclCache::getFieldCache($field_id);
127  $conf->addItem('dcl_field_ids[]', (string) $field_id, $field->getTitle());
128  }
129 
130  $conf->setConfirm($this->lng->txt('delete'), 'deleteFields');
131  $conf->setCancel($this->lng->txt('cancel'), 'listFields');
132  $this->tpl->setContent($conf->getHTML());
133  }
134 
135  /*
136  * save
137  */
138  public function save(): void
139  {
140  $table_id = $this->http->wrapper()->query()->retrieve('table_id', $this->refinery->kindlyTo()->int());
141 
142  $table = ilDclCache::getTableCache($table_id);
143  $fields = $table->getFields();
144 
145  $order = $this->http->wrapper()->post()->retrieve(
146  'order',
147  $this->refinery->kindlyTo()->dictOf($this->refinery->kindlyTo()->string())
148  );
149  asort($order);
150  $val = 10;
151  foreach (array_keys($order) as $field_id) {
152  $order[$field_id] = $val;
153  $val += 10;
154  }
155 
156  $exportable = [];
157  if ($this->http->wrapper()->post()->has("exportable")) {
158  $exportable = $this->http->wrapper()->post()->retrieve(
159  "exportable",
160  $this->refinery->kindlyTo()->dictOf(
161  $this->refinery->kindlyTo()->string()
162  )
163  );
164  }
165 
166  foreach ($fields as $field) {
167  $field->setExportable(array_key_exists($field->getId(), $exportable) && $exportable[$field->getId()] === "on");
168  $field->setOrder($order[$field->getId()]);
169  $field->doUpdate();
170  }
171 
172  $table->reloadFields();
173  $this->tpl->setOnScreenMessage('success', $this->lng->txt("dcl_table_settings_saved"));
174  $this->listFields();
175  }
176 
180  public function listFields(): void
181  {
182  //add button
183  $add_new = $this->ui_factory->button()->primary(
184  $this->lng->txt("dcl_add_new_field"),
185  $this->ctrl->getLinkTargetByClass(ilDclFieldEditGUI::class, 'create')
186  );
187  $this->toolbar->addStickyItem($add_new);
188 
189  $switcher = new ilDclSwitcher($this->toolbar, $this->ui_factory, $this->ctrl, $this->lng);
190  $switcher->addTableSwitcherToToolbar(
191  $this->parent_obj->getDataCollectionObject()->getTables(),
192  self::class,
193  'listFields'
194  );
195 
196  //table gui
197  $list = new ilDclFieldListTableGUI($this, $this->ctrl->getCmd(), $this->table_id);
198  $this->tpl->setContent($list->getHTML());
199  }
200 
201  protected function checkAccess(): bool
202  {
203  $ref_id = $this->getDataCollectionObject()->getRefId();
204 
206  }
207 
209  {
210  return $this->parent_obj->getDataCollectionObject();
211  }
212 }
ILIAS HTTP Services $http
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getFieldCache(int $field_id=0)
ilDclTableListGUI: ilDclFieldListGUI, ilDclFieldEditGUI, ilDclTableViewGUI, ilDclTableEditGUI ...
ilGlobalTemplateInterface $tpl
$ref_id
Definition: ltiauth.php:66
static http()
Fetches the global http state from ILIAS.
static getTableCache(int $table_id=null)
global $DIC
Definition: shib_login.php:25
deleteFields()
Delete multiple fields.
ILIAS UI Factory $ui_factory
executeCommand()
execute command
ilDclTableListGUI $parent_obj
static hasAccessToEditTable(int $ref_id, int $table_id)
ILIAS Refinery Factory $refinery
ILIAS UI Renderer $renderer
__construct(ilDclTableListGUI $a_parent_obj)