30 protected string $id =
"rtg_";
36 protected \ILIAS\DI\UIServices
$ui;
51 $this->
lng = $DIC->language();
52 $this->
ctrl = $DIC->ctrl();
53 $this->
user = $DIC->user();
54 $lng = $DIC->language();
56 $this->
ui = $DIC->ui();
58 $params = $DIC->http()->request()->getQueryParams();
59 $body = $DIC->http()->request()->getParsedBody();
61 if (isset($body[
"rating"]) && is_array($body[
"rating"])) {
62 $this->requested_ratings = ($body[
"rating"] ?? null);
64 $this->requested_rating = (
int) (
$params[
"rating"] ?? 0);
77 $cmd = $ilCtrl->getCmd();
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);
102 ?
int $a_sub_obj_id = 0,
103 ?
string $a_sub_obj_type =
"" 107 if (!trim((
string) $a_sub_obj_type)) {
108 $a_sub_obj_type =
"-";
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 .
"_" .
123 $this->userid = $a_userid;
133 $this->your_rating_text = $a_val;
143 $this->enable_categories = $a_value;
148 $this->ctrl_path = $a_value;
155 array $a_categories = null,
156 string $a_onclick = null,
157 bool $a_average =
false,
158 bool $add_tooltip =
false 162 $f = $this->
ui->factory();
163 $r = $this->
ui->renderer();
165 $ttpl =
new ilTemplate(
"tpl.rating_details.html",
true,
true,
"components/ILIAS/Rating");
171 : $lng->
txt(
"rating_your_rating");
175 if (!$a_categories) {
199 for ($i = 1; $i <= 5; $i++) {
200 $star_tpl =
new ilTemplate(
"tpl.rating_star.html",
true,
true,
"components/ILIAS/Rating");
203 $star_tpl->setCurrentBlock(
"rating_mark_simple");
204 $star_tpl->setVariable(
208 $star_tpl->parseCurrentBlock();
211 $ttpl->setCurrentBlock(
"rating_link_simple");
212 if (stristr((
string) $a_onclick,
"%rating%")) {
215 $ilCtrl->setParameter($this,
"rating", $i);
216 if (!$this->ctrl_path) {
217 $url_save = $ilCtrl->getLinkTarget($this,
"saveRating");
219 $url_save = $ilCtrl->getLinkTargetByClass($this->ctrl_path,
"saveRating");
222 $b = $this->
ui->factory()->button()->shy(
"###star###", $url_save);
225 $onclick = str_replace(
"%rating%", $i, $a_onclick);
226 $b =
$b->withOnLoadCode(
function ($id) use ($onclick) {
228 "$('#" . $id .
"').click(function() { $onclick; return false;});";
233 $ref_rating = $overall_rating[
"avg"];
235 $ref_rating = $rating;
238 if ($ref_rating >= $i) {
239 $star_tpl->setVariable(
244 $star_tpl->setVariable(
249 $star_tpl->setVariable(
251 sprintf($lng->
txt(
"rating_rate_x_of_5"), $i)
256 (
int) ($overall_rating[
"cnt"] ?? 0),
257 (
float) ($overall_rating[
"avg"] ?? 0),
260 $b =
$b->withHelpTopics(...
$f->helpTopics(...$topics));
263 $star_html = $this->
ui->renderer()->render(
$b);
264 $star_html = str_replace(
"###star###", $star_tpl->get(), $star_html);
266 $ttpl->setVariable(
"STAR_BUTTON", $star_html);
268 $ttpl->parseCurrentBlock();
273 $ttpl->setCurrentBlock(
"rating_simple_del_bl");
274 $ttpl->setVariable(
"CAPTION_RATING_DEL", $lng->
txt(
"rating_remove"));
276 if (stristr((
string) $a_onclick,
"%rating%")) {
279 $ilCtrl->setParameter($this,
"rating", 0);
280 if (!$this->ctrl_path) {
281 $url_save = $ilCtrl->getLinkTarget($this,
"saveRating");
283 $url_save = $ilCtrl->getLinkTargetByClass($this->ctrl_path,
"saveRating");
286 $ttpl->setVariable(
"HREF_RATING_DEL", $url_save);
289 $onclick = str_replace(
"%rating%", 0, $a_onclick);
290 $ttpl->setVariable(
"ONCLICK_RATING_DEL",
' onclick="' . $onclick .
'"');
293 $ttpl->parseCurrentBlock();
297 $ttpl->setCurrentBlock(
"rating_simple_title");
298 $ttpl->setVariable(
"TXT_RATING_SIMPLE", $rate_text);
299 $ttpl->parseCurrentBlock();
303 $overall_rating[
"cnt"]) {
304 $ttpl->setCurrentBlock(
"number_votes_simple");
305 $ttpl->setVariable(
"NUMBER_VOTES_SIMPLE", $overall_rating[
"cnt"]);
306 $ttpl->parseCurrentBlock();
310 $ttpl->setCurrentBlock(
"user_rating_simple");
311 $ttpl->parseCurrentBlock();
316 $has_user_rating =
false;
321 foreach ($a_categories as $category) {
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;
344 $star_tpl->setCurrentBlock(
"rating_mark");
345 $star_tpl->setVariable(
349 $star_tpl->parseCurrentBlock();
352 $ttpl->setCurrentBlock(
"user_rating_icon");
353 if ($overall_rating[
"avg"] >= $i) {
354 $star_tpl->setVariable(
358 $star_tpl->setVariable(
'RATING_FRACTION', 10);
359 } elseif ($overall_rating[
"avg"] + 1 <= $i) {
360 $star_tpl->setVariable(
364 $star_tpl->setVariable(
'RATING_FRACTION', 0);
366 $nr = round(($overall_rating[
"avg"] + 1 - $i) * 10);
367 $star_tpl->setVariable(
371 $star_tpl->setVariable(
"RATING_FRACTION", $nr);
373 $star_tpl->setVariable(
375 sprintf($lng->
txt(
"rating_rate_x_of_5"), $i)
378 $b =
$f->button()->shy(
"###star###",
"#");
380 $ttpl->setVariable(
"HREF_RATING",
"il.Rating.setValue(" . $category[
"id"] .
"," . $i .
", '" . $a_js_id .
"')");
381 $star_tpl->setVariable(
"CATEGORY_ID", $category[
"id"]);
382 $star_tpl->setVariable(
"ICON_VALUE", $i);
383 $star_tpl->setVariable(
"JS_ID", $a_js_id);
384 $b =
$b->withOnLoadCode(
function ($id) use ($category, $i, $a_js_id) {
386 "$('#" . $id .
"').click(function() { il.Rating.setValue(" . $category[
"id"] .
"," . $i .
", '" . $a_js_id .
"'); return false;});";
395 (
int) ($overall_rating[
"cnt"] ?? 0),
396 (
float) ($overall_rating[
"avg"] ?? 0),
397 (
int) ($user_rating ?? 0)
399 $b =
$b->withHelpTopics(...
$f->helpTopics(...$topics));
401 $button_html =
$r->render(
$b);
402 $button_html = str_replace(
"###star###", $star_tpl->get(), $button_html);
403 $ttpl->setVariable(
"RATE_BUTTON", $button_html);
404 $ttpl->parseCurrentBlock();
408 $ttpl->setCurrentBlock(
"user_rating_category_column");
409 $ttpl->setVariable(
"JS_ID", $a_js_id);
410 $ttpl->setVariable(
"CATEGORY_ID", $category[
"id"]);
411 $ttpl->setVariable(
"CATEGORY_VALUE", $user_rating);
412 $ttpl->parseCurrentBlock();
417 $ttpl->setCurrentBlock(
"user_rating_category");
418 $ttpl->setVariable(
"TXT_RATING_CATEGORY", $category[
"title"]);
419 $ttpl->parseCurrentBlock();
422 if ($overall_rating[
"cnt"] > 0) {
423 $ttpl->setCurrentBlock(
"votes_number_bl");
424 $ttpl->setVariable(
"NUMBER_VOTES", sprintf($lng->
txt(
"rating_number_votes"), $overall_rating[
"cnt"]));
425 $ttpl->parseCurrentBlock();
430 if ($has_user_rating) {
431 $ttpl->setCurrentBlock(
"user_rating_categories_del_bl");
432 $ttpl->setVariable(
"CAPTION_RATING_DEL_CAT", $lng->
txt(
"rating_remove"));
434 $ilCtrl->setParameter($this,
"rating", 0);
435 if (!$this->ctrl_path) {
436 $url_save = $ilCtrl->getLinkTarget($this,
"resetUserRating");
438 $url_save = $ilCtrl->getLinkTargetByClass($this->ctrl_path,
"resetUserRating");
440 $ttpl->setVariable(
"HREF_RATING_DEL_CAT", $url_save);
442 $ttpl->parseCurrentBlock();
445 if (!$this->ctrl_path) {
446 $url_form = $ilCtrl->getFormAction($this,
"saveRating");
448 $url_form = $ilCtrl->getFormActionByClass($this->ctrl_path,
"saveRating");
450 $ttpl->setVariable(
"FORM_ACTION", $url_form);
451 $ttpl->setVariable(
"TXT_SUBMIT", $lng->
txt(
"rating_overlay_submit"));
452 $ttpl->setVariable(
"CMD_SUBMIT",
"saveRating");
453 $ttpl->touchBlock(
"user_rating_categories_form_out");
462 bool $a_show_overall =
true,
463 bool $a_may_rate =
true,
464 string $a_onclick = null,
465 string $a_additional_id = null
467 $f = $this->
ui->factory();
468 $r = $this->
ui->renderer();
471 if ($a_additional_id) {
472 $unique_id .=
"_" . $a_additional_id;
475 $categories = array();
476 if ($this->enable_categories) {
481 if ($may_rate && !$a_may_rate) {
485 $has_overlay =
false;
486 if ($may_rate || $categories) {
490 $ttpl =
new ilTemplate(
"tpl.rating_input.html",
true,
true,
"components/ILIAS/Rating");
494 if ($may_rate || !$a_show_overall) {
505 if ($a_show_overall) {
513 $rating = array(
"avg" => $user_rating);
516 for ($i = 1; $i <= 5; $i++) {
517 if ($a_show_overall &&
518 $i == $user_rating) {
519 $ttpl->setCurrentBlock(
"rating_mark");
524 $ttpl->parseCurrentBlock();
527 $ttpl->setCurrentBlock(
"rating_icon");
528 if ($rating[
"avg"] >= $i) {
533 } elseif ($rating[
"avg"] + 1 <= $i) {
539 $nr = round(($rating[
"avg"] + 1 - $i) * 10);
545 $ttpl->setVariable(
"ALT_ICON",
"");
546 $ttpl->parseCurrentBlock();
548 $ttpl->setCurrentBlock(
"rating_icon");
550 if ($a_show_overall) {
551 if ($rating[
"cnt"] > 0) {
552 $ttpl->setCurrentBlock(
"rat_nr");
553 $ttpl->setVariable(
"RT_NR", $rating[
"cnt"]);
554 $ttpl->parseCurrentBlock();
560 $ttpl->setCurrentBlock(
"act_rat_start");
561 $ttpl->setVariable(
"ID", $unique_id);
562 $ttpl->setVariable(
"TXT_OPEN_DIALOG", $lng->
txt(
"rating_open_dialog"));
563 $ttpl->parseCurrentBlock();
565 $ttpl->touchBlock(
"act_rat_end");
568 $ttpl->parseCurrentBlock();
573 $ttpl->setVariable(
"TTID", $unique_id);
574 $rating_html = $ttpl->get();
577 (
int) ($rating[
"cnt"] ?? 0),
578 (
float) ($rating[
"avg"] ?? 0),
579 (
int) ($user_rating ?? 0)
583 $button =
$f->button()->shy(
'###button###',
'#')
584 ->withOnLoadCode(
function (
string $id):
string {
585 return "document.getElementById('$id').classList.add('ilRating');";
590 $this->
renderDetails(
"rtov_", $may_rate, $categories, $a_onclick)
593 $popover =
$f->popover()->standard(
594 $f->legacy($this->renderDetails(
"rtov_", $may_rate, $categories, $a_onclick))
596 $button = $button->withOnClick($popover->getShowSignal());
597 $button = $button->withHelpTopics(
598 ...
$f->helpTopics(...$tt_topics)
600 $elements = [$popover, $button];
605 $button = $button->withHelpTopics(
606 ...
$f->helpTopics(...$tt_topics)
608 $elements = [$button];
610 $html =
$r->render($elements);
611 $html = str_replace(
"###button###", $rating_html, $html);
630 $topics[] = sprintf($lng->
txt(
"rat_nr_ratings"), $cnt);
632 $topics[] = $lng->
txt(
"rating_avg_rating") .
": " . round($avg, 1);
645 $categories = array();
646 if ($this->enable_categories) {
653 $panel = $ui->factory()->panel()->secondary()->legacy(
655 $ui->factory()->legacy(
656 $this->
renderDetails(
"rtsb_", $may_rate, $categories, null,
true,
true)
660 return $ui->renderer()->render($panel);
670 if (!is_array($this->requested_ratings)) {
685 foreach ($this->requested_ratings as $cat_id => $rating) {
698 if ($this->update_callback) {
700 $this->update_callback,
708 if ($ilCtrl->isAsynch()) {
715 $this->update_callback = $a_callback;
723 (
int) $this->sub_obj_id,
731 $this->export_callback = $a_callback;
732 $this->export_subobj_title = $a_subobj_title;
745 "il.Object.saveRatingFromListGUI(" . $a_ref_id .
", '" . $a_ajax_hash .
"', %rating%);",
setExportCallback($a_callback, string $a_subobj_title)
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...
setUpdateCallback($a_callback)
if(! $DIC->user() ->getId()||!ilLTIConsumerAccess::hasCustomProviderCreationAccess()) $params
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)
setObject(int $a_obj_id, string $a_obj_type, ?int $a_sub_obj_id=0, ?string $a_sub_obj_type="")
Set Object.
loadLanguageModule(string $a_module)
Load language module.
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.
getBlockHTML(string $a_title)
string $export_subobj_title
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.
setCtrlPath(array $a_value)
getNextClass($a_gui_class=null)
Class ilRatingCategoryGUI.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getTooltipTopics(int $cnt=0, float $avg=0, int $user=0)
static getAllForObject(int $a_parent_obj_id)
getHTML(bool $a_show_overall=true, bool $a_may_rate=true, string $a_onclick=null, string $a_additional_id=null)
static getImagePath(string $image_name, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
enableCategories(bool $a_value)
setYourRatingText(string $a_val)
getListGUIProperty(int $a_ref_id, bool $a_may_rate, string $a_ajax_hash, int $parent_ref_id)
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.
executeCommand()
execute command
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.