ILIAS  release_7 Revision v7.30-3-g800a261c036
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
13{
17 protected $ctrl;
18
22 protected $tabs;
23
27 protected $lng;
28
32 protected $toolbar;
33
37 protected $tpl;
38
39 protected $exc_obj; // [ilObjExercise]
40
41 public function __construct(ilObjExercise $a_exc_obj)
42 {
43 global $DIC;
44
45 $this->ctrl = $DIC->ctrl();
46 $this->tabs = $DIC->tabs();
47 $this->lng = $DIC->language();
48 $this->toolbar = $DIC->toolbar();
49 $this->tpl = $DIC["tpl"];
50 $this->exc_obj = $a_exc_obj;
51 }
52
53 public function executeCommand()
54 {
55 $ilCtrl = $this->ctrl;
56 $ilTabs = $this->tabs;
58
59 $next_class = $ilCtrl->getNextClass($this);
60 $cmd = $ilCtrl->getCmd("view");
61
62 switch ($next_class) {
63 case "ilexccriteriagui":
64 $ilTabs->clearTargets();
65 $ilTabs->setBackTarget($lng->txt("back"), $ilCtrl->getLinkTarget($this, ""));
66 $ilCtrl->saveParameter($this, "cat_id");
67 $crit_gui = new ilExcCriteriaGUI($_REQUEST["cat_id"]);
68 $ilCtrl->forwardCommand($crit_gui);
69 break;
70
71 default:
72 $this->$cmd();
73 break;
74 }
75 }
76
77
78 //
79 // LIST/TABLE
80 //
81
82 protected function view()
83 {
84 $ilToolbar = $this->toolbar;
85 $ilCtrl = $this->ctrl;
88
89 $ilToolbar->addButton(
90 $lng->txt("exc_add_criteria_catalogue"),
91 $ilCtrl->getLinkTarget($this, "add")
92 );
93
94 $tbl = new ilExcCriteriaCatalogueTableGUI($this, "view", $this->exc_obj->getId());
95 $tpl->setContent($tbl->getHTML());
96 }
97
98 protected function saveOrder()
99 {
100 $ilCtrl = $this->ctrl;
102
103 $all_cat = ilExcCriteriaCatalogue::getInstancesByParentId($this->exc_obj->getId());
104
105 $pos = 0;
106 asort($_POST["pos"]);
107 foreach (array_keys($_POST["pos"]) as $id) {
108 if (array_key_exists($id, $all_cat)) {
109 $pos += 10;
110 $all_cat[$id]->setPosition($pos);
111 $all_cat[$id]->update();
112 }
113 }
114
115 ilUtil::sendSuccess($lng->txt("settings_saved"), true);
116 $ilCtrl->redirect($this, "view");
117 }
118
119 protected function confirmDeletion()
120 {
121 $ilCtrl = $this->ctrl;
124
125 $ids = $_POST["id"];
126 if (!sizeof($ids)) {
127 ilUtil::sendInfo($lng->txt("select_one"), true);
128 $ilCtrl->redirect($this, "view");
129 }
130
131 $confirmation_gui = new ilConfirmationGUI();
132 $confirmation_gui->setFormAction($ilCtrl->getFormAction($this, "delete"));
133 $confirmation_gui->setHeaderText($lng->txt("exc_criteria_catalogue_deletion_confirmation"));
134 $confirmation_gui->setCancel($lng->txt("cancel"), "view");
135 $confirmation_gui->setConfirm($lng->txt("delete"), "delete");
136
137 foreach (ilExcCriteriaCatalogue::getInstancesByParentId($this->exc_obj->getId()) as $item) {
138 if (in_array($item->getId(), $ids)) {
139 $confirmation_gui->addItem("id[]", $item->getId(), $item->getTitle());
140 }
141 }
142
143 $tpl->setContent($confirmation_gui->getHTML());
144 }
145
146 protected function delete()
147 {
148 $ilCtrl = $this->ctrl;
150
151 $ids = $_POST["id"];
152 if (!sizeof($ids)) {
153 $ilCtrl->redirect($this, "view");
154 }
155
156 foreach (ilExcCriteriaCatalogue::getInstancesByParentId($this->exc_obj->getId()) as $item) {
157 if (in_array($item->getId(), $ids)) {
158 $item->delete();
159 }
160 }
161
162 ilUtil::sendSuccess($lng->txt("settings_saved"), true);
163 $ilCtrl->redirect($this, "view");
164 }
165
166
167 //
168 // EDIT
169 //
170
171 protected function initForm(ilExcCriteriaCatalogue $a_cat_obj = null)
172 {
173 $ilCtrl = $this->ctrl;
175
176 $form = new ilPropertyFormGUI();
177
178 $is_edit = ($a_cat_obj !== null);
179 if (!$is_edit) {
180 $form->setFormAction($ilCtrl->getFormAction($this, "create"));
181 $form->setTitle($lng->txt("exc_criteria_catalogue_create_form"));
182 $form->addCommandButton("create", $lng->txt("create"));
183 } else {
184 $form->setFormAction($ilCtrl->getFormAction($this, "update"));
185 $form->setTitle($lng->txt("exc_criteria_catalogue_update_form"));
186 $form->addCommandButton("update", $lng->txt("save"));
187 }
188
189 $form->addCommandButton("view", $lng->txt("cancel"));
190
191 $title = new ilTextInputGUI($lng->txt("title"), "title");
192 $title->setRequired(true);
193 $form->addItem($title);
194
195 return $form;
196 }
197
198 protected function add(ilPropertyFormGUI $a_form = null)
199 {
201
202 if (!$a_form) {
203 $a_form = $this->initForm();
204 }
205
206 $tpl->setContent($a_form->getHTML());
207 }
208
209 protected function exportForm(ilExcCriteriaCatalogue $a_cat_obj, ilPropertyFormGUI $a_form)
210 {
211 $a_form->getItemByPostVar("title")->setValue($a_cat_obj->getTitle());
212 }
213
214 protected function importForm(ilExcCriteriaCatalogue $a_cat_obj = null)
215 {
216 $ilCtrl = $this->ctrl;
218
219 $is_edit = ($a_cat_obj !== null);
220
221 $form = $this->initForm($a_cat_obj);
222 if ($form->checkInput()) {
223 if (!$is_edit) {
224 $a_cat_obj = new ilExcCriteriaCatalogue();
225 $a_cat_obj->setParent($this->exc_obj->getId());
226 }
227
228 $a_cat_obj->setTitle($form->getInput("title"));
229
230 if (!$is_edit) {
231 $a_cat_obj->save();
232 } else {
233 $a_cat_obj->update();
234 }
235
236 ilUtil::sendSuccess($lng->txt("settings_saved"), true);
237 $ilCtrl->redirect($this, "view");
238 }
239
240 $form->setValuesByPost();
241 $this->{$is_edit ? "edit" : "add"}($form);
242 }
243
244 protected function create()
245 {
246 $this->importForm();
247 }
248
249 protected function getCurrentCatalogue()
250 {
251 $ilCtrl = $this->ctrl;
252
253 $id = (int) $_REQUEST["cat_id"];
254 if ($id) {
255 $cat_obj = new ilExcCriteriaCatalogue($id);
256 if ($cat_obj->getParent() == $this->exc_obj->getId()) {
257 $ilCtrl->setParameter($this, "cat_id", $id);
258 return $cat_obj;
259 }
260 }
261
262 $ilCtrl->redirect($this, "view");
263 }
264
265 protected function edit(ilPropertyFormGUI $a_form = null)
266 {
268
269 $cat_obj = $this->getCurrentCatalogue();
270
271 if (!$a_form) {
272 $a_form = $this->initForm($cat_obj);
273 $this->exportForm($cat_obj, $a_form);
274 }
275
276 $tpl->setContent($a_form->getHTML());
277 }
278
279 protected function update()
280 {
281 $cat_obj = $this->getCurrentCatalogue();
282 $this->importForm($cat_obj);
283 }
284}
$_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.
global $DIC
Definition: goto.php:24