ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilBiblLibraryGUI.php
Go to the documentation of this file.
1<?php
2
19use ILIAS\components\OrgUnit\ARHelper\DIC;
22
29{
30 use DIC;
31 public const F_LIB_ID = 'lib_id';
32 public const F_LIB_IDS = 'lib_ids';
33 public const CMD_DELETE = 'delete';
34 public const CMD_EDIT = 'edit';
35 public const CMD_INDEX = 'index';
36 public const CMD_ADD = 'add';
37 private \ilGlobalTemplateInterface $main_tpl;
38 protected Factory $refinery;
40
44 public function __construct(protected \ilBiblAdminLibraryFacadeInterface $facade)
45 {
46 global $DIC;
47 $this->main_tpl = $DIC->ui()->mainTemplate();
48 $this->wrapper = $DIC->http()->wrapper();
49 $this->refinery = $DIC->refinery();
50 }
51
52
59 public function executeCommand(): void
60 {
61 if ($this->ctrl()->getNextClass() === null) {
62 $cmd = $this->ctrl()->getCmd(self::CMD_INDEX);
63 $this->{$cmd}();
64 }
65 }
66
67
72 public function index(): bool
73 {
74 if ($this->checkPermissionBoolAndReturn('write')) {
75 $btn_add = $this->ui()->factory()->button()->primary(
76 $this->lng()->txt(self::CMD_ADD),
77 $this->ctrl()->getLinkTarget($this, self::CMD_ADD)
78 );
79 $this->toolbar()->addComponent($btn_add);
80
81 }
82
83 $table_gui = new ilBiblLibraryTableGUI($this->facade);
84 $this->tpl()->setContent($table_gui->getRenderedTable());
85
86 return true;
87 }
88
89
93 public function add(): void
94 {
95 $this->checkPermissionAndFail('write');
96 $form = new ilBiblLibraryFormGUI($this->facade->libraryFactory()->getEmptyInstance());
97 $this->tpl()->setContent($form->getHTML());
98 }
99
100
104 public function delete(): void
105 {
106 $this->checkPermissionAndFail('write');
107 $ilBibliographicSettings = $this->getInstancesFromRequest();
108 foreach ($ilBibliographicSettings as $ilBibliographicSetting) {
109 $ilBibliographicSetting->delete();
110 }
111 $this->ctrl()->redirect($this, self::CMD_INDEX);
112 }
113
114
118 public function cancel(): void
119 {
120 $this->ctrl()->redirect($this, self::CMD_INDEX);
121 }
122
123
127 public function update(): void
128 {
129 $this->checkPermissionAndFail('write');
130 $ilBibliographicSetting = $this->getInstancesFromRequest()[0];
131 $form = new ilBiblLibraryFormGUI($ilBibliographicSetting);
132 $form->setValuesByPost();
133 if ($form->saveObject()) {
134 $this->main_tpl->setOnScreenMessage('success', $this->lng()->txt("settings_saved"), true);
135 $this->ctrl()->redirect($this, self::CMD_INDEX);
136 }
137 $this->tpl()->setContent($form->getHTML());
138 }
139
140
144 public function create(): void
145 {
146 $this->checkPermissionAndFail('write');
147 $form = new ilBiblLibraryFormGUI($this->facade->libraryFactory()->getEmptyInstance());
148 $form->setValuesByPost();
149 if ($form->saveObject()) {
150 $this->main_tpl->setOnScreenMessage('success', $this->lng()->txt("settings_saved"), true);
151 $this->ctrl()->redirect($this, self::CMD_INDEX);
152 }
153 $this->tpl()->setContent($form->getHTML());
154 }
155
156
160 public function edit(): void
161 {
162 $this->checkPermissionAndFail('write');
163 $ilBibliographicSetting = $this->getInstancesFromRequest()[0];
164 $form = new ilBiblLibraryFormGUI($ilBibliographicSetting);
165 $this->tpl()->setContent($form->getHTML());
166 }
167
171 private function getInstancesFromRequest(): array
172 {
173 $lib_ids = null;
174 $to_int = $this->refinery->kindlyTo()->int();
175 $to_int_array = $this->refinery->kindlyTo()->listOf($to_int);
176 if ($this->wrapper->query()->has(self::F_LIB_IDS)) {
177 $lib_ids = $this->wrapper->query()->retrieve(self::F_LIB_IDS, $to_int_array);
178 } elseif ($this->wrapper->query()->has(self::F_LIB_ID)) {
179 $lib_ids[] = $this->wrapper->query()->retrieve(self::F_LIB_ID, $to_int);
180 } elseif ($this->wrapper->post()->has(self::F_LIB_IDS)) {
181 $lib_ids = $this->wrapper->post()->retrieve(self::F_LIB_IDS, $to_int_array);
182 } elseif ($this->wrapper->post()->has(self::F_LIB_ID)) {
183 $lib_ids[] = $this->wrapper->post()->retrieve(self::F_LIB_ID, $to_int);
184 }
185
186 if ($lib_ids === null) {
187 throw new ilException('library not found');
188 }
189
190 $instances = [];
191 foreach ($lib_ids as $lib_id) {
192 $instances[] = $this->facade->libraryFactory()->findById($lib_id);
193 }
194 return $instances;
195 }
196}
Builds data types.
Definition: Factory.php:36
Bibliographic Libraries Form.
Class ilBiblLibraryGUI.
ilGlobalTemplateInterface $main_tpl
__construct(protected \ilBiblAdminLibraryFacadeInterface $facade)
ilBiblLibraryGUI constructor.
update()
save changes in library
executeCommand()
Execute command.
getInstancesFromRequest()
return ilBiblLibraryInterface[]
index()
@global $ilToolbar ilToolbarGUI;
Base class for ILIAS Exception handling.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: shib_login.php:26