ILIAS  trunk Revision v11.0_alpha-1744-gb0451eebef4
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator 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)
 
 getTooltipTopics (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(), null, 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:31
ilLanguage $lng
loadLanguageModule(string $a_module)
Load language module.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
global $DIC
Definition: shib_login.php:22
+ Here is the call graph for this function:

Member Function Documentation

◆ 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 635 of file class.ilRatingGUI.php.

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

635  : string
636  {
637  $ui = $this->ui;
638 
639  $categories = array();
640  if ($this->enable_categories) {
641  $categories = ilRatingCategory::getAllForObject($this->obj_id);
642  }
643 
644  $may_rate = ($this->getUserId() != ANONYMOUS_USER_ID);
645 
646 
647  $panel = $ui->factory()->panel()->secondary()->legacy(
648  $a_title,
649  $ui->factory()->legacy(
650  $this->renderDetails("rtsb_", $may_rate, $categories, null, true, true)
651  )
652  );
653 
654  return $ui->renderer()->render($panel);
655  }
ILIAS DI UIServices $ui
const ANONYMOUS_USER_ID
Definition: constants.php:27
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)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
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 458 of file class.ilRatingGUI.php.

References Vendor\Package\$f, $id, $lng, $r, ANONYMOUS_USER_ID, ilRatingCategory\getAllForObject(), ilUtil\getImagePath(), ilRating\getOverallRatingForObject(), ilRating\getRatingForUserAndObject(), getTooltipTopics(), getUserId(), renderDetails(), ilLanguage\txt(), and ILIAS\Repository\ui().

Referenced by getListGUIProperty().

463  : string {
464  $f = $this->ui->factory();
465  $r = $this->ui->renderer();
466  $lng = $this->lng;
467  $unique_id = $this->id;
468  if ($a_additional_id) {
469  $unique_id .= "_" . $a_additional_id;
470  }
471 
472  $categories = array();
473  if ($this->enable_categories) {
474  $categories = ilRatingCategory::getAllForObject($this->obj_id);
475  }
476 
477  $may_rate = ($this->getUserId() != ANONYMOUS_USER_ID);
478  if ($may_rate && !$a_may_rate) {
479  $may_rate = false;
480  }
481 
482  $has_overlay = false;
483  if ($may_rate || $categories) {
484  $has_overlay = true;
485  }
486 
487  $ttpl = new ilTemplate("tpl.rating_input.html", true, true, "components/ILIAS/Rating");
488 
489  // user rating
490  $user_rating = 0;
491  if ($may_rate || !$a_show_overall) {
492  $user_rating = round(ilRating::getRatingForUserAndObject(
493  $this->obj_id,
494  $this->obj_type,
495  $this->sub_obj_id,
496  $this->sub_obj_type,
497  $this->getUserId()
498  ));
499  }
500 
501  // (1) overall rating
502  if ($a_show_overall) {
504  $this->obj_id,
505  $this->obj_type,
506  $this->sub_obj_id,
507  $this->sub_obj_type
508  );
509  } else {
510  $rating = array("avg" => $user_rating);
511  }
512 
513  for ($i = 1; $i <= 5; $i++) {
514  if ($a_show_overall &&
515  $i == $user_rating) {
516  $ttpl->setCurrentBlock("rating_mark");
517  $ttpl->setVariable(
518  "SRC_MARK",
519  ilUtil::getImagePath("standard/icon_rate_marker.svg")
520  );
521  $ttpl->parseCurrentBlock();
522  }
523 
524  $ttpl->setCurrentBlock("rating_icon");
525  if ($rating["avg"] >= $i) {
526  $ttpl->setVariable(
527  "SRC_ICON",
528  ilUtil::getImagePath("standard/icon_rate_on.svg")
529  );
530  } elseif ($rating["avg"] + 1 <= $i) {
531  $ttpl->setVariable(
532  "SRC_ICON",
533  ilUtil::getImagePath("standard/icon_rate_off.svg")
534  );
535  } else {
536  $nr = round(($rating["avg"] + 1 - $i) * 10);
537  $ttpl->setVariable(
538  "SRC_ICON",
539  ilUtil::getImagePath("standard/icon_rate_$nr.svg")
540  );
541  }
542  $ttpl->setVariable("ALT_ICON", "");
543  $ttpl->parseCurrentBlock();
544  }
545  $ttpl->setCurrentBlock("rating_icon");
546 
547  if ($a_show_overall) {
548  if ($rating["cnt"] > 0) {
549  $ttpl->setCurrentBlock("rat_nr");
550  $ttpl->setVariable("RT_NR", $rating["cnt"]);
551  $ttpl->parseCurrentBlock();
552  }
553  }
554 
555  // add overlay (trigger)
556  if ($has_overlay) {
557  $ttpl->setCurrentBlock("act_rat_start");
558  $ttpl->setVariable("ID", $unique_id);
559  $ttpl->setVariable("TXT_OPEN_DIALOG", $lng->txt("rating_open_dialog"));
560  $ttpl->parseCurrentBlock();
561 
562  $ttpl->touchBlock("act_rat_end");
563  }
564 
565  $ttpl->parseCurrentBlock();
566 
567 
568  // (2) user rating
569 
570  $ttpl->setVariable("TTID", $unique_id);
571  $rating_html = $ttpl->get();
572 
573  $tt_topics = $this->getTooltipTopics(
574  (int) ($rating["cnt"] ?? 0),
575  (float) ($rating["avg"] ?? 0),
576  (int) ($user_rating ?? 0)
577  );
578 
579 
580  $button = $f->button()->shy('###button###', '#');
581  if ($has_overlay) {
582  $ttpl->setVariable(
583  "RATING_DETAILS",
584  $this->renderDetails("rtov_", $may_rate, $categories, $a_onclick)
585  );
586 
587  $popover = $f->popover()->standard(
588  $f->legacy($this->renderDetails("rtov_", $may_rate, $categories, $a_onclick))
589  );
590  $button = $button->withOnClick($popover->getShowSignal());
591  $button = $button->withHelpTopics(
592  ...$f->helpTopics(...$tt_topics)
593  );
594  $elements = [$popover, $button];
595  } else {
596  $button = $button->withOnLoadCode(function ($id) {
597  return "return false;";
598  });
599  $button = $button->withHelpTopics(
600  ...$f->helpTopics(...$tt_topics)
601  );
602  $elements = [$button];
603  }
604  $html = $r->render($elements);
605  $html = str_replace("###button###", $rating_html, $html);
606 
607  return $html;
608  }
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...
ilLanguage $lng
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.
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)
getTooltipTopics(int $cnt=0, float $avg=0, int $user=0)
static getAllForObject(int $a_parent_obj_id)
static getImagePath(string $image_name, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
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.
$r
+ 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 730 of file class.ilRatingGUI.php.

References getHTML().

735  : string {
736  return $this->getHTML(
737  true,
738  $a_may_rate,
739  "il.Object.saveRatingFromListGUI(" . $a_ref_id . ", '" . $a_ajax_hash . "', %rating%);",
740  $parent_ref_id
741  );
742  }
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:

◆ getTooltipTopics()

ilRatingGUI::getTooltipTopics ( int  $cnt = 0,
float  $avg = 0,
int  $user = 0 
)
protected

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

References $lng, ILIAS\GlobalScreen\Scope\$topics, $user, and ilLanguage\txt().

Referenced by getHTML(), and renderDetails().

614  : array {
615  $topics = [];
616  $lng = $this->lng;
617 
618  if ($cnt == 0) {
619  $topics[] = $lng->txt("rat_not_rated_yet");
620  } else {
621  if ($cnt == 1) {
622  $topics[] = $lng->txt("rat_one_rating");
623  } else {
624  $topics[] = sprintf($lng->txt("rat_nr_ratings"), $cnt);
625  }
626  $topics[] = $lng->txt("rating_avg_rating") . ": " . round($avg, 1);
627  }
628 
629  if ($user > 0) {
630  $topics[] = $lng->txt("rating_personal_rating") . ": " . $user;
631  }
632  return $topics;
633  }
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
+ Here is the call graph for this function:
+ Here is the caller 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 Vendor\Package\$b, $ctrl, Vendor\Package\$f, $lng, $r, ILIAS\GlobalScreen\Scope\$topics, ilUtil\getImagePath(), ilRating\getOverallRatingForObject(), ilRating\getRatingForUserAndObject(), getTooltipTopics(), getUserId(), getYourRatingText(), null, ilLanguage\txt(), and ILIAS\Repository\ui().

Referenced by getBlockHTML(), and getHTML().

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

◆ resetUserRating()

ilRatingGUI::resetUserRating ( )

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

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

Referenced by saveRating().

712  : void
713  {
715  $this->obj_id,
716  $this->obj_type,
717  (int) $this->sub_obj_id,
718  $this->sub_obj_type,
719  $this->getUserId()
720  );
721  }
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 660 of file class.ilRatingGUI.php.

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

660  : void
661  {
662  $ilCtrl = $this->ctrl;
663 
664  if (!is_array($this->requested_ratings)) {
665  $rating = $this->requested_rating;
666  if ($rating == 0) {
667  $this->resetUserRating();
668  } else {
670  $this->obj_id,
671  $this->obj_type,
672  $this->sub_obj_id,
673  $this->sub_obj_type,
674  $this->getUserId(),
675  $rating
676  );
677  }
678  } else {
679  foreach ($this->requested_ratings as $cat_id => $rating) {
681  $this->obj_id,
682  $this->obj_type,
683  $this->sub_obj_id,
684  $this->sub_obj_type,
685  $this->getUserId(),
686  $rating,
687  $cat_id
688  );
689  }
690  }
691 
692  if ($this->update_callback) {
693  call_user_func(
694  $this->update_callback,
695  $this->obj_id,
696  $this->obj_type,
697  $this->sub_obj_id,
698  $this->sub_obj_type
699  );
700  }
701 
702  if ($ilCtrl->isAsynch()) {
703  exit();
704  }
705  }
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.
exit
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
+ 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 723 of file class.ilRatingGUI.php.

723  : void
724  {
725  $this->export_callback = $a_callback;
726  $this->export_subobj_title = $a_subobj_title;
727  }

◆ 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 $sub_obj_type, $user, and setUserId().

104  : void {
105  $ilUser = $this->user;
106 
107  if (!trim((string) $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)
+ Here is the call graph for this function:

◆ setUpdateCallback()

ilRatingGUI::setUpdateCallback (   $a_callback)

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

707  : void
708  {
709  $this->update_callback = $a_callback;
710  }

◆ 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 getHTML(), getTooltipTopics(), 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 getTooltipTopics(), 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: