ILIAS  release_8 Revision v8.24
class.ilDclFieldListGUI.php
Go to the documentation of this file.
1<?php
2
20{
21 protected ilCtrl $ctrl;
22 protected ilLanguage $lng;
25 protected ilTabsGUI $tabs;
28 protected int $table_id;
30 protected int $obj_id;
31
35 public function __construct(ilDclTableListGUI $a_parent_obj)
36 {
37 global $DIC;
38
39 $this->http = $DIC->http();
40 $this->refinery = $DIC->refinery();
41 $this->table_id = $this->http->wrapper()->query()->retrieve('table_id', $this->refinery->kindlyTo()->int());
42 $locator = $DIC['ilLocator'];
43 $this->parent_obj = $a_parent_obj;
44 $this->obj_id = $a_parent_obj->getObjId();
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
51 $this->ctrl->saveParameterByClass('ilDclTableEditGUI', 'table_id');
52 $locator->addItem(
53 ilDclCache::getTableCache($this->table_id)->getTitle(),
54 $this->ctrl->getLinkTargetByClass('ilDclTableEditGUI', 'edit')
55 );
56 $this->tpl->setLocator();
57
58 if (!$this->checkAccess()) {
59 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('permission_denied'), true);
60 $this->ctrl->redirectByClass('ildclrecordlistgui', 'listRecords');
61 }
62 }
63
64 public function getTableId(): int
65 {
66 return $this->table_id;
67 }
68
72 public function executeCommand(): void
73 {
74 $cmd = $this->ctrl->getCmd('listFields');
75 $this->$cmd();
76 }
77
81 public function deleteFields(): void
82 {
83 if ($this->http->wrapper()->post()->has('dcl_field_ids')) {
84 $field_ids = $this->http->wrapper()->post()->retrieve(
85 'dcl_field_ids',
86 $this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->int())
87 );
88 $table = ilDclCache::getTableCache($this->table_id);
89 foreach ($field_ids as $field_id) {
90 $table->deleteField($field_id);
91 }
92 }
93
94 $this->tpl->setOnScreenMessage('success', $this->lng->txt('dcl_msg_fields_deleted'), true);
95 $this->ctrl->redirect($this, 'listFields');
96 }
97
101 public function confirmDeleteFields(): void
102 {
103 $this->tabs->clearSubTabs();
104 $conf = new ilConfirmationGUI();
105 $conf->setFormAction($this->ctrl->getFormAction($this));
106 $conf->setHeaderText($this->lng->txt('dcl_confirm_delete_fields'));
107
108 $has_field_ids = $this->http->wrapper()->post()->has('dcl_field_ids');
109 if (!$has_field_ids) {
110 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('dcl_delete_fields_no_selection'), true);
111 $this->ctrl->redirect($this, 'listFields');
112 }
113
114 $field_ids = $this->http->wrapper()->post()->retrieve(
115 'dcl_field_ids',
116 $this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->int())
117 );
118 foreach ($field_ids as $field_id) {
120 $field = ilDclCache::getFieldCache($field_id);
121 $conf->addItem('dcl_field_ids[]', $field_id, $field->getTitle());
122 }
123
124 $conf->setConfirm($this->lng->txt('delete'), 'deleteFields');
125 $conf->setCancel($this->lng->txt('cancel'), 'listFields');
126 $this->tpl->setContent($conf->getHTML());
127 }
128
129 /*
130 * save
131 */
132 public function save(): void
133 {
134 $table_id = $this->http->wrapper()->query()->retrieve('table_id', $this->refinery->kindlyTo()->int());
135
137 $fields = $table->getFields();
138
139 $order = $this->http->wrapper()->post()->retrieve(
140 'order',
141 $this->refinery->kindlyTo()->dictOf($this->refinery->kindlyTo()->string())
142 );
143 asort($order);
144 $val = 10;
145 foreach (array_keys($order) as $field_id) {
146 $order[$field_id] = $val;
147 $val += 10;
148 }
149
150 $exportable = [];
151 if ($this->http->wrapper()->post()->has("exportable")) {
152 $exportable = $this->http->wrapper()->post()->retrieve(
153 "exportable",
154 $this->refinery->kindlyTo()->dictOf(
155 $this->refinery->kindlyTo()->string()
156 )
157 );
158 }
159
160 foreach ($fields as $field) {
161 $field->setExportable(array_key_exists($field->getId(), $exportable) && $exportable[$field->getId()] === "on");
162 $field->setOrder($order[$field->getId()]);
163 $field->doUpdate();
164 }
165
166 $table->reloadFields();
167 $this->tpl->setOnScreenMessage('success', $this->lng->txt("dcl_table_settings_saved"));
168 $this->listFields();
169 }
170
174 public function listFields(): void
175 {
176 //add button
177 $add_new = ilLinkButton::getInstance();
178 $add_new->setPrimary(true);
179 $add_new->setCaption("dcl_add_new_field");
180 $add_new->setUrl($this->ctrl->getLinkTargetByClass('ildclfieldeditgui', 'create'));
181 $this->toolbar->addStickyItem($add_new);
182
183 $this->toolbar->addSeparator();
184
185 // Show tableswitcher
186 $tables = $this->parent_obj->getDataCollectionObject()->getTables();
187
188 foreach ($tables as $table) {
189 $options[$table->getId()] = $table->getTitle();
190 }
191 $table_selection = new ilSelectInputGUI('', 'table_id');
192 $table_selection->setOptions($options);
193 $table_selection->setValue($this->table_id);
194
195 $this->toolbar->setFormAction($this->ctrl->getFormActionByClass("ilDclFieldListGUI", "doTableSwitch"));
196 $this->toolbar->addText($this->lng->txt("dcl_select"));
197 $this->toolbar->addInputItem($table_selection);
198 $this->toolbar->addFormButton($this->lng->txt('change'), 'doTableSwitch');
199
200 //table gui
201 $list = new ilDclFieldListTableGUI($this, $this->ctrl->getCmd(), $this->table_id);
202 $this->tpl->setContent($list->getHTML());
203 }
204
205 /*
206 * doTableSwitch
207 */
208 public function doTableSwitch(): void
209 {
210 $table_id = $this->http->wrapper()->post()->retrieve('table_id', $this->refinery->kindlyTo()->int());
211 $this->ctrl->setParameterByClass("ilObjDataCollectionGUI", "table_id", $table_id);
212 $this->ctrl->redirectByClass("ilDclFieldListGUI", "listFields");
213 }
214
215 protected function checkAccess(): bool
216 {
217 $ref_id = $this->getDataCollectionObject()->getRefId();
218
220 }
221
223 {
224 return $this->parent_obj->getDataCollectionObject();
225 }
226}
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 getFieldCache(int $field_id=0)
static getTableCache(int $table_id=null)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ILIAS HTTP Services $http
ilDclTableListGUI $parent_obj
ILIAS Refinery Factory $refinery
executeCommand()
execute command
deleteFields()
Delete multiple fields.
ilGlobalTemplateInterface $tpl
__construct(ilDclTableListGUI $a_parent_obj)
Constructor.
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 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...
This class represents a selection list property in a property form.
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
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$ref_id
Definition: ltiauth.php:67
static http()
Fetches the global http state from ILIAS.