ILIAS  release_8 Revision v8.24
class.ilRatingCategoryGUI.php
Go to the documentation of this file.
1<?php
2
19use Psr\Http\Message\RequestInterface;
20
27{
28 protected ilLanguage $lng;
29 protected ilCtrl $ctrl;
32 protected int $parent_id; // [int]
33 protected $export_callback; // [string|array]
34 protected ?string $export_subobj_title = null;
35 protected int $requested_cat_id;
36 protected RequestInterface $request;
37 protected int $cat_id;
38
45 public function __construct(
46 int $a_parent_id,
47 $a_export_callback = null,
48 string $a_export_subobj_title = null
49 ) {
50 global $DIC;
51
52 $this->lng = $DIC->language();
53 $this->ctrl = $DIC->ctrl();
54 $this->tpl = $DIC["tpl"];
55 $this->toolbar = $DIC->toolbar();
56 $this->request = $DIC->http()->request();
57 $lng = $DIC->language();
58
59 $this->parent_id = $a_parent_id;
60 $this->export_callback = $a_export_callback;
61 $this->export_subobj_title = $a_export_subobj_title;
62
63 $lng->loadLanguageModule("rating");
64
65 $params = $this->request->getQueryParams();
66 $body = $this->request->getParsedBody();
67 $this->requested_cat_id = (int) ($body["cat_id"] ?? ($params["cat_id"] ?? 0));
68
69 if ($this->requested_cat_id) {
70 $cat = new ilRatingCategory($this->requested_cat_id);
71 if ($cat->getParentId() == $this->parent_id) {
72 $this->cat_id = $cat->getId();
73 }
74 }
75 }
76
80 public function executeCommand(): void
81 {
82 $ilCtrl = $this->ctrl;
83
84 $next_class = $ilCtrl->getNextClass($this);
85 $cmd = $ilCtrl->getCmd("listCategories");
86
87 switch ($next_class) {
88 default:
89 $this->$cmd();
90 break;
91 }
92 }
93
94 protected function listCategories(): void
95 {
97 $ilToolbar = $this->toolbar;
99 $ilCtrl = $this->ctrl;
100
101 $ilToolbar->addButton(
102 $lng->txt("rating_add_category"),
103 $ilCtrl->getLinkTarget($this, "add")
104 );
105
106 $ilToolbar->addSeparator();
107
108 $ilToolbar->addButton(
109 $lng->txt("export"),
110 $ilCtrl->getLinkTarget($this, "export")
111 );
112
113 $table = new ilRatingCategoryTableGUI($this, "listCategories", $this->parent_id);
114 $tpl->setContent($table->getHTML());
115 }
116
117
118 protected function initCategoryForm(int $a_id = null): ilPropertyFormGUI
119 {
121 $ilCtrl = $this->ctrl;
122
123 $form = new ilPropertyFormGUI();
124 $form->setTarget("_top");
125 $form->setFormAction($ilCtrl->getFormAction($this, "save"));
126 $form->setTitle($lng->txt("rating_category_" . ($a_id ? "edit" : "create")));
127
128 // title
129 $ti = new ilTextInputGUI($lng->txt("title"), "title");
130 $ti->setMaxLength(128);
131 $ti->setSize(40);
132 $ti->setRequired(true);
133 $form->addItem($ti);
134
135 // description
136 $ta = new ilTextAreaInputGUI($lng->txt("description"), "desc");
137 $ta->setCols(40);
138 $ta->setRows(2);
139 $form->addItem($ta);
140
141 if (!$a_id) {
142 $form->addCommandButton("save", $lng->txt("rating_category_add"));
143 } else {
144 $cat = new ilRatingCategory($a_id);
145 $ti->setValue($cat->getTitle());
146 $ta->setValue($cat->getDescription());
147
148 $form->addCommandButton("update", $lng->txt("rating_category_update"));
149 }
150 $form->addCommandButton("listCategories", $lng->txt("cancel"));
151
152 return $form;
153 }
154
155 protected function add(ilPropertyFormGUI $a_form = null): void
156 {
158
159 if (!$a_form) {
160 $a_form = $this->initCategoryForm();
161 }
162
163 $tpl->setContent($a_form->getHTML());
164 }
165
166 protected function save(): void
167 {
168 $ilCtrl = $this->ctrl;
170
171 $form = $this->initCategoryForm();
172 if ($form->checkInput()) {
173 $cat = new ilRatingCategory();
174 $cat->setParentId($this->parent_id);
175 $cat->setTitle($form->getInput("title"));
176 $cat->setDescription($form->getInput("desc"));
177 $cat->save();
178
179 $this->tpl->setOnScreenMessage('success', $lng->txt("rating_category_created"));
180 $ilCtrl->redirect($this, "listCategories");
181 }
182
183 $form->setValuesByPost();
184 $this->add($form);
185 }
186
187 protected function edit(ilPropertyFormGUI $a_form = null): void
188 {
190 $ilCtrl = $this->ctrl;
191
192 $ilCtrl->setParameter($this, "cat_id", $this->cat_id);
193
194 if (!$a_form) {
195 $a_form = $this->initCategoryForm($this->cat_id);
196 }
197
198 $tpl->setContent($a_form->getHTML());
199 }
200
201 protected function update(): void
202 {
203 $ilCtrl = $this->ctrl;
205
206 $form = $this->initCategoryForm($this->cat_id);
207 if ($form->checkInput()) {
208 $cat = new ilRatingCategory($this->cat_id);
209 $cat->setTitle($form->getInput("title"));
210 $cat->setDescription($form->getInput("desc"));
211 $cat->update();
212
213 $this->tpl->setOnScreenMessage('success', $lng->txt("rating_category_updated"));
214 $ilCtrl->redirect($this, "listCategories");
215 }
216
217 $form->setValuesByPost();
218 $this->add($form);
219 }
220
221 protected function updateOrder(): void
222 {
223 $ilCtrl = $this->ctrl;
225
226 $body = $this->request->getParsedBody();
227 $order = $body["pos"];
228 asort($order);
229
230 $cnt = 0;
231 foreach ($order as $id => $pos) {
232 $cat = new ilRatingCategory($id);
233 if ($cat->getParentId() == $this->parent_id) {
234 $cnt += 10;
235 $cat->setPosition($cnt);
236 $cat->update();
237 }
238 }
239
240 $this->tpl->setOnScreenMessage('success', $lng->txt("settings_saved"), true);
241 $ilCtrl->redirect($this, "listCategories");
242 }
243
244 protected function confirmDelete(): void
245 {
247 $ilCtrl = $this->ctrl;
249
250 if (!$this->cat_id) {
251 $this->listCategories();
252 return;
253 }
254
255 $cgui = new ilConfirmationGUI();
256 $cgui->setHeaderText($lng->txt("rating_category_delete_sure") . "<br/>" .
257 $lng->txt("info_delete_warning_no_trash"));
258
259 $cgui->setFormAction($ilCtrl->getFormAction($this));
260 $cgui->setCancel($lng->txt("cancel"), "listCategories");
261 $cgui->setConfirm($lng->txt("confirm"), "delete");
262
263 $cat = new ilRatingCategory($this->cat_id);
264 $cgui->addItem("cat_id", $this->cat_id, $cat->getTitle());
265
266 $tpl->setContent($cgui->getHTML());
267 }
268
269 protected function delete(): void
270 {
271 $ilCtrl = $this->ctrl;
273
274 if ($this->cat_id) {
275 ilRatingCategory::delete($this->cat_id);
276 $this->tpl->setOnScreenMessage('success', $lng->txt("rating_category_deleted"), true);
277 }
278
279 // fix order
280 $cnt = 0;
281 foreach (ilRatingCategory::getAllForObject($this->parent_id) as $item) {
282 $cnt += 10;
283
284 $cat = new ilRatingCategory($item["id"]);
285 $cat->setPosition($cnt);
286 $cat->update();
287 }
288
289 $ilCtrl->redirect($this, "listCategories");
290 }
291
292 protected function export(): void
293 {
295
296 $excel = new ilExcel();
297 $excel->addSheet($lng->txt("rating_categories"));
298
299 // restrict to currently active (probably not needed - see delete())
300 $active = array();
301 foreach (ilRatingCategory::getAllForObject($this->parent_id) as $item) {
302 $active[$item["id"]] = $item["title"];
303 }
304
305 // title row
306 $row = 1;
307 $excel->setCell($row, 0, $this->export_subobj_title . " (" . $lng->txt("id") . ")");
308 $excel->setCell($row, 1, $this->export_subobj_title);
309 $excel->setCell($row, 2, $lng->txt("rating_export_category") . " (" . $lng->txt("id") . ")");
310 $excel->setCell($row, 3, $lng->txt("rating_export_category"));
311 $excel->setCell($row, 4, $lng->txt("rating_export_date"));
312 $excel->setCell($row, 5, $lng->txt("rating_export_rating"));
313 $excel->setBold("A1:F1");
314
315 // content rows
316 foreach (ilRating::getExportData($this->parent_id, ilObject::_lookupType($this->parent_id), array_keys($active)) as $item) {
317 // overall rating?
318 if (!$item["sub_obj_id"]) {
319 continue;
320 }
321
322 $row++;
323
324 $sub_obj_title = $item["sub_obj_type"];
325 if ($this->export_callback) {
326 $sub_obj_title = call_user_func($this->export_callback, $item["sub_obj_id"], $item["sub_obj_type"]);
327 }
328
329 $excel->setCell($row, 0, (int) $item["sub_obj_id"]);
330 $excel->setCell($row, 1, $sub_obj_title);
331 $excel->setCell($row, 2, (int) $item["category_id"]);
332 $excel->setCell($row, 3, $active[$item["category_id"]] ?? "");
333 $excel->setCell($row, 4, new ilDateTime($item["tstamp"] ?? null, IL_CAL_UNIX));
334 $excel->setCell($row, 5, $item["rating"] ?? "");
335 }
336
337 $excel->sendToClient(ilObject::_lookupTitle($this->parent_id));
338 }
339}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
const IL_CAL_UNIX
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilCtrl provides processing control methods.
getNextClass($a_gui_class=null)
@inheritDoc
setParameter(object $a_gui_obj, string $a_parameter, $a_value)
@inheritDoc
@classDescription Date and time handling
language handling
loadLanguageModule(string $a_module)
Load language module.
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
static _lookupType(int $id, bool $reference=false)
static _lookupTitle(int $obj_id)
This class represents a property form user interface.
Class ilRatingCategoryGUI.
add(ilPropertyFormGUI $a_form=null)
ilGlobalTemplateInterface $tpl
edit(ilPropertyFormGUI $a_form=null)
__construct(int $a_parent_id, $a_export_callback=null, string $a_export_subobj_title=null)
ilRatingCategoryGUI constructor.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getAllForObject(int $a_parent_obj_id)
static delete(int $a_id)
static getExportData(int $a_obj_id, string $a_obj_type, array $a_category_ids=null)
Get export data.
This class represents a text area property in a property form.
This class represents a text property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setContent(string $a_html)
Sets content for standard template.
if(! $DIC->user() ->getId()||!ilLTIConsumerAccess::hasCustomProviderCreationAccess()) $params
Definition: ltiregstart.php:33