ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilExcCriteriaCatalogueGUI.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
4
5include_once "Modules/Exercise/classes/class.ilExcCriteriaCatalogue.php";
6
15{
19 protected $ctrl;
20
24 protected $tabs;
25
29 protected $lng;
30
34 protected $toolbar;
35
39 protected $tpl;
40
41 protected $exc_obj; // [ilObjExercise]
42
43 public function __construct(ilObjExercise $a_exc_obj)
44 {
45 global $DIC;
46
47 $this->ctrl = $DIC->ctrl();
48 $this->tabs = $DIC->tabs();
49 $this->lng = $DIC->language();
50 $this->toolbar = $DIC->toolbar();
51 $this->tpl = $DIC["tpl"];
52 $this->exc_obj = $a_exc_obj;
53 }
54
55 public function executeCommand()
56 {
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 include_once "Modules/Exercise/classes/class.ilExcCriteriaGUI.php";
70 $crit_gui = new ilExcCriteriaGUI($_REQUEST["cat_id"]);
71 $ilCtrl->forwardCommand($crit_gui);
72 break;
73
74 default:
75 $this->$cmd();
76 break;
77 }
78 }
79
80
81 //
82 // LIST/TABLE
83 //
84
85 protected function view()
86 {
87 $ilToolbar = $this->toolbar;
91
92 $ilToolbar->addButton(
93 $lng->txt("exc_add_criteria_catalogue"),
94 $ilCtrl->getLinkTarget($this, "add")
95 );
96
97 include_once "Modules/Exercise/classes/class.ilExcCriteriaCatalogueTableGUI.php";
98 $tbl = new ilExcCriteriaCatalogueTableGUI($this, "view", $this->exc_obj->getId());
99 $tpl->setContent($tbl->getHTML());
100 }
101
102 protected function saveOrder()
103 {
106
107 $all_cat = ilExcCriteriaCatalogue::getInstancesByParentId($this->exc_obj->getId());
108
109 $pos = 0;
110 asort($_POST["pos"]);
111 foreach (array_keys($_POST["pos"]) as $id) {
112 if (array_key_exists($id, $all_cat)) {
113 $pos += 10;
114 $all_cat[$id]->setPosition($pos);
115 $all_cat[$id]->update();
116 }
117 }
118
119 ilUtil::sendSuccess($lng->txt("settings_saved"), true);
120 $ilCtrl->redirect($this, "view");
121 }
122
123 protected function confirmDeletion()
124 {
128
129 $ids = $_POST["id"];
130 if (!sizeof($ids)) {
131 ilUtil::sendInfo($lng->txt("select_one"), true);
132 $ilCtrl->redirect($this, "view");
133 }
134
135 include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
136 $confirmation_gui = new ilConfirmationGUI();
137 $confirmation_gui->setFormAction($ilCtrl->getFormAction($this, "delete"));
138 $confirmation_gui->setHeaderText($lng->txt("exc_criteria_catalogue_deletion_confirmation"));
139 $confirmation_gui->setCancel($lng->txt("cancel"), "view");
140 $confirmation_gui->setConfirm($lng->txt("delete"), "delete");
141
142 foreach (ilExcCriteriaCatalogue::getInstancesByParentId($this->exc_obj->getId()) as $item) {
143 if (in_array($item->getId(), $ids)) {
144 $confirmation_gui->addItem("id[]", $item->getId(), $item->getTitle());
145 }
146 }
147
148 $tpl->setContent($confirmation_gui->getHTML());
149 }
150
151 protected function delete()
152 {
155
156 $ids = $_POST["id"];
157 if (!sizeof($ids)) {
158 $ilCtrl->redirect($this, "view");
159 }
160
161 foreach (ilExcCriteriaCatalogue::getInstancesByParentId($this->exc_obj->getId()) as $item) {
162 if (in_array($item->getId(), $ids)) {
163 $item->delete();
164 }
165 }
166
167 ilUtil::sendSuccess($lng->txt("settings_saved"), true);
168 $ilCtrl->redirect($this, "view");
169 }
170
171
172 //
173 // EDIT
174 //
175
176 protected function initForm(ilExcCriteriaCatalogue $a_cat_obj = null)
177 {
180
181 include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
182 $form = new ilPropertyFormGUI();
183
184 $is_edit = ($a_cat_obj !== null);
185 if (!$is_edit) {
186 $form->setFormAction($ilCtrl->getFormAction($this, "create"));
187 $form->setTitle($lng->txt("exc_criteria_catalogue_create_form"));
188 $form->addCommandButton("create", $lng->txt("create"));
189 } else {
190 $form->setFormAction($ilCtrl->getFormAction($this, "update"));
191 $form->setTitle($lng->txt("exc_criteria_catalogue_update_form"));
192 $form->addCommandButton("update", $lng->txt("save"));
193 }
194
195 $form->addCommandButton("view", $lng->txt("cancel"));
196
197 $title = new ilTextInputGUI($lng->txt("title"), "title");
198 $title->setRequired(true);
199 $form->addItem($title);
200
201 return $form;
202 }
203
204 protected function add(ilPropertyFormGUI $a_form = null)
205 {
207
208 if (!$a_form) {
209 $a_form = $this->initForm();
210 }
211
212 $tpl->setContent($a_form->getHTML());
213 }
214
215 protected function exportForm(ilExcCriteriaCatalogue $a_cat_obj, ilPropertyFormGUI $a_form)
216 {
217 $a_form->getItemByPostVar("title")->setValue($a_cat_obj->getTitle());
218 }
219
220 protected function importForm(ilExcCriteriaCatalogue $a_cat_obj = null)
221 {
224
225 $is_edit = ($a_cat_obj !== null);
226
227 $form = $this->initForm($a_cat_obj);
228 if ($form->checkInput()) {
229 if (!$is_edit) {
230 $a_cat_obj = new ilExcCriteriaCatalogue();
231 $a_cat_obj->setParent($this->exc_obj->getId());
232 }
233
234 $a_cat_obj->setTitle($form->getInput("title"));
235
236 if (!$is_edit) {
237 $a_cat_obj->save();
238 } else {
239 $a_cat_obj->update();
240 }
241
242 ilUtil::sendSuccess($lng->txt("settings_saved"), true);
243 $ilCtrl->redirect($this, "view");
244 }
245
246 $form->setValuesByPost();
247 $this->{$is_edit ? "edit" : "add"}($form);
248 }
249
250 protected function create()
251 {
252 $this->importForm();
253 }
254
255 protected function getCurrentCatalogue()
256 {
258
259 $id = (int) $_REQUEST["cat_id"];
260 if ($id) {
261 $cat_obj = new ilExcCriteriaCatalogue($id);
262 if ($cat_obj->getParent() == $this->exc_obj->getId()) {
263 $ilCtrl->setParameter($this, "cat_id", $id);
264 return $cat_obj;
265 }
266 }
267
268 $ilCtrl->redirect($this, "view");
269 }
270
271 protected function edit(ilPropertyFormGUI $a_form = null)
272 {
274
275 $cat_obj = $this->getCurrentCatalogue();
276
277 if (!$a_form) {
278 $a_form = $this->initForm($cat_obj);
279 $this->exportForm($cat_obj, $a_form);
280 }
281
282 $tpl->setContent($a_form->getHTML());
283 }
284
285 protected function update()
286 {
287 $cat_obj = $this->getCurrentCatalogue();
288 $this->importForm($cat_obj);
289 }
290}
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
Confirmation screen class.
Class ilExcCriteriaCatalogueGUI.
edit(ilPropertyFormGUI $a_form=null)
importForm(ilExcCriteriaCatalogue $a_cat_obj=null)
add(ilPropertyFormGUI $a_form=null)
exportForm(ilExcCriteriaCatalogue $a_cat_obj, ilPropertyFormGUI $a_form)
initForm(ilExcCriteriaCatalogue $a_cat_obj=null)
Class ilExcCriteriaCatalogueTableGUI.
Class ilExcCriteriaCatalogue.
static getInstancesByParentId($a_parent_id)
Class ilExcCriteriaGUI.
Class ilObjExercise.
This class represents a property form user interface.
getItemByPostVar($a_post_var)
Get Item by POST variable.
This class represents a text property in a property form.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
$tbl
Definition: example_048.php:81
if(!array_key_exists('StateId', $_REQUEST)) $id
global $ilCtrl
Definition: ilias.php:18
if(isset($_POST['submit'])) $form
global $DIC
Definition: saml.php:7