ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilExcCriteriaGUI.php
Go to the documentation of this file.
1<?php
2
20
29{
30 protected \ILIAS\Exercise\InternalGUIService $gui;
31 protected ilCtrl $ctrl;
33 protected ilLanguage $lng;
35 protected int $cat_id;
37
38 public function __construct(int $a_cat_id)
39 {
40 global $DIC;
41
42 $this->ctrl = $DIC->ctrl();
43 $this->toolbar = $DIC->toolbar();
44 $this->lng = $DIC->language();
45 $this->tpl = $DIC["tpl"];
46 $this->cat_id = $a_cat_id;
47 $this->request = $DIC->exercise()->internal()->gui()->request();
48 $this->gui = $DIC->exercise()->internal()->gui();
49 }
50
51 public function executeCommand(): void
52 {
53 $ilCtrl = $this->ctrl;
54
55 $next_class = $ilCtrl->getNextClass($this);
56 $cmd = $ilCtrl->getCmd("view");
57
58 switch ($next_class) {
59 default:
60 $this->$cmd();
61 break;
62 }
63 }
64
65
66 //
67 // LIST/TABLE
68 //
69
70 protected function view(): void
71 {
72 $ilToolbar = $this->toolbar;
73 $ilCtrl = $this->ctrl;
76
77 $ilToolbar->setFormAction($ilCtrl->getFormAction($this, "add"));
78
79 $types = new ilSelectInputGUI($lng->txt("type"), "type");
80 $types->setOptions(ilExcCriteria::getTypesMap());
81 $ilToolbar->addStickyItem($types);
82
83 $this->gui->button(
84 $lng->txt("exc_add_criteria"),
85 "add"
86 )->submit()->toToolbar(true);
87
88 $tbl = new ilExcCriteriaTableGUI($this, "view", $this->cat_id);
89 $tpl->setContent($tbl->getHTML());
90 }
91
92 protected function saveOrder(): void
93 {
94 $ilCtrl = $this->ctrl;
96
97 $all_cat = ilExcCriteria::getInstancesByParentId($this->cat_id);
98
99 $pos = 0;
100 $req_positions = $this->request->getPositions();
101 asort($req_positions);
102 foreach (array_keys($req_positions) as $id) {
103 if (array_key_exists($id, $all_cat)) {
104 $pos += 10;
105 $all_cat[$id]->setPosition($pos);
106 $all_cat[$id]->update();
107 }
108 }
109
110 $this->tpl->setOnScreenMessage('success', $lng->txt("settings_saved"), true);
111 $ilCtrl->redirect($this, "view");
112 }
113
114 protected function confirmDeletion(): void
115 {
116 $ilCtrl = $this->ctrl;
119
120 $ids = $this->request->getCriteriaIds();
121 if (count($ids) == 0) {
122 $this->tpl->setOnScreenMessage('info', $lng->txt("select_one"), true);
123 $ilCtrl->redirect($this, "view");
124 }
125
126 $confirmation_gui = new ilConfirmationGUI();
127 $confirmation_gui->setFormAction($ilCtrl->getFormAction($this, "delete"));
128 $confirmation_gui->setHeaderText($lng->txt("exc_criteria_deletion_confirmation"));
129 $confirmation_gui->setCancel($lng->txt("cancel"), "view");
130 $confirmation_gui->setConfirm($lng->txt("delete"), "delete");
131
132 foreach (ilExcCriteria::getInstancesByParentId($this->cat_id) as $item) {
133 if (in_array($item->getId(), $ids)) {
134 $confirmation_gui->addItem("id[]", $item->getId(), $item->getTitle());
135 }
136 }
137
138 $tpl->setContent($confirmation_gui->getHTML());
139 }
140
141 protected function delete(): void
142 {
143 $ilCtrl = $this->ctrl;
145
146 $ids = $this->request->getCriteriaIds();
147 if (count($ids) == 0) {
148 $ilCtrl->redirect($this, "view");
149 }
150
151 foreach (ilExcCriteria::getInstancesByParentId($this->cat_id) as $item) {
152 if (in_array($item->getId(), $ids)) {
153 $item->delete();
154 }
155 }
156
157 $this->tpl->setOnScreenMessage('success', $lng->txt("settings_saved"), true);
158 $ilCtrl->redirect($this, "view");
159 }
160
161
162 //
163 // EDIT
164 //
165
166 protected function initForm(ilExcCriteria $a_crit_obj): ilPropertyFormGUI
167 {
168 $ilCtrl = $this->ctrl;
170
171 $form = new ilPropertyFormGUI();
172
173 $is_edit = (bool) $a_crit_obj->getId();
174 if (!$is_edit) {
175 $form->setFormAction($ilCtrl->getFormAction($this, "create"));
176 $form->setTitle($lng->txt("exc_criteria_create_form"));
177 $form->addCommandButton("create", $lng->txt("create"));
178 } else {
179 $form->setFormAction($ilCtrl->getFormAction($this, "update"));
180 $form->setTitle($lng->txt("exc_criteria_update_form"));
181 $form->addCommandButton("update", $lng->txt("save"));
182 }
183
184 $form->addCommandButton("view", $lng->txt("cancel"));
185
186 $type = new ilNonEditableValueGUI($lng->txt("type"));
187 $type->setValue($a_crit_obj->getTranslatedType());
188 $form->addItem($type);
189
190 $title = new ilTextInputGUI($lng->txt("title"), "title");
191 $title->setRequired(true);
192 $form->addItem($title);
193
194 $desc = new ilTextAreaInputGUI($lng->txt("description"), "desc");
195 $form->addItem($desc);
196
197 $req = new ilCheckboxInputGUI($lng->txt("required_field"), "req");
198 $form->addItem($req);
199
200 $a_crit_obj->initCustomForm($form);
201
202 return $form;
203 }
204
205 protected function add(?ilPropertyFormGUI $a_form = null): void
206 {
208 $ilCtrl = $this->ctrl;
209
210 $new_type = $this->request->getCriteriaType();
211 if (!$new_type) {
212 $ilCtrl->redirect($this, "view");
213 }
214
215 $ilCtrl->setParameter($this, "type", $new_type);
216
217 if (!$a_form) {
218 $crit_obj = ilExcCriteria::getInstanceByType($new_type);
219 $a_form = $this->initForm($crit_obj);
220 }
221
222 $tpl->setContent($a_form->getHTML());
223 }
224
225 protected function exportForm(
226 ilExcCriteria $a_crit_obj,
227 ilPropertyFormGUI $a_form
228 ): void {
229 $a_form->getItemByPostVar("title")->setValue($a_crit_obj->getTitle());
230 $a_form->getItemByPostVar("desc")->setValue($a_crit_obj->getDescription());
231 $a_form->getItemByPostVar("req")->setChecked($a_crit_obj->isRequired());
232
233 $a_crit_obj->exportCustomForm($a_form);
234 }
235
236 protected function importForm(
237 ilExcCriteria $a_crit_obj
238 ): void {
239 $ilCtrl = $this->ctrl;
241
242 $is_edit = (bool) $a_crit_obj->getId();
243 $ilCtrl->setParameter($this, "type", $this->request->getCriteriaType());
244 $form = $this->initForm($a_crit_obj);
245 if ($form->checkInput()) {
246 $a_crit_obj->setTitle($form->getInput("title"));
247 $a_crit_obj->setDescription($form->getInput("desc"));
248 $a_crit_obj->setRequired($form->getInput("req"));
249
250 $a_crit_obj->importCustomForm($form);
251
252 if (!$is_edit) {
253 $a_crit_obj->setParent($this->cat_id);
254 $a_crit_obj->save();
255 } else {
256 $a_crit_obj->update();
257 }
258
259 $this->tpl->setOnScreenMessage('success', $lng->txt("settings_saved"), true);
260 $ilCtrl->redirect($this, "view");
261 }
262
263 $form->setValuesByPost();
264 $this->{$is_edit ? "edit" : "add"}($form);
265 }
266
267 protected function create(): void
268 {
269 $ilCtrl = $this->ctrl;
270
271 $new_type = $this->request->getCriteriaType();
272 if (!$new_type) {
273 $ilCtrl->redirect($this, "view");
274 }
275
276 $crit_obj = ilExcCriteria::getInstanceByType($new_type);
277 $this->importForm($crit_obj);
278 }
279
280 protected function getCurrentCritera(): ?ilExcCriteria
281 {
282 $ilCtrl = $this->ctrl;
283
284 $id = $this->request->getCritId();
285 if ($id) {
287 if ($crit_obj->getParent() == $this->cat_id) {
288 $ilCtrl->setParameter($this, "crit_id", $id);
289 return $crit_obj;
290 }
291 }
292
293 $ilCtrl->redirect($this, "view");
294
295 return null;
296 }
297
298 protected function edit(?ilPropertyFormGUI $a_form = null): void
299 {
300 $tpl = $this->tpl;
301
302 $crit_obj = $this->getCurrentCritera();
303
304 if (!$a_form) {
305 $a_form = $this->initForm($crit_obj);
306 $this->exportForm($crit_obj, $a_form);
307 }
308
309 $tpl->setContent($a_form->getHTML());
310 }
311
312 protected function update(): void
313 {
314 $crit_obj = $this->getCurrentCritera();
315 $this->importForm($crit_obj);
316 }
317}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Exercise gui request wrapper.
This class represents a checkbox property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilCtrl provides processing control methods.
getNextClass($a_gui_class=null)
@inheritDoc
redirect(object $a_gui_obj, ?string $a_cmd=null, ?string $a_anchor=null, bool $is_async=false)
@inheritDoc
Class ilExcCriteriaGUI.
add(?ilPropertyFormGUI $a_form=null)
initForm(ilExcCriteria $a_crit_obj)
__construct(int $a_cat_id)
ilGlobalTemplateInterface $tpl
edit(?ilPropertyFormGUI $a_form=null)
ILIAS Exercise InternalGUIService $gui
importForm(ilExcCriteria $a_crit_obj)
exportForm(ilExcCriteria $a_crit_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...
initCustomForm(ilPropertyFormGUI $a_form)
exportCustomForm(ilPropertyFormGUI $a_form)
setRequired(bool $a_value)
setTitle(?string $a_value)
importCustomForm(ilPropertyFormGUI $a_form)
setDescription(?string $a_value)
static getInstancesByParentId(int $a_parent_id)
static getInstanceById(int $a_id)
setParent(?int $a_value)
static getInstanceByType(string $a_type)
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...
This class represents a non editable value in a property form.
This class represents a property form user interface.
getItemByPostVar(string $a_post_var)
This class represents a selection list property in a property form.
This class represents a text area property in a property form.
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.
catch(\Exception $e) $req
Definition: xapiproxy.php:91
global $lng
Definition: privfeed.php:31
global $DIC
Definition: shib_login.php:26