ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilExcCriteriaGUI.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 
5 include_once "Modules/Exercise/classes/class.ilExcCriteria.php";
6 
15 {
16  protected $cat_id; // [int]
17 
18  public function __construct($a_cat_id)
19  {
20  $this->cat_id = $a_cat_id;
21  }
22 
23  public function executeCommand()
24  {
25  global $ilCtrl;
26 
27  $next_class = $ilCtrl->getNextClass($this);
28  $cmd = $ilCtrl->getCmd("view");
29 
30  switch($next_class)
31  {
32  default:
33  $this->$cmd();
34  break;
35  }
36  }
37 
38 
39  //
40  // LIST/TABLE
41  //
42 
43  protected function view()
44  {
45  global $ilToolbar, $ilCtrl, $lng, $tpl;
46 
47  $ilToolbar->setFormAction($ilCtrl->getFormAction($this, "add"));
48 
49  include_once "Services/Form/classes/class.ilSelectInputGUI.php";
50  $types = new ilSelectInputGUI($lng->txt("type"), "type");
52  $ilToolbar->addStickyItem($types);
53 
54  include_once "Services/UIComponent/Button/classes/class.ilSubmitButton.php";
55  $button = ilSubmitButton::getInstance();
56  $button->setCaption("exc_add_criteria");
57  $button->setCommand("add");
58  $ilToolbar->addStickyItem($button);
59 
60  include_once "Modules/Exercise/classes/class.ilExcCriteriaTableGUI.php";
61  $tbl = new ilExcCriteriaTableGUI($this, "view", $this->cat_id);
62  $tpl->setContent($tbl->getHTML());
63  }
64 
65  protected function saveOrder()
66  {
67  global $ilCtrl, $lng;
68 
69  $all_cat = ilExcCriteria::getInstancesByParentId($this->cat_id);
70 
71  $pos = 0;
72  asort($_POST["pos"]);
73  foreach(array_keys($_POST["pos"]) as $id)
74  {
75  if(array_key_exists($id, $all_cat))
76  {
77  $pos += 10;
78  $all_cat[$id]->setPosition($pos);
79  $all_cat[$id]->update();
80  }
81  }
82 
83  ilUtil::sendSuccess($lng->txt("settings_saved"), true);
84  $ilCtrl->redirect($this, "view");
85  }
86 
87  protected function confirmDeletion()
88  {
89  global $ilCtrl, $lng, $tpl;
90 
91  $ids = $_POST["id"];
92  if(!sizeof($ids))
93  {
94  ilUtil::sendInfo($lng->txt("select_one"), true);
95  $ilCtrl->redirect($this, "view");
96  }
97 
98  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
99  $confirmation_gui = new ilConfirmationGUI();
100  $confirmation_gui->setFormAction($ilCtrl->getFormAction($this, "delete"));
101  $confirmation_gui->setHeaderText($lng->txt("exc_criteria_deletion_confirmation"));
102  $confirmation_gui->setCancel($lng->txt("cancel"), "view");
103  $confirmation_gui->setConfirm($lng->txt("delete"), "delete");
104 
105  foreach(ilExcCriteria::getInstancesByParentId($this->cat_id) as $item)
106  {
107  if(in_array($item->getId(), $ids))
108  {
109  $confirmation_gui->addItem("id[]", $item->getId(), $item->getTitle());
110  }
111  }
112 
113  $tpl->setContent($confirmation_gui->getHTML());
114  }
115 
116  protected function delete()
117  {
118  global $ilCtrl, $lng;
119 
120  $ids = $_POST["id"];
121  if(!sizeof($ids))
122  {
123  $ilCtrl->redirect($this, "view");
124  }
125 
126  foreach(ilExcCriteria::getInstancesByParentId($this->cat_id) as $item)
127  {
128  if(in_array($item->getId(), $ids))
129  {
130  $item->delete();
131  }
132  }
133 
134  ilUtil::sendSuccess($lng->txt("settings_saved"), true);
135  $ilCtrl->redirect($this, "view");
136  }
137 
138 
139  //
140  // EDIT
141  //
142 
143  protected function initForm(ilExcCriteria $a_crit_obj)
144  {
145  global $ilCtrl, $lng;
146 
147  include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
148  $form = new ilPropertyFormGUI();
149 
150  $is_edit = (bool)$a_crit_obj->getId();
151  if(!$is_edit)
152  {
153  $form->setFormAction($ilCtrl->getFormAction($this, "create"));
154  $form->setTitle($lng->txt("exc_criteria_create_form"));
155  $form->addCommandButton("create", $lng->txt("create"));
156  }
157  else
158  {
159  $form->setFormAction($ilCtrl->getFormAction($this, "update"));
160  $form->setTitle($lng->txt("exc_criteria_update_form"));
161  $form->addCommandButton("update", $lng->txt("save"));
162  }
163 
164  $form->addCommandButton("view", $lng->txt("cancel"));
165 
166  $type = new ilNonEditableValueGUI($lng->txt("type"));
167  $type->setValue($a_crit_obj->getTranslatedType());
168  $form->addItem($type);
169 
170  $title = new ilTextInputGUI($lng->txt("title"), "title");
171  $title->setRequired(true);
172  $form->addItem($title);
173 
174  $desc = new ilTextAreaInputGUI($lng->txt("description"), "desc");
175  $form->addItem($desc);
176 
177  $req = new ilCheckboxInputGUI($lng->txt("required_field"), "req");
178  $form->addItem($req);
179 
180  $a_crit_obj->initCustomForm($form);
181 
182  return $form;
183  }
184 
185  protected function add(ilPropertyFormGUI $a_form = null)
186  {
187  global $tpl, $ilCtrl;
188 
189  $new_type = trim($_REQUEST["type"]);
190  if(!$new_type)
191  {
192  $ilCtrl->redirect($this, "view");
193  }
194 
195  $ilCtrl->setParameter($this, "type", $new_type);
196 
197  if(!$a_form)
198  {
199  $crit_obj = ilExcCriteria::getInstanceByType($new_type);
200  $a_form = $this->initForm($crit_obj);
201  }
202 
203  $tpl->setContent($a_form->getHTML());
204  }
205 
206  protected function exportForm(ilExcCriteria $a_crit_obj, ilPropertyFormGUI $a_form)
207  {
208  $a_form->getItemByPostVar("title")->setValue($a_crit_obj->getTitle());
209  $a_form->getItemByPostVar("desc")->setValue($a_crit_obj->getDescription());
210  $a_form->getItemByPostVar("req")->setChecked($a_crit_obj->isRequired());
211 
212  $a_crit_obj->exportCustomForm($a_form);
213  }
214 
215  protected function importForm(ilExcCriteria $a_crit_obj)
216  {
217  global $ilCtrl, $lng;
218 
219  $is_edit = (bool)$a_crit_obj->getId();
220 
221  $form = $this->initForm($a_crit_obj);
222  if($form->checkInput())
223  {
224  $a_crit_obj->setTitle($form->getInput("title"));
225  $a_crit_obj->setDescription($form->getInput("desc"));
226  $a_crit_obj->setRequired($form->getInput("req"));
227 
228  $a_crit_obj->importCustomForm($form);
229 
230  if(!$is_edit)
231  {
232  $a_crit_obj->setParent($this->cat_id);
233  $a_crit_obj->save();
234  }
235  else
236  {
237  $a_crit_obj->update();
238  }
239 
240  ilUtil::sendSuccess($lng->txt("settings_saved"), true);
241  $ilCtrl->redirect($this, "view");
242  }
243 
244  $form->setValuesByPost();
245  $this->{$is_edit ? "edit" : "add"}($form);
246  }
247 
248  protected function create()
249  {
250  global $ilCtrl;
251 
252  $new_type = trim($_REQUEST["type"]);
253  if(!$new_type)
254  {
255  $ilCtrl->redirect($this, "view");
256  }
257 
258  $crit_obj = ilExcCriteria::getInstanceByType($new_type);
259  $this->importForm($crit_obj);
260  }
261 
262  protected function getCurrentCritera()
263  {
264  global $ilCtrl;
265 
266  $id = (int)$_REQUEST["crit_id"];
267  if($id)
268  {
269  $crit_obj = ilExcCriteria::getInstanceById($id);
270  if($crit_obj->getParent() == $this->cat_id)
271  {
272  $ilCtrl->setParameter($this, "crit_id", $id);
273  return $crit_obj;
274  }
275  }
276 
277  $ilCtrl->redirect($this, "view");
278  }
279 
280  protected function edit(ilPropertyFormGUI $a_form = null)
281  {
282  global $tpl;
283 
284  $crit_obj = $this->getCurrentCritera();
285 
286  if(!$a_form)
287  {
288  $a_form = $this->initForm($crit_obj);
289  $this->exportForm($crit_obj, $a_form);
290  }
291 
292  $tpl->setContent($a_form->getHTML());
293  }
294 
295  protected function update()
296  {
297  $crit_obj = $this->getCurrentCritera();
298  $this->importForm($crit_obj);
299  }
300 
301 }
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
static getInstanceByType($a_type)
importCustomForm(ilPropertyFormGUI $a_form)
Class ilExcCriteria.
getItemByPostVar($a_post_var)
Get Item by POST variable.
This class represents a selection list property in a property form.
This class represents a property form user interface.
$tbl
Definition: example_048.php:81
static getInstanceById($a_id)
$cmd
Definition: sahs_server.php:35
This class represents a checkbox property in a property form.
exportCustomForm(ilPropertyFormGUI $a_form)
global $tpl
Definition: ilias.php:8
global $ilCtrl
Definition: ilias.php:18
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
add(ilPropertyFormGUI $a_form=null)
static getInstancesByParentId($a_parent_id)
This class represents a text property in a property form.
Class ilExcCriteriaGUI.
setOptions($a_options)
Set Options.
edit(ilPropertyFormGUI $a_form=null)
This class represents a non editable value in a property form.
global $lng
Definition: privfeed.php:17
This class represents a text area property in a property form.
exportForm(ilExcCriteria $a_crit_obj, ilPropertyFormGUI $a_form)
initCustomForm(ilPropertyFormGUI $a_form)
initForm(ilExcCriteria $a_crit_obj)
Class ilExcCriteriaTableGUI.
$_POST["username"]
importForm(ilExcCriteria $a_crit_obj)
Confirmation screen class.