ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ilRatingGUI Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

+ Collaboration diagram for ilRatingGUI:

Public Member Functions

 __construct ()
 
 executeCommand ()
 execute command More...
 
 setObject (int $a_obj_id, string $a_obj_type, ?int $a_sub_obj_id=0, ?string $a_sub_obj_type="")
 Set Object. More...
 
 setUserId (int $a_userid)
 
 getUserId ()
 
 setYourRatingText (string $a_val)
 
 getYourRatingText ()
 
 enableCategories (bool $a_value)
 
 setCtrlPath (array $a_value)
 
 getHTML (bool $a_show_overall=true, bool $a_may_rate=true, string $a_onclick=null, string $a_additional_id=null)
 
 getBlockHTML (string $a_title)
 
 saveRating ()
 Save Rating. More...
 
 setUpdateCallback ($a_callback)
 
 resetUserRating ()
 
 setExportCallback ($a_callback, string $a_subobj_title)
 
 getListGUIProperty (int $a_ref_id, bool $a_may_rate, string $a_ajax_hash, int $parent_ref_id)
 

Protected Member Functions

 renderDetails (string $a_js_id, bool $a_may_rate, array $a_categories=null, string $a_onclick=null, bool $a_average=false, bool $add_tooltip=false)
 
 addTooltip (string $id, int $cnt=0, float $avg=0, int $user=0)
 

Protected Attributes

ilLanguage $lng
 
ilCtrl $ctrl
 
ilObjUser $user
 
string $id = "rtg_"
 
 $export_callback
 
string $export_subobj_title = ""
 
array $ctrl_path = []
 
bool $enable_categories = false
 
string $your_rating_text = ""
 
ILIAS DI UIServices $ui
 
int $obj_id
 
string $obj_type
 
int $sub_obj_id
 
string $sub_obj_type
 
int $userid
 
 $update_callback = null
 
array $requested_ratings = null
 
int $requested_rating
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning Class ilRatingGUI. User interface class for rating.

Author
Alexander Killing killi.nosp@m.ng@l.nosp@m.eifos.nosp@m..de ilRatingGUI: ilRatingCategoryGUI

Definition at line 25 of file class.ilRatingGUI.php.

Constructor & Destructor Documentation

◆ __construct()

ilRatingGUI::__construct ( )

Definition at line 47 of file class.ilRatingGUI.php.

References $DIC, $params, ILIAS\Repository\ctrl(), ILIAS\Repository\int(), ILIAS\Repository\lng(), ilLanguage\loadLanguageModule(), ILIAS\Repository\ui(), and ILIAS\Repository\user().

48  {
49  global $DIC;
50 
51  $this->lng = $DIC->language();
52  $this->ctrl = $DIC->ctrl();
53  $this->user = $DIC->user();
54  $lng = $DIC->language();
55 
56  $this->ui = $DIC->ui();
57 
58  $params = $DIC->http()->request()->getQueryParams();
59  $body = $DIC->http()->request()->getParsedBody();
60 
61  if (isset($body["rating"]) && is_array($body["rating"])) {
62  $this->requested_ratings = ($body["rating"] ?? null);
63  }
64  $this->requested_rating = (int) ($params["rating"] ?? 0);
65 
66  $lng->loadLanguageModule("rating");
67  }
if(! $DIC->user() ->getId()||!ilLTIConsumerAccess::hasCustomProviderCreationAccess()) $params
Definition: ltiregstart.php:33
ilLanguage $lng
loadLanguageModule(string $a_module)
Load language module.
global $DIC
Definition: feed.php:28
+ Here is the call graph for this function:

Member Function Documentation

◆ addTooltip()

ilRatingGUI::addTooltip ( string  $id,
int  $cnt = 0,
float  $avg = 0,
int  $user = 0 
)
protected

Definition at line 577 of file class.ilRatingGUI.php.

References $lng, $user, ilTooltipGUI\addTooltip(), and ilLanguage\txt().

Referenced by getHTML(), and renderDetails().

582  : void {
583  $lng = $this->lng;
584 
585  $tt = "";
586  if ($cnt == 0) {
587  $tt = $lng->txt("rat_not_rated_yet");
588  } else {
589  if ($cnt == 1) {
590  $tt = $lng->txt("rat_one_rating");
591  } else {
592  $tt = sprintf($lng->txt("rat_nr_ratings"), $cnt);
593  }
594  $tt .= "<br>" . $lng->txt("rating_avg_rating") . ": " . round($avg, 1);
595  }
596 
597  if ($user > 0) {
598  $tt .= "<br>" . $lng->txt("rating_personal_rating") . ": " . $user;
599  }
600  if ($tt !== "") {
602  $id,
603  $tt,
604  "",
605  "bottom center",
606  "top center",
607  false
608  );
609  }
610  }
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...
ilLanguage $lng
static addTooltip(string $a_el_id, string $a_text, string $a_container="", string $a_my="bottom center", string $a_at="top center", bool $a_use_htmlspecialchars=true)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ enableCategories()

ilRatingGUI::enableCategories ( bool  $a_value)

Definition at line 141 of file class.ilRatingGUI.php.

141  : void
142  {
143  $this->enable_categories = $a_value;
144  }

◆ executeCommand()

ilRatingGUI::executeCommand ( )

execute command

Definition at line 72 of file class.ilRatingGUI.php.

References $ctrl, and ilCtrl\getNextClass().

72  : void
73  {
74  $ilCtrl = $this->ctrl;
75 
76  $next_class = $ilCtrl->getNextClass($this);
77  $cmd = $ilCtrl->getCmd();
78 
79  switch ($next_class) {
80  case "ilratingcategorygui":
81  $gui = new ilRatingCategoryGUI($this->obj_id, $this->export_callback, $this->export_subobj_title);
82  $ilCtrl->forwardCommand($gui);
83  break;
84 
85  default:
86  $this->$cmd();
87  break;
88  }
89  }
getNextClass($a_gui_class=null)
Class ilRatingCategoryGUI.
+ Here is the call graph for this function:

◆ getBlockHTML()

ilRatingGUI::getBlockHTML ( string  $a_title)

Definition at line 612 of file class.ilRatingGUI.php.

References $panel, $ui, ANONYMOUS_USER_ID, ilRatingCategory\getAllForObject(), getUserId(), and renderDetails().

612  : string
613  {
614  $ui = $this->ui;
615 
616  $categories = array();
617  if ($this->enable_categories) {
618  $categories = ilRatingCategory::getAllForObject($this->obj_id);
619  }
620 
621  $may_rate = ($this->getUserId() != ANONYMOUS_USER_ID);
622 
623 
624  $panel = $ui->factory()->panel()->secondary()->legacy(
625  $a_title,
626  $ui->factory()->legacy(
627  $this->renderDetails("rtsb_", $may_rate, $categories, null, true, true)
628  )
629  );
630 
631  return $ui->renderer()->render($panel);
632  }
ILIAS DI UIServices $ui
const ANONYMOUS_USER_ID
Definition: constants.php:27
if(isset($_FILES['img_file']) &&is_array($_FILES['img_file'])) $panel
Definition: imgupload.php:198
renderDetails(string $a_js_id, bool $a_may_rate, array $a_categories=null, string $a_onclick=null, bool $a_average=false, bool $add_tooltip=false)
static getAllForObject(int $a_parent_obj_id)
+ Here is the call graph for this function:

◆ getHTML()

ilRatingGUI::getHTML ( bool  $a_show_overall = true,
bool  $a_may_rate = true,
string  $a_onclick = null,
string  $a_additional_id = null 
)

Definition at line 440 of file class.ilRatingGUI.php.

References $i, $id, $lng, addTooltip(), ANONYMOUS_USER_ID, ilRatingCategory\getAllForObject(), ilUtil\getImagePath(), ilRating\getOverallRatingForObject(), ilRating\getRatingForUserAndObject(), getUserId(), renderDetails(), and ilLanguage\txt().

Referenced by getListGUIProperty().

445  : string {
446  $lng = $this->lng;
447  $unique_id = $this->id;
448  if ($a_additional_id) {
449  $unique_id .= "_" . $a_additional_id;
450  }
451 
452  $categories = array();
453  if ($this->enable_categories) {
454  $categories = ilRatingCategory::getAllForObject($this->obj_id);
455  }
456 
457  $may_rate = ($this->getUserId() != ANONYMOUS_USER_ID);
458  if ($may_rate && !$a_may_rate) {
459  $may_rate = false;
460  }
461 
462  $has_overlay = false;
463  if ($may_rate || $categories) {
464  $has_overlay = true;
465  }
466 
467  $ttpl = new ilTemplate("tpl.rating_input.html", true, true, "Services/Rating");
468 
469  // user rating
470  $user_rating = 0;
471  if ($may_rate || !$a_show_overall) {
472  $user_rating = round(ilRating::getRatingForUserAndObject(
473  $this->obj_id,
474  $this->obj_type,
475  $this->sub_obj_id,
476  $this->sub_obj_type,
477  $this->getUserId()
478  ));
479  }
480 
481  // (1) overall rating
482  if ($a_show_overall) {
484  $this->obj_id,
485  $this->obj_type,
486  $this->sub_obj_id,
487  $this->sub_obj_type
488  );
489  } else {
490  $rating = array("avg" => $user_rating);
491  }
492 
493  for ($i = 1; $i <= 5; $i++) {
494  if ($a_show_overall &&
495  $i == $user_rating) {
496  $ttpl->setCurrentBlock("rating_mark");
497  $ttpl->setVariable(
498  "SRC_MARK",
499  ilUtil::getImagePath("icon_rate_marker.svg")
500  );
501  $ttpl->parseCurrentBlock();
502  }
503 
504  $ttpl->setCurrentBlock("rating_icon");
505  if ($rating["avg"] >= $i) {
506  $ttpl->setVariable(
507  "SRC_ICON",
508  ilUtil::getImagePath("icon_rate_on.svg")
509  );
510  } elseif ($rating["avg"] + 1 <= $i) {
511  $ttpl->setVariable(
512  "SRC_ICON",
513  ilUtil::getImagePath("icon_rate_off.svg")
514  );
515  } else {
516  $nr = round(($rating["avg"] + 1 - $i) * 10);
517  $ttpl->setVariable(
518  "SRC_ICON",
519  ilUtil::getImagePath("icon_rate_$nr.svg")
520  );
521  }
522  $ttpl->setVariable("ALT_ICON", "");
523  $ttpl->parseCurrentBlock();
524  }
525  $ttpl->setCurrentBlock("rating_icon");
526 
527  if ($a_show_overall) {
528  if ($rating["cnt"] > 0) {
529  $ttpl->setCurrentBlock("rat_nr");
530  $ttpl->setVariable("RT_NR", $rating["cnt"]);
531  $ttpl->parseCurrentBlock();
532  }
533  }
534 
535  $this->addTooltip(
536  $unique_id . "_tt",
537  (int) ($rating["cnt"] ?? 0),
538  (float) ($rating["avg"] ?? 0),
539  (int) ($user_rating ?? 0)
540  );
541 
542  // add overlay (trigger)
543  if ($has_overlay) {
544  $ov = new ilOverlayGUI($unique_id);
545  $ov->setTrigger("tr_" . $unique_id, "click", "tr_" . $unique_id);
546  $ov->add();
547 
548  $ttpl->setCurrentBlock("act_rat_start");
549  $ttpl->setVariable("ID", $unique_id);
550  $ttpl->setVariable("TXT_OPEN_DIALOG", $lng->txt("rating_open_dialog"));
551  $ttpl->parseCurrentBlock();
552 
553  $ttpl->touchBlock("act_rat_end");
554  }
555 
556  $ttpl->parseCurrentBlock();
557 
558 
559  // (2) user rating
560 
561  if ($has_overlay) {
562  $ttpl->setVariable(
563  "RATING_DETAILS",
564  $this->renderDetails("rtov_", $may_rate, $categories, $a_onclick)
565  );
566 
567  $ttpl->setCurrentBlock("user_rating");
568  $ttpl->setVariable("ID", $unique_id);
569  $ttpl->parseCurrentBlock();
570  }
571 
572  $ttpl->setVariable("TTID", $unique_id);
573 
574  return $ttpl->get();
575  }
const ANONYMOUS_USER_ID
Definition: constants.php:27
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...
renderDetails(string $a_js_id, bool $a_may_rate, array $a_categories=null, string $a_onclick=null, bool $a_average=false, bool $add_tooltip=false)
ilLanguage $lng
static getImagePath(string $img, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
static getAllForObject(int $a_parent_obj_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addTooltip(string $id, int $cnt=0, float $avg=0, int $user=0)
static getRatingForUserAndObject(int $a_obj_id, string $a_obj_type, int $a_sub_obj_id, string $a_sub_obj_type, int $a_user_id, int $a_category_id=null)
Get rating for a user and an object.
static getOverallRatingForObject(int $a_obj_id, string $a_obj_type, int $a_sub_obj_id=null, string $a_sub_obj_type=null, int $a_category_id=null)
Get overall rating for an object.
$i
Definition: metadata.php:41
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getListGUIProperty()

ilRatingGUI::getListGUIProperty ( int  $a_ref_id,
bool  $a_may_rate,
string  $a_ajax_hash,
int  $parent_ref_id 
)

Definition at line 707 of file class.ilRatingGUI.php.

References getHTML().

712  : string {
713  return $this->getHTML(
714  true,
715  $a_may_rate,
716  "il.Object.saveRatingFromListGUI(" . $a_ref_id . ", '" . $a_ajax_hash . "', %rating%);",
717  $parent_ref_id
718  );
719  }
getHTML(bool $a_show_overall=true, bool $a_may_rate=true, string $a_onclick=null, string $a_additional_id=null)
+ Here is the call graph for this function:

◆ getUserId()

ilRatingGUI::getUserId ( )

Definition at line 126 of file class.ilRatingGUI.php.

References $userid.

Referenced by getBlockHTML(), getHTML(), renderDetails(), resetUserRating(), and saveRating().

126  : int
127  {
128  return $this->userid;
129  }
+ Here is the caller graph for this function:

◆ getYourRatingText()

ilRatingGUI::getYourRatingText ( )

Definition at line 136 of file class.ilRatingGUI.php.

References $your_rating_text.

Referenced by renderDetails().

136  : string
137  {
139  }
string $your_rating_text
+ Here is the caller graph for this function:

◆ renderDetails()

ilRatingGUI::renderDetails ( string  $a_js_id,
bool  $a_may_rate,
array  $a_categories = null,
string  $a_onclick = null,
bool  $a_average = false,
bool  $add_tooltip = false 
)
protected

Definition at line 152 of file class.ilRatingGUI.php.

References $ctrl, $i, $lng, addTooltip(), ilUtil\getImagePath(), ilRating\getOverallRatingForObject(), ilRating\getRatingForUserAndObject(), getUserId(), getYourRatingText(), and ilLanguage\txt().

Referenced by getBlockHTML(), and getHTML().

159  : string {
160  $lng = $this->lng;
161  $ilCtrl = $this->ctrl;
162 
163  $ttpl = new ilTemplate("tpl.rating_details.html", true, true, "Services/Rating");
164 
165  $rate_text = null;
166  if ($this->getYourRatingText() != "#") {
167  $rate_text = ($this->getYourRatingText() != "")
168  ? $this->getYourRatingText()
169  : $lng->txt("rating_your_rating");
170  }
171 
172  // no categories: 1 simple rating (link)
173  if (!$a_categories) {
174  if ($a_may_rate) {
176  $this->obj_id,
177  $this->obj_type,
178  $this->sub_obj_id,
179  $this->sub_obj_type,
180  $this->getUserId(),
181  0
182  );
183  $overall_rating = [
184  "avg" => 0,
185  "cnt" => 0
186  ];
187  if ($a_average) {
188  $overall_rating = ilRating::getOverallRatingForObject(
189  $this->obj_id,
190  $this->obj_type,
191  $this->sub_obj_id,
192  $this->sub_obj_type
193  );
194  }
195 
196  // user rating links
197  for ($i = 1; $i <= 5; $i++) {
198  if ($a_average &&
199  $i == $rating) {
200  $ttpl->setCurrentBlock("rating_mark_simple");
201  $ttpl->setVariable(
202  "SRC_MARK_SIMPLE",
203  ilUtil::getImagePath("icon_rate_marker.svg")
204  );
205  $ttpl->parseCurrentBlock();
206  }
207 
208  $ttpl->setCurrentBlock("rating_link_simple");
209  if (stristr($a_onclick, "%rating%")) {
210  $url_save = "#";
211  } else {
212  $ilCtrl->setParameter($this, "rating", $i);
213  if (!$this->ctrl_path) {
214  $url_save = $ilCtrl->getLinkTarget($this, "saveRating");
215  } else {
216  $url_save = $ilCtrl->getLinkTargetByClass($this->ctrl_path, "saveRating");
217  }
218  }
219  $ttpl->setVariable("HREF_RATING", $url_save);
220 
221  if ($a_onclick) {
222  $onclick = str_replace("%rating%", $i, $a_onclick);
223  $ttpl->setVariable("ONCLICK_RATING", ' onclick="' . $onclick . '"');
224  }
225 
226  if ($a_average) {
227  $ref_rating = $overall_rating["avg"];
228  } else {
229  $ref_rating = $rating;
230  }
231 
232  if ($ref_rating >= $i) {
233  $ttpl->setVariable(
234  "SRC_ICON",
235  ilUtil::getImagePath("icon_rate_on.svg")
236  );
237  } else {
238  $ttpl->setVariable(
239  "SRC_ICON",
240  ilUtil::getImagePath("icon_rate_off.svg")
241  );
242  }
243  $ttpl->setVariable(
244  "ALT_ICON",
245  sprintf($lng->txt("rating_rate_x_of_5"), $i)
246  );
247  $ttpl->parseCurrentBlock();
248  }
249 
250  // remove
251  if ($rating) {
252  $ttpl->setCurrentBlock("rating_simple_del_bl");
253  $ttpl->setVariable("CAPTION_RATING_DEL", $lng->txt("rating_remove"));
254 
255  if (stristr($a_onclick, "%rating%")) {
256  $url_save = "#";
257  } else {
258  $ilCtrl->setParameter($this, "rating", 0);
259  if (!$this->ctrl_path) {
260  $url_save = $ilCtrl->getLinkTarget($this, "saveRating");
261  } else {
262  $url_save = $ilCtrl->getLinkTargetByClass($this->ctrl_path, "saveRating");
263  }
264  }
265  $ttpl->setVariable("HREF_RATING_DEL", $url_save);
266 
267  if ($a_onclick) {
268  $onclick = str_replace("%rating%", 0, $a_onclick);
269  $ttpl->setVariable("ONCLICK_RATING_DEL", ' onclick="' . $onclick . '"');
270  }
271 
272  $ttpl->parseCurrentBlock();
273  }
274 
275  if ($rate_text) {
276  $ttpl->setCurrentBlock("rating_simple_title");
277  $ttpl->setVariable("TXT_RATING_SIMPLE", $rate_text);
278  $ttpl->parseCurrentBlock();
279  }
280 
281  if ($a_average &&
282  $overall_rating["cnt"]) {
283  $ttpl->setCurrentBlock("number_votes_simple");
284  $ttpl->setVariable("NUMBER_VOTES_SIMPLE", $overall_rating["cnt"]);
285  $ttpl->parseCurrentBlock();
286  }
287 
288  if ($add_tooltip) {
289  $unique_id = $this->id . "_block";
290  $ttpl->setVariable("TTID", $unique_id);
291  $this->addTooltip(
292  $unique_id,
293  (int) ($overall_rating["cnt"] ?? 0),
294  (float) ($overall_rating["avg"] ?? 0),
295  (int) ($rating ?? 0)
296  );
297  }
298 
299  // user rating text
300  $ttpl->setCurrentBlock("user_rating_simple");
301  $ttpl->parseCurrentBlock();
302  }
303  }
304  // categories: overall & user (form)
305  else {
306  $has_user_rating = false;
307  $overall_rating = [
308  "avg" => 0,
309  "cnt" => 0
310  ];
311  foreach ($a_categories as $category) {
312  $user_rating = round(ilRating::getRatingForUserAndObject(
313  $this->obj_id,
314  $this->obj_type,
315  $this->sub_obj_id,
316  $this->sub_obj_type,
317  $this->getUserId(),
318  $category["id"]
319  ));
320 
321  $overall_rating = ilRating::getOverallRatingForObject(
322  $this->obj_id,
323  $this->obj_type,
324  $this->sub_obj_id,
325  $this->sub_obj_type,
326  $category["id"]
327  );
328 
329  for ($i = 1; $i <= 5; $i++) {
330  if ($a_may_rate && $i == $user_rating) {
331  $has_user_rating = true;
332 
333  $ttpl->setCurrentBlock("rating_mark");
334  $ttpl->setVariable(
335  "SRC_MARK",
336  ilUtil::getImagePath("icon_rate_marker.svg")
337  );
338  $ttpl->parseCurrentBlock();
339  }
340 
341  $ttpl->setCurrentBlock("user_rating_icon");
342  if ($overall_rating["avg"] >= $i) {
343  $ttpl->setVariable(
344  "SRC_ICON",
345  ilUtil::getImagePath("icon_rate_on.svg")
346  );
347  } elseif ($overall_rating["avg"] + 1 <= $i) {
348  $ttpl->setVariable(
349  "SRC_ICON",
350  ilUtil::getImagePath("icon_rate_off.svg")
351  );
352  } else {
353  $nr = round(($overall_rating["avg"] + 1 - $i) * 10);
354  $ttpl->setVariable(
355  "SRC_ICON",
356  ilUtil::getImagePath("icon_rate_$nr.svg")
357  );
358  }
359  $ttpl->setVariable(
360  "ALT_ICON",
361  sprintf($lng->txt("rating_rate_x_of_5"), $i)
362  );
363 
364  if ($a_may_rate) {
365  $ttpl->setVariable("HREF_RATING", "il.Rating.setValue(" . $category["id"] . "," . $i . ", '" . $a_js_id . "')");
366  $ttpl->setVariable("CATEGORY_ID", $category["id"]);
367  $ttpl->setVariable("ICON_VALUE", $i);
368  $ttpl->setVariable("JS_ID", $a_js_id);
369  $ttpl->setVariable("ICON_MOUSEACTION", " onmouseover=\"il.Rating.toggleIcon(this," . $i . ")\"" .
370  " onmouseout=\"il.Rating.toggleIcon(this," . $i . ",1)\"");
371  }
372 
373  $ttpl->parseCurrentBlock();
374  }
375 
376  if ($a_may_rate) {
377  $ttpl->setCurrentBlock("user_rating_category_column");
378  $ttpl->setVariable("JS_ID", $a_js_id);
379  $ttpl->setVariable("CATEGORY_ID", $category["id"]);
380  $ttpl->setVariable("CATEGORY_VALUE", $user_rating);
381  if ($add_tooltip) {
382  $unique_id = $this->id . "_block_" . $category["id"];
383  $ttpl->setVariable("CAT_TTID", $unique_id);
384  $this->addTooltip(
385  $unique_id,
386  (int) ($overall_rating["cnt"] ?? 0),
387  (float) ($overall_rating["avg"] ?? 0),
388  (int) ($user_rating ?? 0)
389  );
390  }
391  $ttpl->parseCurrentBlock();
392  }
393 
394 
395  // category title
396  $ttpl->setCurrentBlock("user_rating_category");
397  $ttpl->setVariable("TXT_RATING_CATEGORY", $category["title"]);
398  $ttpl->parseCurrentBlock();
399  }
400 
401  if ($overall_rating["cnt"] > 0) {
402  $ttpl->setCurrentBlock("votes_number_bl");
403  $ttpl->setVariable("NUMBER_VOTES", sprintf($lng->txt("rating_number_votes"), $overall_rating["cnt"]));
404  $ttpl->parseCurrentBlock();
405  }
406 
407  if ($a_may_rate) {
408  // remove
409  if ($has_user_rating) {
410  $ttpl->setCurrentBlock("user_rating_categories_del_bl");
411  $ttpl->setVariable("CAPTION_RATING_DEL_CAT", $lng->txt("rating_remove"));
412 
413  $ilCtrl->setParameter($this, "rating", 0);
414  if (!$this->ctrl_path) {
415  $url_save = $ilCtrl->getLinkTarget($this, "resetUserRating");
416  } else {
417  $url_save = $ilCtrl->getLinkTargetByClass($this->ctrl_path, "resetUserRating");
418  }
419  $ttpl->setVariable("HREF_RATING_DEL_CAT", $url_save);
420 
421  $ttpl->parseCurrentBlock();
422  }
423 
424  if (!$this->ctrl_path) {
425  $url_form = $ilCtrl->getFormAction($this, "saveRating");
426  } else {
427  $url_form = $ilCtrl->getFormActionByClass($this->ctrl_path, "saveRating");
428  }
429  $ttpl->setVariable("FORM_ACTION", $url_form);
430  $ttpl->setVariable("TXT_SUBMIT", $lng->txt("rating_overlay_submit"));
431  $ttpl->setVariable("CMD_SUBMIT", "saveRating");
432  $ttpl->touchBlock("user_rating_categories_form_out");
433  }
434  }
435 
436  return $ttpl->get();
437  }
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...
ilLanguage $lng
static getImagePath(string $img, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
addTooltip(string $id, int $cnt=0, float $avg=0, int $user=0)
static getRatingForUserAndObject(int $a_obj_id, string $a_obj_type, int $a_sub_obj_id, string $a_sub_obj_type, int $a_user_id, int $a_category_id=null)
Get rating for a user and an object.
static getOverallRatingForObject(int $a_obj_id, string $a_obj_type, int $a_sub_obj_id=null, string $a_sub_obj_type=null, int $a_category_id=null)
Get overall rating for an object.
$i
Definition: metadata.php:41
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ resetUserRating()

ilRatingGUI::resetUserRating ( )

Definition at line 689 of file class.ilRatingGUI.php.

References getUserId(), and ilRating\resetRatingForUserAndObject().

Referenced by saveRating().

689  : void
690  {
692  $this->obj_id,
693  $this->obj_type,
694  (int) $this->sub_obj_id,
695  $this->sub_obj_type,
696  $this->getUserId()
697  );
698  }
static resetRatingForUserAndObject(int $a_obj_id, string $a_obj_type, int $a_sub_obj_id, string $a_sub_obj_type, int $a_user_id)
Reset rating for a user and an object.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ saveRating()

ilRatingGUI::saveRating ( )

Save Rating.

Definition at line 637 of file class.ilRatingGUI.php.

References $ctrl, $requested_rating, exit, getUserId(), resetUserRating(), and ilRating\writeRatingForUserAndObject().

637  : void
638  {
639  $ilCtrl = $this->ctrl;
640 
641  if (!is_array($this->requested_ratings)) {
642  $rating = $this->requested_rating;
643  if ($rating == 0) {
644  $this->resetUserRating();
645  } else {
647  $this->obj_id,
648  $this->obj_type,
649  $this->sub_obj_id,
650  $this->sub_obj_type,
651  $this->getUserId(),
652  $rating
653  );
654  }
655  } else {
656  foreach ($this->requested_ratings as $cat_id => $rating) {
658  $this->obj_id,
659  $this->obj_type,
660  $this->sub_obj_id,
661  $this->sub_obj_type,
662  $this->getUserId(),
663  $rating,
664  $cat_id
665  );
666  }
667  }
668 
669  if ($this->update_callback) {
670  call_user_func(
671  $this->update_callback,
672  $this->obj_id,
673  $this->obj_type,
674  $this->sub_obj_id,
675  $this->sub_obj_type
676  );
677  }
678 
679  if ($ilCtrl->isAsynch()) {
680  exit();
681  }
682  }
exit
Definition: login.php:28
static writeRatingForUserAndObject(int $a_obj_id, string $a_obj_type, ?int $a_sub_obj_id, ?string $a_sub_obj_type, int $a_user_id, int $a_rating, int $a_category_id=0)
Write rating for a user and an object.
+ Here is the call graph for this function:

◆ setCtrlPath()

ilRatingGUI::setCtrlPath ( array  $a_value)

Definition at line 146 of file class.ilRatingGUI.php.

146  : void
147  {
148  $this->ctrl_path = $a_value;
149  }

◆ setExportCallback()

ilRatingGUI::setExportCallback (   $a_callback,
string  $a_subobj_title 
)

Definition at line 700 of file class.ilRatingGUI.php.

700  : void
701  {
702  $this->export_callback = $a_callback;
703  $this->export_subobj_title = $a_subobj_title;
704  }

◆ setObject()

ilRatingGUI::setObject ( int  $a_obj_id,
string  $a_obj_type,
?int  $a_sub_obj_id = 0,
?string  $a_sub_obj_type = "" 
)

Set Object.

Parameters
int$a_obj_idObject ID
string$a_obj_typeObject Type
int$a_sub_obj_idSubobject ID
string$a_sub_obj_typeSubobject Type

Definition at line 99 of file class.ilRatingGUI.php.

References $ilUser, $sub_obj_type, $user, and setUserId().

104  : void {
106 
107  if (!trim($a_sub_obj_type)) {
108  $a_sub_obj_type = "-";
109  }
110 
111  $this->obj_id = $a_obj_id;
112  $this->obj_type = $a_obj_type;
113  $this->sub_obj_id = $a_sub_obj_id;
114  $this->sub_obj_type = $a_sub_obj_type;
115  $this->id = "rtg_" . $this->obj_id . "_" . $this->obj_type . "_" . $this->sub_obj_id . "_" .
117 
118  $this->setUserId($ilUser->getId());
119  }
setUserId(int $a_userid)
$ilUser
Definition: imgupload.php:34
+ Here is the call graph for this function:

◆ setUpdateCallback()

ilRatingGUI::setUpdateCallback (   $a_callback)

Definition at line 684 of file class.ilRatingGUI.php.

684  : void
685  {
686  $this->update_callback = $a_callback;
687  }

◆ setUserId()

ilRatingGUI::setUserId ( int  $a_userid)

Definition at line 121 of file class.ilRatingGUI.php.

Referenced by setObject().

121  : void
122  {
123  $this->userid = $a_userid;
124  }
+ Here is the caller graph for this function:

◆ setYourRatingText()

ilRatingGUI::setYourRatingText ( string  $a_val)

Definition at line 131 of file class.ilRatingGUI.php.

131  : void
132  {
133  $this->your_rating_text = $a_val;
134  }

Field Documentation

◆ $ctrl

ilCtrl ilRatingGUI::$ctrl
protected

Definition at line 28 of file class.ilRatingGUI.php.

Referenced by executeCommand(), renderDetails(), and saveRating().

◆ $ctrl_path

array ilRatingGUI::$ctrl_path = []
protected

Definition at line 33 of file class.ilRatingGUI.php.

◆ $enable_categories

bool ilRatingGUI::$enable_categories = false
protected

Definition at line 34 of file class.ilRatingGUI.php.

◆ $export_callback

ilRatingGUI::$export_callback
protected

Definition at line 31 of file class.ilRatingGUI.php.

◆ $export_subobj_title

string ilRatingGUI::$export_subobj_title = ""
protected

Definition at line 32 of file class.ilRatingGUI.php.

◆ $id

string ilRatingGUI::$id = "rtg_"
protected

Definition at line 30 of file class.ilRatingGUI.php.

Referenced by getHTML().

◆ $lng

ilLanguage ilRatingGUI::$lng
protected

Definition at line 27 of file class.ilRatingGUI.php.

Referenced by addTooltip(), getHTML(), and renderDetails().

◆ $obj_id

int ilRatingGUI::$obj_id
protected

Definition at line 38 of file class.ilRatingGUI.php.

◆ $obj_type

string ilRatingGUI::$obj_type
protected

Definition at line 39 of file class.ilRatingGUI.php.

◆ $requested_rating

int ilRatingGUI::$requested_rating
protected

Definition at line 45 of file class.ilRatingGUI.php.

Referenced by saveRating().

◆ $requested_ratings

array ilRatingGUI::$requested_ratings = null
protected

Definition at line 44 of file class.ilRatingGUI.php.

◆ $sub_obj_id

int ilRatingGUI::$sub_obj_id
protected

Definition at line 40 of file class.ilRatingGUI.php.

◆ $sub_obj_type

string ilRatingGUI::$sub_obj_type
protected

Definition at line 41 of file class.ilRatingGUI.php.

Referenced by setObject().

◆ $ui

ILIAS DI UIServices ilRatingGUI::$ui
protected

Definition at line 36 of file class.ilRatingGUI.php.

Referenced by getBlockHTML().

◆ $update_callback

ilRatingGUI::$update_callback = null
protected

Definition at line 43 of file class.ilRatingGUI.php.

◆ $user

ilObjUser ilRatingGUI::$user
protected

Definition at line 29 of file class.ilRatingGUI.php.

Referenced by addTooltip(), and setObject().

◆ $userid

int ilRatingGUI::$userid
protected

Definition at line 42 of file class.ilRatingGUI.php.

Referenced by getUserId().

◆ $your_rating_text

string ilRatingGUI::$your_rating_text = ""
protected

Definition at line 35 of file class.ilRatingGUI.php.

Referenced by getYourRatingText().


The documentation for this class was generated from the following file: