ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 
5 include_once "Modules/Exercise/classes/class.ilExcCriteriaCatalogue.php";
6 
15 {
16  protected $exc_obj; // [ilObjExercise]
17 
18  public function __construct(ilObjExercise $a_exc_obj)
19  {
20  $this->exc_obj = $a_exc_obj;
21  }
22 
23  public function executeCommand()
24  {
25  global $ilCtrl, $ilTabs, $lng;
26 
27  $next_class = $ilCtrl->getNextClass($this);
28  $cmd = $ilCtrl->getCmd("view");
29 
30  switch($next_class)
31  {
32  case "ilexccriteriagui":
33  $ilTabs->clearTargets();
34  $ilTabs->setBackTarget($lng->txt("back"), $ilCtrl->getLinkTarget($this, ""));
35  $ilCtrl->saveParameter($this, "cat_id");
36  include_once "Modules/Exercise/classes/class.ilExcCriteriaGUI.php";
37  $crit_gui = new ilExcCriteriaGUI($_REQUEST["cat_id"]);
38  $ilCtrl->forwardCommand($crit_gui);
39  break;
40 
41  default:
42  $this->$cmd();
43  break;
44  }
45  }
46 
47 
48  //
49  // LIST/TABLE
50  //
51 
52  protected function view()
53  {
54  global $ilToolbar, $ilCtrl, $lng, $tpl;
55 
56  $ilToolbar->addButton($lng->txt("exc_add_criteria_catalogue"),
57  $ilCtrl->getLinkTarget($this, "add"));
58 
59  include_once "Modules/Exercise/classes/class.ilExcCriteriaCatalogueTableGUI.php";
60  $tbl = new ilExcCriteriaCatalogueTableGUI($this, "view", $this->exc_obj->getId());
61  $tpl->setContent($tbl->getHTML());
62  }
63 
64  protected function saveOrder()
65  {
66  global $ilCtrl, $lng;
67 
68  $all_cat = ilExcCriteriaCatalogue::getInstancesByParentId($this->exc_obj->getId());
69 
70  $pos = 0;
71  asort($_POST["pos"]);
72  foreach(array_keys($_POST["pos"]) as $id)
73  {
74  if(array_key_exists($id, $all_cat))
75  {
76  $pos += 10;
77  $all_cat[$id]->setPosition($pos);
78  $all_cat[$id]->update();
79  }
80  }
81 
82  ilUtil::sendSuccess($lng->txt("settings_saved"), true);
83  $ilCtrl->redirect($this, "view");
84  }
85 
86  protected function confirmDeletion()
87  {
88  global $ilCtrl, $lng, $tpl;
89 
90  $ids = $_POST["id"];
91  if(!sizeof($ids))
92  {
93  ilUtil::sendInfo($lng->txt("select_one"), true);
94  $ilCtrl->redirect($this, "view");
95  }
96 
97  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
98  $confirmation_gui = new ilConfirmationGUI();
99  $confirmation_gui->setFormAction($ilCtrl->getFormAction($this, "delete"));
100  $confirmation_gui->setHeaderText($lng->txt("exc_criteria_catalogue_deletion_confirmation"));
101  $confirmation_gui->setCancel($lng->txt("cancel"), "view");
102  $confirmation_gui->setConfirm($lng->txt("delete"), "delete");
103 
104  foreach(ilExcCriteriaCatalogue::getInstancesByParentId($this->exc_obj->getId()) as $item)
105  {
106  if(in_array($item->getId(), $ids))
107  {
108  $confirmation_gui->addItem("id[]", $item->getId(), $item->getTitle());
109  }
110  }
111 
112  $tpl->setContent($confirmation_gui->getHTML());
113  }
114 
115  protected function delete()
116  {
117  global $ilCtrl, $lng;
118 
119  $ids = $_POST["id"];
120  if(!sizeof($ids))
121  {
122  $ilCtrl->redirect($this, "view");
123  }
124 
125  foreach(ilExcCriteriaCatalogue::getInstancesByParentId($this->exc_obj->getId()) as $item)
126  {
127  if(in_array($item->getId(), $ids))
128  {
129  $item->delete();
130  }
131  }
132 
133  ilUtil::sendSuccess($lng->txt("settings_saved"), true);
134  $ilCtrl->redirect($this, "view");
135  }
136 
137 
138  //
139  // EDIT
140  //
141 
142  protected function initForm(ilExcCriteriaCatalogue $a_cat_obj = null)
143  {
144  global $ilCtrl, $lng;
145 
146  include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
147  $form = new ilPropertyFormGUI();
148 
149  $is_edit = ($a_cat_obj !== null);
150  if(!$is_edit)
151  {
152  $form->setFormAction($ilCtrl->getFormAction($this, "create"));
153  $form->setTitle($lng->txt("exc_criteria_catalogue_create_form"));
154  $form->addCommandButton("create", $lng->txt("create"));
155  }
156  else
157  {
158  $form->setFormAction($ilCtrl->getFormAction($this, "update"));
159  $form->setTitle($lng->txt("exc_criteria_catalogue_update_form"));
160  $form->addCommandButton("update", $lng->txt("save"));
161  }
162 
163  $form->addCommandButton("view", $lng->txt("cancel"));
164 
165  $title = new ilTextInputGUI($lng->txt("title"), "title");
166  $title->setRequired(true);
167  $form->addItem($title);
168 
169  return $form;
170  }
171 
172  protected function add(ilPropertyFormGUI $a_form = null)
173  {
174  global $tpl;
175 
176  if(!$a_form)
177  {
178  $a_form = $this->initForm();
179  }
180 
181  $tpl->setContent($a_form->getHTML());
182  }
183 
184  protected function exportForm(ilExcCriteriaCatalogue $a_cat_obj, ilPropertyFormGUI $a_form)
185  {
186  $a_form->getItemByPostVar("title")->setValue($a_cat_obj->getTitle());
187  }
188 
189  protected function importForm(ilExcCriteriaCatalogue $a_cat_obj = null)
190  {
191  global $ilCtrl, $lng;
192 
193  $is_edit = ($a_cat_obj !== null);
194 
195  $form = $this->initForm($a_cat_obj);
196  if($form->checkInput())
197  {
198  if(!$is_edit)
199  {
200  $a_cat_obj = new ilExcCriteriaCatalogue();
201  $a_cat_obj->setParent($this->exc_obj->getId());
202  }
203 
204  $a_cat_obj->setTitle($form->getInput("title"));
205 
206  if(!$is_edit)
207  {
208  $a_cat_obj->save();
209  }
210  else
211  {
212  $a_cat_obj->update();
213  }
214 
215  ilUtil::sendSuccess($lng->txt("settings_saved"), true);
216  $ilCtrl->redirect($this, "view");
217  }
218 
219  $form->setValuesByPost();
220  $this->{$is_edit ? "edit" : "add"}($form);
221  }
222 
223  protected function create()
224  {
225  $this->importForm();
226  }
227 
228  protected function getCurrentCatalogue()
229  {
230  global $ilCtrl;
231 
232  $id = (int)$_REQUEST["cat_id"];
233  if($id)
234  {
235  $cat_obj = new ilExcCriteriaCatalogue($id);
236  if($cat_obj->getParent() == $this->exc_obj->getId())
237  {
238  $ilCtrl->setParameter($this, "cat_id", $id);
239  return $cat_obj;
240  }
241  }
242 
243  $ilCtrl->redirect($this, "view");
244  }
245 
246  protected function edit(ilPropertyFormGUI $a_form = null)
247  {
248  global $tpl;
249 
250  $cat_obj = $this->getCurrentCatalogue();
251 
252  if(!$a_form)
253  {
254  $a_form = $this->initForm($cat_obj);
255  $this->exportForm($cat_obj, $a_form);
256  }
257 
258  $tpl->setContent($a_form->getHTML());
259  }
260 
261  protected function update()
262  {
263  $cat_obj = $this->getCurrentCatalogue();
264  $this->importForm($cat_obj);
265  }
266 
267 
268 
269 }
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
Class ilExcCriteriaCatalogue.
Class ilExcCriteriaCatalogueGUI.
initForm(ilExcCriteriaCatalogue $a_cat_obj=null)
getItemByPostVar($a_post_var)
Get Item by POST variable.
This class represents a property form user interface.
$tbl
Definition: example_048.php:81
$cmd
Definition: sahs_server.php:35
add(ilPropertyFormGUI $a_form=null)
global $tpl
Definition: ilias.php:8
global $ilCtrl
Definition: ilias.php:18
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
Class ilObjExercise.
exportForm(ilExcCriteriaCatalogue $a_cat_obj, ilPropertyFormGUI $a_form)
Class ilExcCriteriaCatalogueTableGUI.
This class represents a text property in a property form.
Class ilExcCriteriaGUI.
edit(ilPropertyFormGUI $a_form=null)
static getInstancesByParentId($a_parent_id)
global $lng
Definition: privfeed.php:17
importForm(ilExcCriteriaCatalogue $a_cat_obj=null)
$_POST["username"]
Confirmation screen class.