ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilExcCriteriaCatalogueGUI.php
Go to the documentation of this file.
1<?php
2
20
28{
29 protected ilCtrl $ctrl;
30 protected ilTabsGUI $tabs;
31 protected ilLanguage $lng;
36
37 public function __construct(ilObjExercise $a_exc_obj)
38 {
40 global $DIC;
41
42 $this->ctrl = $DIC->ctrl();
43 $this->tabs = $DIC->tabs();
44 $this->lng = $DIC->language();
45 $this->toolbar = $DIC->toolbar();
46 $this->tpl = $DIC->ui()->mainTemplate();
47 $this->exc_obj = $a_exc_obj;
48
49 $this->request = $DIC->exercise()->internal()->gui()->request();
50 }
51
55 public function executeCommand(): void
56 {
57 $ilCtrl = $this->ctrl;
58 $ilTabs = $this->tabs;
60
61 $next_class = $ilCtrl->getNextClass($this);
62 $cmd = $ilCtrl->getCmd("view");
63
64 switch ($next_class) {
65 case "ilexccriteriagui":
66 $ilTabs->clearTargets();
67 $ilTabs->setBackTarget($lng->txt("back"), $ilCtrl->getLinkTarget($this, ""));
68 $ilCtrl->saveParameter($this, "cat_id");
69 $crit_gui = new ilExcCriteriaGUI($this->request->getCatalogueId());
70 $ilCtrl->forwardCommand($crit_gui);
71 break;
72
73 default:
74 $this->$cmd();
75 break;
76 }
77 }
78
79
80 //
81 // LIST/TABLE
82 //
83
84 protected function view(): void
85 {
86 $ilToolbar = $this->toolbar;
87 $ilCtrl = $this->ctrl;
90
91 $ilToolbar->addButton(
92 $lng->txt("exc_add_criteria_catalogue"),
93 $ilCtrl->getLinkTarget($this, "add")
94 );
95
96 $tbl = new ilExcCriteriaCatalogueTableGUI($this, "view", $this->exc_obj->getId());
97 $tpl->setContent($tbl->getHTML());
98 }
99
100 protected function saveOrder(): void
101 {
102 $ilCtrl = $this->ctrl;
104
105 $all_cat = ilExcCriteriaCatalogue::getInstancesByParentId($this->exc_obj->getId());
106
107 $pos = 0;
108 $req_positions = $this->request->getPositions();
109 asort($req_positions);
110 foreach (array_keys($req_positions) as $id) {
111 if (array_key_exists($id, $all_cat)) {
112 $pos += 10;
113 $all_cat[$id]->setPosition($pos);
114 $all_cat[$id]->update();
115 }
116 }
117
118 $this->tpl->setOnScreenMessage('success', $lng->txt("settings_saved"), true);
119 $ilCtrl->redirect($this, "view");
120 }
121
122 protected function confirmDeletion(): void
123 {
124 $ilCtrl = $this->ctrl;
127
128 $ids = $this->request->getCatalogueIds();
129 if (count($ids) == 0) {
130 $this->tpl->setOnScreenMessage('info', $lng->txt("select_one"), true);
131 $ilCtrl->redirect($this, "view");
132 }
133
134 $confirmation_gui = new ilConfirmationGUI();
135 $confirmation_gui->setFormAction($ilCtrl->getFormAction($this, "delete"));
136 $confirmation_gui->setHeaderText($lng->txt("exc_criteria_catalogue_deletion_confirmation"));
137 $confirmation_gui->setCancel($lng->txt("cancel"), "view");
138 $confirmation_gui->setConfirm($lng->txt("delete"), "delete");
139
140 foreach (ilExcCriteriaCatalogue::getInstancesByParentId($this->exc_obj->getId()) as $item) {
141 if (in_array($item->getId(), $ids)) {
142 $confirmation_gui->addItem("id[]", $item->getId(), $item->getTitle());
143 }
144 }
145
146 $tpl->setContent($confirmation_gui->getHTML());
147 }
148
149 protected function delete(): void
150 {
151 $ilCtrl = $this->ctrl;
153
154 $ids = $this->request->getCatalogueIds();
155 if (count($ids) == 0) {
156 $ilCtrl->redirect($this, "view");
157 }
158
159 foreach (ilExcCriteriaCatalogue::getInstancesByParentId($this->exc_obj->getId()) as $item) {
160 if (in_array($item->getId(), $ids)) {
161 $item->delete();
162 }
163 }
164
165 $this->tpl->setOnScreenMessage('success', $lng->txt("settings_saved"), true);
166 $ilCtrl->redirect($this, "view");
167 }
168
169
170 //
171 // EDIT
172 //
173
174 protected function initForm(
175 ?ilExcCriteriaCatalogue $a_cat_obj = null
177 $ilCtrl = $this->ctrl;
179
180 $form = new ilPropertyFormGUI();
181
182 $is_edit = ($a_cat_obj !== null);
183 if (!$is_edit) {
184 $form->setFormAction($ilCtrl->getFormAction($this, "create"));
185 $form->setTitle($lng->txt("exc_criteria_catalogue_create_form"));
186 $form->addCommandButton("create", $lng->txt("create"));
187 } else {
188 $form->setFormAction($ilCtrl->getFormAction($this, "update"));
189 $form->setTitle($lng->txt("exc_criteria_catalogue_update_form"));
190 $form->addCommandButton("update", $lng->txt("save"));
191 }
192
193 $form->addCommandButton("view", $lng->txt("cancel"));
194
195 $title = new ilTextInputGUI($lng->txt("title"), "title");
196 $title->setRequired(true);
197 $form->addItem($title);
198
199 return $form;
200 }
201
202 protected function add(?ilPropertyFormGUI $a_form = null): void
203 {
204 $tpl = $this->tpl;
205
206 if (!$a_form) {
207 $a_form = $this->initForm();
208 }
209
210 $tpl->setContent($a_form->getHTML());
211 }
212
213 protected function exportForm(
214 ilExcCriteriaCatalogue $a_cat_obj,
215 ilPropertyFormGUI $a_form
216 ): void {
217 $a_form->getItemByPostVar("title")->setValue($a_cat_obj->getTitle());
218 }
219
220 protected function importForm(
221 ?ilExcCriteriaCatalogue $a_cat_obj = null
222 ): void {
223 $ilCtrl = $this->ctrl;
225
226 $is_edit = ($a_cat_obj !== null);
227
228 $form = $this->initForm($a_cat_obj);
229 if ($form->checkInput()) {
230 if (!$is_edit) {
231 $a_cat_obj = new ilExcCriteriaCatalogue();
232 $a_cat_obj->setParent($this->exc_obj->getId());
233 }
234
235 $a_cat_obj->setTitle($form->getInput("title"));
236
237 if (!$is_edit) {
238 $a_cat_obj->save();
239 } else {
240 $a_cat_obj->update();
241 }
242
243 $this->tpl->setOnScreenMessage('success', $lng->txt("settings_saved"), true);
244 $ilCtrl->redirect($this, "view");
245 }
246
247 $form->setValuesByPost();
248 $this->{$is_edit ? "edit" : "add"}($form);
249 }
250
251 protected function create(): void
252 {
253 $this->importForm();
254 }
255
257 {
258 $ilCtrl = $this->ctrl;
259
260 $id = $this->request->getCatalogueId();
261 if ($id > 0) {
262 $cat_obj = new ilExcCriteriaCatalogue($id);
263 if ($cat_obj->getParent() == $this->exc_obj->getId()) {
264 $ilCtrl->setParameter($this, "cat_id", $id);
265 return $cat_obj;
266 }
267 }
268
269 $ilCtrl->redirect($this, "view");
270
271 return null;
272 }
273
274 protected function edit(?ilPropertyFormGUI $a_form = null): void
275 {
276 $tpl = $this->tpl;
277
278 $cat_obj = $this->getCurrentCatalogue();
279
280 if (!$a_form) {
281 $a_form = $this->initForm($cat_obj);
282 $this->exportForm($cat_obj, $a_form);
283 }
284
285 $tpl->setContent($a_form->getHTML());
286 }
287
288 protected function update(): void
289 {
290 $cat_obj = $this->getCurrentCatalogue();
291 $this->importForm($cat_obj);
292 }
293}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Exercise gui request wrapper.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilCtrl provides processing control methods.
Class ilExcCriteriaCatalogueGUI.
initForm(?ilExcCriteriaCatalogue $a_cat_obj=null)
add(?ilPropertyFormGUI $a_form=null)
importForm(?ilExcCriteriaCatalogue $a_cat_obj=null)
edit(?ilPropertyFormGUI $a_form=null)
exportForm(ilExcCriteriaCatalogue $a_cat_obj, ilPropertyFormGUI $a_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...
static getInstancesByParentId(int $a_parent_id)
Class ilExcCriteriaGUI.
language handling
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
Class ilObjExercise.
This class represents a property form user interface.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This class represents a text property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setOnScreenMessage(string $type, string $a_txt, bool $a_keep=false)
Set a message to be displayed to the user.
setContent(string $a_html)
Sets content for standard template.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $lng
Definition: privfeed.php:31
global $DIC
Definition: shib_login.php:26