ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilRatingCategoryGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2011 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once("./Services/Rating/classes/class.ilRatingCategory.php");
5 
15 {
16  protected $parent_id; // [int]
17  protected $export_callback; // [string|array]
18  protected $export_subobj_title; // [string]
19 
20  function __construct($a_parent_id, $a_export_callback = null, $a_export_subobj_title = null)
21  {
22  global $lng;
23 
24  $this->parent_id = (int)$a_parent_id;
25  $this->export_callback = $a_export_callback;
26  $this->export_subobj_title = $a_export_subobj_title;
27 
28  $lng->loadLanguageModule("rating");
29 
30  if($_REQUEST["cat_id"])
31  {
32  $cat = new ilRatingCategory($_REQUEST["cat_id"]);
33  if($cat->getParentId() == $this->parent_id)
34  {
35  $this->cat_id = $cat->getId();
36  }
37  }
38  }
39 
43  function executeCommand()
44  {
45  global $ilCtrl;
46 
47  $next_class = $ilCtrl->getNextClass($this);
48  $cmd = $ilCtrl->getCmd("listCategories");
49 
50  switch($next_class)
51  {
52  default:
53  return $this->$cmd();
54  break;
55  }
56  }
57 
58  protected function listCategories()
59  {
60  global $tpl, $ilToolbar, $lng, $ilCtrl;
61 
62  $ilToolbar->addButton($lng->txt("rating_add_category"),
63  $ilCtrl->getLinkTarget($this, "add"));
64 
65  $ilToolbar->addSeparator();
66 
67  $ilToolbar->addButton($lng->txt("export"),
68  $ilCtrl->getLinkTarget($this, "export"));
69 
70  include_once "Services/Rating/classes/class.ilRatingCategoryTableGUI.php";
71  $table = new ilRatingCategoryTableGUI($this, "listCategories", $this->parent_id);
72  $tpl->setContent($table->getHTML());
73  }
74 
75 
76  protected function initCategoryForm($a_id = null)
77  {
78  global $lng, $ilCtrl;
79 
80  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
81  $form = new ilPropertyFormGUI();
82  $form->setTarget("_top");
83  $form->setFormAction($ilCtrl->getFormAction($this, "save"));
84  $form->setTitle($lng->txt("rating_category_".($a_id ? "edit" : "create")));
85 
86  // title
87  $ti = new ilTextInputGUI($lng->txt("title"), "title");
88  $ti->setMaxLength(128);
89  $ti->setSize(40);
90  $ti->setRequired(true);
91  $form->addItem($ti);
92 
93  // description
94  $ta = new ilTextAreaInputGUI($lng->txt("description"), "desc");
95  $ta->setCols(40);
96  $ta->setRows(2);
97  $form->addItem($ta);
98 
99  if(!$a_id)
100  {
101  $form->addCommandButton("save", $lng->txt("rating_category_add"));
102  }
103  else
104  {
105  $cat = new ilRatingCategory($a_id);
106  $ti->setValue($cat->getTitle());
107  $ta->setValue($cat->getDescription());
108 
109  $form->addCommandButton("update", $lng->txt("rating_category_update"));
110  }
111  $form->addCommandButton("listCategories", $lng->txt("cancel"));
112 
113  return $form;
114  }
115 
116  protected function add($a_form = null)
117  {
118  global $tpl;
119 
120  if(!$a_form)
121  {
122  $a_form = $this->initCategoryForm();
123  }
124 
125  $tpl->setContent($a_form->getHTML());
126  }
127 
128  protected function save()
129  {
130  global $ilCtrl, $lng;
131 
132  $form = $this->initCategoryForm("create");
133  if($form->checkInput())
134  {
135  include_once "Services/Rating/classes/class.ilRatingCategory.php";
136  $cat = new ilRatingCategory();
137  $cat->setParentId($this->parent_id);
138  $cat->setTitle($form->getInput("title"));
139  $cat->setDescription($form->getInput("desc"));
140  $cat->save();
141 
142  ilUtil::sendSuccess($lng->txt("rating_category_created"));
143  $ilCtrl->redirect($this, "listCategories");
144  }
145 
146  $form->setValuesByPost();
147  $this->add($form);
148  }
149 
150  protected function edit($a_form = null)
151  {
152  global $tpl, $ilCtrl;
153 
154  $ilCtrl->setParameter($this, "cat_id", $this->cat_id);
155 
156  if(!$a_form)
157  {
158  $a_form = $this->initCategoryForm($this->cat_id);
159  }
160 
161  $tpl->setContent($a_form->getHTML());
162  }
163 
164  protected function update()
165  {
166  global $ilCtrl, $lng;
167 
168  $form = $this->initCategoryForm($this->cat_id);
169  if($form->checkInput())
170  {
171  include_once "Services/Rating/classes/class.ilRatingCategory.php";
172  $cat = new ilRatingCategory($this->cat_id);
173  $cat->setTitle($form->getInput("title"));
174  $cat->setDescription($form->getInput("desc"));
175  $cat->update();
176 
177  ilUtil::sendSuccess($lng->txt("rating_category_updated"));
178  $ilCtrl->redirect($this, "listCategories");
179  }
180 
181  $form->setValuesByPost();
182  $this->add($form);
183  }
184 
185  protected function updateOrder()
186  {
187  global $ilCtrl, $lng;
188 
189  $order = $_POST["pos"];
190  asort($order);
191 
192  $cnt = 0;
193  foreach($order as $id => $pos)
194  {
195  $cat = new ilRatingCategory($id);
196  if($cat->getParentId() == $this->parent_id)
197  {
198  $cnt += 10;
199  $cat->setPosition($cnt);
200  $cat->update();
201  }
202  }
203 
204  ilUtil::sendSuccess($lng->txt("settings_saved"), true);
205  $ilCtrl->redirect($this, "listCategories");
206  }
207 
208  protected function confirmDelete()
209  {
210  global $tpl, $ilCtrl, $lng;
211 
212  if(!$this->cat_id)
213  {
214  return $this->listCategories();
215  }
216 
217  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
218  $cgui = new ilConfirmationGUI();
219  $cgui->setHeaderText($lng->txt("rating_category_delete_sure")."<br/>".
220  $lng->txt("info_delete_warning_no_trash"));
221 
222  $cgui->setFormAction($ilCtrl->getFormAction($this));
223  $cgui->setCancel($lng->txt("cancel"), "listCategories");
224  $cgui->setConfirm($lng->txt("confirm"), "delete");
225 
226  $cat = new ilRatingCategory($this->cat_id);
227  $cgui->addItem("cat_id", $this->cat_id, $cat->getTitle());
228 
229  $tpl->setContent($cgui->getHTML());
230  }
231 
232  protected function delete()
233  {
234  global $ilCtrl, $lng;
235 
236  if($this->cat_id)
237  {
238  ilRatingCategory::delete($this->cat_id);
239  ilUtil::sendSuccess($lng->txt("rating_category_deleted"), true);
240  }
241 
242  // fix order
243  $cnt = 0;
244  foreach(ilRatingCategory::getAllForObject($this->parent_id) as $item)
245  {
246  $cnt += 10;
247 
248  $cat = new ilRatingCategory($item["id"]);
249  $cat->setPosition($cnt);
250  $cat->update();
251  }
252 
253  $ilCtrl->redirect($this, "listCategories");
254  }
255 
256  protected function export()
257  {
258  global $lng;
259 
260  include_once "./Services/Excel/classes/class.ilExcel.php";
261  $excel = new ilExcel();
262  $excel->addSheet($lng->txt("rating_categories"));
263 
264  // restrict to currently active (probably not needed - see delete())
265  $active = array();
266  foreach(ilRatingCategory::getAllForObject($this->parent_id) as $item)
267  {
268  $active[$item["id"]] = $item["title"];
269  }
270 
271  // title row
272  $row = 1;
273  $excel->setCell($row, 0, $this->export_subobj_title." (".$lng->txt("id").")");
274  $excel->setCell($row, 1, $this->export_subobj_title);
275  $excel->setCell($row, 2, $lng->txt("rating_export_category")." (".$lng->txt("id").")");
276  $excel->setCell($row, 3, $lng->txt("rating_export_category"));
277  $excel->setCell($row, 4, $lng->txt("rating_export_date"));
278  $excel->setCell($row, 5, $lng->txt("rating_export_rating"));
279  $excel->setBold("A1:F1");
280 
281  // content rows
282  foreach(ilRating::getExportData($this->parent_id, ilObject::_lookupType($this->parent_id), array_keys($active)) as $item)
283  {
284  // overall rating?
285  if(!$item["sub_obj_id"])
286  {
287  continue;
288  }
289 
290  $row++;
291 
292  $sub_obj_title = $item["sub_obj_type"];
293  if($this->export_callback)
294  {
295  $sub_obj_title = call_user_func($this->export_callback, $item["sub_obj_id"], $item["sub_obj_type"]);
296  }
297 
298  $excel->setCell($row, 0, (int)$item["sub_obj_id"]);
299  $excel->setCell($row, 1, $sub_obj_title);
300  $excel->setCell($row, 2, (int)$item["category_id"]);
301  $excel->setCell($row, 3, $active[$item["category_id"]]);
302  $excel->setCell($row, 4, new ilDateTime($item["tstamp"], IL_CAL_UNIX));
303  $excel->setCell($row, 5, $item["rating"]);
304  }
305 
306  $excel->sendToClient(ilObject::_lookupTitle($this->parent_id));
307  }
308 }
309 
310 ?>
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
executeCommand()
execute command
This class represents a property form user interface.
__construct($a_parent_id, $a_export_callback=null, $a_export_subobj_title=null)
$cmd
Definition: sahs_server.php:35
static _lookupTitle($a_id)
lookup object title
const IL_CAL_UNIX
static getAllForObject($a_parent_obj_id)
Get all categories for object.
static getExportData($a_obj_id, $a_obj_type, array $a_category_ids=null)
Get export data.
global $tpl
Definition: ilias.php:8
global $ilCtrl
Definition: ilias.php:18
Class ilRatingCategoryGUI.
This class represents a text property in a property form.
Date and time handling
setMaxLength($a_maxlength)
Set Max Length.
Create styles array
The data for the language used.
static _lookupType($a_id, $a_reference=false)
lookup object type
global $lng
Definition: privfeed.php:17
This class represents a text area property in a property form.
static delete($a_id)
Delete db entry.
Class ilRatingCategory.
$_POST["username"]
Confirmation screen class.