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