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