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 163 $ttpl =
new ilTemplate(
"tpl.rating_details.html",
true,
true,
"Services/Rating");
169 : $lng->
txt(
"rating_your_rating");
173 if (!$a_categories) {
197 for ($i = 1; $i <= 5; $i++) {
200 $ttpl->setCurrentBlock(
"rating_mark_simple");
205 $ttpl->parseCurrentBlock();
208 $ttpl->setCurrentBlock(
"rating_link_simple");
209 if (stristr((
string) $a_onclick,
"%rating%")) {
212 $ilCtrl->setParameter($this,
"rating", $i);
213 if (!$this->ctrl_path) {
214 $url_save = $ilCtrl->getLinkTarget($this,
"saveRating");
216 $url_save = $ilCtrl->getLinkTargetByClass($this->ctrl_path,
"saveRating");
219 $ttpl->setVariable(
"HREF_RATING", $url_save);
222 $onclick = str_replace(
"%rating%", $i, $a_onclick);
223 $ttpl->setVariable(
"ONCLICK_RATING",
' onclick="' . $onclick .
'"');
227 $ref_rating = $overall_rating[
"avg"];
229 $ref_rating = $rating;
232 if ($ref_rating >= $i) {
245 sprintf($lng->
txt(
"rating_rate_x_of_5"), $i)
247 $ttpl->parseCurrentBlock();
252 $ttpl->setCurrentBlock(
"rating_simple_del_bl");
253 $ttpl->setVariable(
"CAPTION_RATING_DEL", $lng->
txt(
"rating_remove"));
255 if (stristr((
string) $a_onclick,
"%rating%")) {
258 $ilCtrl->setParameter($this,
"rating", 0);
259 if (!$this->ctrl_path) {
260 $url_save = $ilCtrl->getLinkTarget($this,
"saveRating");
262 $url_save = $ilCtrl->getLinkTargetByClass($this->ctrl_path,
"saveRating");
265 $ttpl->setVariable(
"HREF_RATING_DEL", $url_save);
268 $onclick = str_replace(
"%rating%", 0, $a_onclick);
269 $ttpl->setVariable(
"ONCLICK_RATING_DEL",
' onclick="' . $onclick .
'"');
272 $ttpl->parseCurrentBlock();
276 $ttpl->setCurrentBlock(
"rating_simple_title");
277 $ttpl->setVariable(
"TXT_RATING_SIMPLE", $rate_text);
278 $ttpl->parseCurrentBlock();
282 $overall_rating[
"cnt"]) {
283 $ttpl->setCurrentBlock(
"number_votes_simple");
284 $ttpl->setVariable(
"NUMBER_VOTES_SIMPLE", $overall_rating[
"cnt"]);
285 $ttpl->parseCurrentBlock();
289 $unique_id = $this->
id .
"_block";
290 $ttpl->setVariable(
"TTID", $unique_id);
293 (
int) ($overall_rating[
"cnt"] ?? 0),
294 (
float) ($overall_rating[
"avg"] ?? 0),
300 $ttpl->setCurrentBlock(
"user_rating_simple");
301 $ttpl->parseCurrentBlock();
306 $has_user_rating =
false;
311 foreach ($a_categories as $category) {
329 for ($i = 1; $i <= 5; $i++) {
330 if ($a_may_rate && $i == $user_rating) {
331 $has_user_rating =
true;
333 $ttpl->setCurrentBlock(
"rating_mark");
338 $ttpl->parseCurrentBlock();
341 $ttpl->setCurrentBlock(
"user_rating_icon");
342 if ($overall_rating[
"avg"] >= $i) {
347 } elseif ($overall_rating[
"avg"] + 1 <= $i) {
353 $nr = round(($overall_rating[
"avg"] + 1 - $i) * 10);
361 sprintf($lng->
txt(
"rating_rate_x_of_5"), $i)
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)\"");
373 $ttpl->parseCurrentBlock();
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);
382 $unique_id = $this->
id .
"_block_" . $category[
"id"];
383 $ttpl->setVariable(
"CAT_TTID", $unique_id);
386 (
int) ($overall_rating[
"cnt"] ?? 0),
387 (
float) ($overall_rating[
"avg"] ?? 0),
388 (
int) ($user_rating ?? 0)
391 $ttpl->parseCurrentBlock();
396 $ttpl->setCurrentBlock(
"user_rating_category");
397 $ttpl->setVariable(
"TXT_RATING_CATEGORY", $category[
"title"]);
398 $ttpl->parseCurrentBlock();
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();
409 if ($has_user_rating) {
410 $ttpl->setCurrentBlock(
"user_rating_categories_del_bl");
411 $ttpl->setVariable(
"CAPTION_RATING_DEL_CAT", $lng->
txt(
"rating_remove"));
413 $ilCtrl->setParameter($this,
"rating", 0);
414 if (!$this->ctrl_path) {
415 $url_save = $ilCtrl->getLinkTarget($this,
"resetUserRating");
417 $url_save = $ilCtrl->getLinkTargetByClass($this->ctrl_path,
"resetUserRating");
419 $ttpl->setVariable(
"HREF_RATING_DEL_CAT", $url_save);
421 $ttpl->parseCurrentBlock();
424 if (!$this->ctrl_path) {
425 $url_form = $ilCtrl->getFormAction($this,
"saveRating");
427 $url_form = $ilCtrl->getFormActionByClass($this->ctrl_path,
"saveRating");
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");
441 bool $a_show_overall =
true,
442 bool $a_may_rate =
true,
443 string $a_onclick = null,
444 string $a_additional_id = null
446 $f = $this->
ui->factory();
447 $r = $this->
ui->renderer();
450 if ($a_additional_id) {
451 $unique_id .=
"_" . $a_additional_id;
454 $categories = array();
455 if ($this->enable_categories) {
460 if ($may_rate && !$a_may_rate) {
464 $has_overlay =
false;
465 if ($may_rate || $categories) {
469 $ttpl =
new ilTemplate(
"tpl.rating_input.html",
true,
true,
"Services/Rating");
473 if ($may_rate || !$a_show_overall) {
484 if ($a_show_overall) {
492 $rating = array(
"avg" => $user_rating);
495 for ($i = 1; $i <= 5; $i++) {
496 if ($a_show_overall &&
497 $i == $user_rating) {
498 $ttpl->setCurrentBlock(
"rating_mark");
503 $ttpl->parseCurrentBlock();
506 $ttpl->setCurrentBlock(
"rating_icon");
507 if ($rating[
"avg"] >= $i) {
512 } elseif ($rating[
"avg"] + 1 <= $i) {
518 $nr = round(($rating[
"avg"] + 1 - $i) * 10);
524 $ttpl->setVariable(
"ALT_ICON",
"");
525 $ttpl->parseCurrentBlock();
527 $ttpl->setCurrentBlock(
"rating_icon");
529 if ($a_show_overall) {
530 if ($rating[
"cnt"] > 0) {
531 $ttpl->setCurrentBlock(
"rat_nr");
532 $ttpl->setVariable(
"RT_NR", $rating[
"cnt"]);
533 $ttpl->parseCurrentBlock();
539 (
int) ($rating[
"cnt"] ?? 0),
540 (
float) ($rating[
"avg"] ?? 0),
541 (
int) ($user_rating ?? 0)
551 $ttpl->setCurrentBlock(
"act_rat_start");
552 $ttpl->setVariable(
"ID", $unique_id);
553 $ttpl->setVariable(
"TXT_OPEN_DIALOG", $lng->
txt(
"rating_open_dialog"));
554 $ttpl->parseCurrentBlock();
556 $ttpl->touchBlock(
"act_rat_end");
559 $ttpl->parseCurrentBlock();
564 $ttpl->setVariable(
"TTID", $unique_id);
565 $rating_html = $ttpl->get();
570 $this->
renderDetails(
"rtov_", $may_rate, $categories, $a_onclick)
573 $popover =
$f->popover()->standard(
574 $f->legacy($this->renderDetails(
"rtov_", $may_rate, $categories, $a_onclick))
576 $button =
$f->button()->shy(
'###button###',
'#')
577 ->withOnClick($popover->getShowSignal())
579 return "document.getElementById('$id').classList.add('ilRating');";
586 $popover_html =
$r->render([$popover, $button]);
587 $rating_html = str_replace(
"###button###", $rating_html, $popover_html);
605 $tt = $lng->
txt(
"rat_not_rated_yet");
608 $tt = $lng->
txt(
"rat_one_rating");
610 $tt = sprintf($lng->
txt(
"rat_nr_ratings"), $cnt);
612 $tt .=
"<br>" . $lng->
txt(
"rating_avg_rating") .
": " . round($avg, 1);
616 $tt .=
"<br>" . $lng->
txt(
"rating_personal_rating") .
": " .
$user;
634 $categories = array();
635 if ($this->enable_categories) {
642 $panel = $ui->factory()->panel()->secondary()->legacy(
644 $ui->factory()->legacy(
645 $this->
renderDetails(
"rtsb_", $may_rate, $categories, null,
true,
true)
649 return $ui->renderer()->render($panel);
659 if (!is_array($this->requested_ratings)) {
674 foreach ($this->requested_ratings as $cat_id => $rating) {
687 if ($this->update_callback) {
689 $this->update_callback,
697 if ($ilCtrl->isAsynch()) {
704 $this->update_callback = $a_callback;
712 (
int) $this->sub_obj_id,
720 $this->export_callback = $a_callback;
721 $this->export_subobj_title = $a_subobj_title;
734 "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)
static getImagePath(string $img, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
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)
withOnLoadCode(Closure $binder)
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...
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)
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)
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.
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.