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();
56 $this->
ui = $DIC->ui();
58 $params =
$DIC->http()->request()->getQueryParams();
59 $body =
$DIC->http()->request()->getParsedBody();
61 if (isset($body[
'rating'])) {
62 if (is_array($body[
'rating'])) {
63 $this->requested_ratings = ($body[
'rating'] ??
null);
65 $this->requested_rating = (
int) ($body[
'rating'] ?? 0);
68 $this->requested_rating = (
int) (
$params[
'rating'] ?? 0);
82 $cmd = $ilCtrl->getCmd();
84 switch ($next_class) {
85 case "ilratingcategorygui":
86 $gui =
new ilRatingCategoryGUI($this->obj_id, $this->export_callback, $this->export_subobj_title);
87 $ilCtrl->forwardCommand($gui);
98 return [
'saveRating'];
117 ?
int $a_sub_obj_id = 0,
118 ?
string $a_sub_obj_type =
""
120 $ilUser = $this->
user;
122 if (!trim((
string) $a_sub_obj_type)) {
123 $a_sub_obj_type =
"-";
126 $this->obj_id = $a_obj_id;
127 $this->obj_type = $a_obj_type;
128 $this->sub_obj_id = $a_sub_obj_id;
129 $this->sub_obj_type = $a_sub_obj_type;
130 $this->
id =
"rtg_" . $this->obj_id .
"_" . $this->obj_type .
"_" . $this->sub_obj_id .
"_" .
138 $this->userid = $a_userid;
143 return $this->userid;
148 $this->your_rating_text = $a_val;
153 return $this->your_rating_text;
158 $this->enable_categories = $a_value;
163 $this->ctrl_path = $a_value;
170 ?array $a_categories =
null,
171 ?
string $a_onclick =
null,
172 bool $a_average =
false,
173 bool $add_tooltip =
false
176 $ilCtrl = $this->ctrl;
177 $f = $this->
ui->factory();
178 $r = $this->
ui->renderer();
180 $ttpl =
new ilTemplate(
"tpl.rating_details.html",
true,
true,
"components/ILIAS/Rating");
183 if ($this->getYourRatingText() !=
"#") {
184 $rate_text = ($this->getYourRatingText() !=
"")
185 ? $this->getYourRatingText()
186 :
$lng->txt(
"rating_your_rating");
190 if (!$a_categories) {
214 for ($i = 1; $i <= 5; $i++) {
215 $star_tpl =
new ilTemplate(
"tpl.rating_star.html",
true,
true,
"components/ILIAS/Rating");
218 $star_tpl->setCurrentBlock(
"rating_mark_simple");
219 $star_tpl->setVariable(
223 $star_tpl->parseCurrentBlock();
226 $ttpl->setCurrentBlock(
"rating_link_simple");
227 if (stristr((
string) $a_onclick,
"%rating%")) {
230 $ilCtrl->setParameter($this,
"rating", $i);
231 if (!$this->ctrl_path) {
232 $url_save = $ilCtrl->getLinkTarget($this,
"saveRating");
234 $url_save = $ilCtrl->getLinkTargetByClass($this->ctrl_path,
"saveRating");
237 $b = $this->
ui->factory()->button()->shy(
"###star###", $url_save);
240 $onclick = str_replace(
"%rating%", $i, $a_onclick);
241 $b =
$b->withOnLoadCode(
function (
$id) use ($onclick) {
243 "$('#" .
$id .
"').click(function() { $onclick; return false;});";
248 $ref_rating = $overall_rating[
"avg"];
250 $ref_rating = $rating;
253 if ($ref_rating >= $i) {
254 $star_tpl->setVariable(
259 $star_tpl->setVariable(
264 $star_tpl->setVariable(
266 sprintf(
$lng->txt(
"rating_rate_x_of_5"), $i)
270 $topics = $this->getTooltipTopics(
271 (
int) ($overall_rating[
"cnt"] ?? 0),
272 (
float) ($overall_rating[
"avg"] ?? 0),
275 $b =
$b->withHelpTopics(...
$f->helpTopics(...$topics));
278 $star_html = $this->
ui->renderer()->render(
$b);
279 $star_html = str_replace(
"###star###", $star_tpl->get(), $star_html);
281 $ttpl->setVariable(
"STAR_BUTTON", $star_html);
283 $ttpl->parseCurrentBlock();
288 $ttpl->setCurrentBlock(
"rating_simple_del_bl");
289 $ttpl->setVariable(
"CAPTION_RATING_DEL",
$lng->txt(
"rating_remove"));
291 if (stristr((
string) $a_onclick,
"%rating%")) {
294 $ilCtrl->setParameter($this,
"rating", 0);
295 if (!$this->ctrl_path) {
296 $url_save = $ilCtrl->getLinkTarget($this,
"saveRating");
298 $url_save = $ilCtrl->getLinkTargetByClass($this->ctrl_path,
"saveRating");
301 $ttpl->setVariable(
"HREF_RATING_DEL", $url_save);
304 $onclick = str_replace(
"%rating%", 0, $a_onclick);
305 $ttpl->setVariable(
"ONCLICK_RATING_DEL",
' onclick="' . $onclick .
'"');
308 $ttpl->parseCurrentBlock();
312 $ttpl->setCurrentBlock(
"rating_simple_title");
313 $ttpl->setVariable(
"TXT_RATING_SIMPLE", $rate_text);
314 $ttpl->parseCurrentBlock();
318 $overall_rating[
"cnt"]) {
319 $ttpl->setCurrentBlock(
"number_votes_simple");
320 $ttpl->setVariable(
"NUMBER_VOTES_SIMPLE", $overall_rating[
"cnt"]);
321 $ttpl->parseCurrentBlock();
325 $ttpl->setCurrentBlock(
"user_rating_simple");
326 $ttpl->parseCurrentBlock();
331 $has_user_rating =
false;
338 $category_ids = array_column($a_categories,
"id");
346 foreach ($a_categories as $category) {
364 for ($i = 1; $i <= 5; $i++) {
365 $star_tpl =
new ilTemplate(
"tpl.js_rating_star.html",
true,
true,
"components/ILIAS/Rating");
366 if ($a_may_rate && $i == $user_rating) {
367 $has_user_rating =
true;
369 $star_tpl->setCurrentBlock(
"rating_mark");
370 $star_tpl->setVariable(
374 $star_tpl->parseCurrentBlock();
377 $ttpl->setCurrentBlock(
"user_rating_icon");
378 if ($overall_rating[
"avg"] >= $i) {
379 $star_tpl->setVariable(
383 $star_tpl->setVariable(
'RATING_FRACTION', 10);
384 } elseif ($overall_rating[
"avg"] + 1 <= $i) {
385 $star_tpl->setVariable(
389 $star_tpl->setVariable(
'RATING_FRACTION', 0);
391 $nr = round(($overall_rating[
"avg"] + 1 - $i) * 10);
392 $star_tpl->setVariable(
396 $star_tpl->setVariable(
"RATING_FRACTION", $nr);
398 $star_tpl->setVariable(
400 sprintf(
$lng->txt(
"rating_rate_x_of_5"), $i)
403 $b =
$f->button()->shy(
"###star###",
"#");
405 $ttpl->setVariable(
"HREF_RATING",
"il.Rating.setValue(" . $category[
"id"] .
"," . $i .
", '" . $a_js_id .
"')");
406 $star_tpl->setVariable(
"CATEGORY_ID", $category[
"id"]);
407 $star_tpl->setVariable(
"ICON_VALUE", $i);
408 $star_tpl->setVariable(
"JS_ID", $a_js_id);
409 $b =
$b->withOnLoadCode(
function (
$id) use ($category, $i, $a_js_id) {
411 "$('#" .
$id .
"').click(function() { il.Rating.setValue(" . $category[
"id"] .
"," . $i .
", '" . $a_js_id .
"'); return false;});";
419 $topics = $this->getTooltipTopics(
420 (
int) ($overall_rating[
"cnt"] ?? 0),
421 (
float) ($overall_rating[
"avg"] ?? 0),
422 (
int) ($user_rating ?? 0)
424 $b =
$b->withHelpTopics(...
$f->helpTopics(...$topics));
426 $button_html = $r->render(
$b);
427 $button_html = str_replace(
"###star###", $star_tpl->get(), $button_html);
428 $ttpl->setVariable(
"RATE_BUTTON", $button_html);
429 $ttpl->parseCurrentBlock();
433 $ttpl->setCurrentBlock(
"user_rating_category_column");
434 $ttpl->setVariable(
"JS_ID", $a_js_id);
435 $ttpl->setVariable(
"CATEGORY_ID", $category[
"id"]);
436 $ttpl->setVariable(
"CATEGORY_VALUE", $user_rating);
437 $ttpl->parseCurrentBlock();
442 $ttpl->setCurrentBlock(
"user_rating_category");
443 $ttpl->setVariable(
"TXT_RATING_CATEGORY", $category[
"title"]);
444 $ttpl->parseCurrentBlock();
447 if ($overall_count > 0) {
448 $ttpl->setCurrentBlock(
"votes_number_bl");
449 $ttpl->setVariable(
"NUMBER_VOTES", sprintf(
$lng->txt(
"rating_number_votes"), $overall_count));
450 $ttpl->parseCurrentBlock();
455 if ($has_user_rating) {
456 $ttpl->setCurrentBlock(
"user_rating_categories_del_bl");
457 $ttpl->setVariable(
"CAPTION_RATING_DEL_CAT",
$lng->txt(
"rating_remove"));
459 $ilCtrl->setParameter($this,
"rating", 0);
460 if (!$this->ctrl_path) {
461 $url_save = $ilCtrl->getLinkTarget($this,
"resetUserRating");
463 $url_save = $ilCtrl->getLinkTargetByClass($this->ctrl_path,
"resetUserRating");
465 $ttpl->setVariable(
"HREF_RATING_DEL_CAT", $url_save);
467 $ttpl->parseCurrentBlock();
470 if (!$this->ctrl_path) {
471 $url_form = $ilCtrl->getFormAction($this,
"saveRating");
473 $url_form = $ilCtrl->getFormActionByClass($this->ctrl_path,
"saveRating");
475 $ttpl->setVariable(
"FORM_ACTION", $url_form);
476 $ttpl->setVariable(
"TXT_SUBMIT",
$lng->txt(
"rating_overlay_submit"));
477 $ttpl->setVariable(
"CMD_SUBMIT",
"saveRating");
478 $ttpl->touchBlock(
"user_rating_categories_form_out");
487 bool $a_show_overall =
true,
488 bool $a_may_rate =
true,
489 ?
string $a_onclick =
null,
490 ?
string $a_additional_id =
null
493 $r = $this->
ui->renderer();
496 if ($a_additional_id) {
497 $unique_id .=
"_" . $a_additional_id;
500 $categories = array();
501 if ($this->enable_categories) {
506 if ($may_rate && !$a_may_rate) {
510 $has_overlay =
false;
511 if ($may_rate || $categories) {
515 $ttpl =
new ilTemplate(
"tpl.rating_input.html",
true,
true,
"components/ILIAS/Rating");
519 if ($may_rate || !$a_show_overall) {
530 if ($a_show_overall) {
538 $rating = array(
"avg" => $user_rating);
541 for ($i = 1; $i <= 5; $i++) {
542 if ($a_show_overall &&
543 $i == $user_rating) {
544 $ttpl->setCurrentBlock(
"rating_mark");
549 $ttpl->parseCurrentBlock();
552 $ttpl->setCurrentBlock(
"rating_icon");
553 if ($rating[
"avg"] >= $i) {
558 } elseif ($rating[
"avg"] + 1 <= $i) {
564 $nr = round(($rating[
"avg"] + 1 - $i) * 10);
570 $ttpl->setVariable(
"ALT_ICON",
"");
571 $ttpl->parseCurrentBlock();
573 $ttpl->setCurrentBlock(
"rating_icon");
575 if ($a_show_overall) {
576 if ($rating[
"cnt"] > 0) {
577 $ttpl->setCurrentBlock(
"rat_nr");
578 $ttpl->setVariable(
"RT_NR", $rating[
"cnt"]);
579 $ttpl->parseCurrentBlock();
585 $ttpl->setCurrentBlock(
"act_rat_start");
586 $ttpl->setVariable(
"ID", $unique_id);
587 $ttpl->setVariable(
"TXT_OPEN_DIALOG",
$lng->txt(
"rating_open_dialog"));
588 $ttpl->parseCurrentBlock();
590 $ttpl->touchBlock(
"act_rat_end");
593 $ttpl->parseCurrentBlock();
598 $ttpl->setVariable(
"TTID", $unique_id);
599 $rating_html = $ttpl->get();
601 $tt_topics = $this->getTooltipTopics(
602 (
int) ($rating[
"cnt"] ?? 0),
603 (
float) ($rating[
"avg"] ?? 0),
604 (
int) ($user_rating ?? 0)
608 $button =
$f->button()->shy(
'###button###',
'#')
609 ->withOnLoadCode(
function (
string $id):
string {
610 return "document.getElementById('$id').classList.add('ilRating');";
615 $this->renderDetails(
"rtov_", $may_rate, $categories, $a_onclick)
618 $popover =
$f->popover()->standard(
619 $f->legacy()->content($this->renderDetails(
"rtov_", $may_rate, $categories, $a_onclick))
621 $button = $button->withOnClick($popover->getShowSignal());
622 $button = $button->withHelpTopics(
623 ...
$f->helpTopics(...$tt_topics)
625 $elements = [$popover, $button];
630 $button = $button->withHelpTopics(
631 ...
$f->helpTopics(...$tt_topics)
633 $elements = [$button];
635 $html = $r->render($elements);
636 $html = str_replace(
"###button###", $rating_html, $html);
655 $topics[] = sprintf(
$lng->txt(
"rat_nr_ratings"), $cnt);
657 $topics[] =
$lng->txt(
"rating_avg_rating") .
": " . round($avg, 1);
661 $topics[] =
$lng->txt(
"rating_personal_rating") .
": " . $user;
670 $categories = array();
671 if ($this->enable_categories) {
678 $panel = $ui->factory()->panel()->secondary()->legacy(
680 $ui->factory()->legacy()->content(
681 $this->renderDetails(
"rtsb_", $may_rate, $categories,
null,
true,
true)
685 return $ui->renderer()->render($panel);
693 $ilCtrl = $this->ctrl;
695 if (!is_array($this->requested_ratings)) {
696 $rating = $this->requested_rating;
698 $this->resetUserRating();
710 foreach ($this->requested_ratings as $cat_id => $rating) {
723 if ($this->update_callback) {
725 $this->update_callback,
733 if ($ilCtrl->isAsynch()) {
740 $this->update_callback = $a_callback;
748 (
int) $this->sub_obj_id,
756 $this->export_callback = $a_callback;
757 $this->export_subobj_title = $a_subobj_title;
770 "il.Object.saveRatingFromListGUI(" . $a_ref_id .
", '" . $a_ajax_hash .
"', %rating%);",
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Class ilCtrl provides processing control methods.
getNextClass($a_gui_class=null)
@inheritDoc
loadLanguageModule(string $a_module)
Load language module.
Class ilRatingCategoryGUI.
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...
setObject(int $a_obj_id, string $a_obj_type, ?int $a_sub_obj_id=0, ?string $a_sub_obj_type="")
Set Object.
getUnsafeGetCommands()
This method must return a list of unsafe GET commands.
setCtrlPath(array $a_value)
getBlockHTML(string $a_title)
executeCommand()
execute command
getSafePostCommands()
This method must return a list of safe POST commands.
getHTML(bool $a_show_overall=true, bool $a_may_rate=true, ?string $a_onclick=null, ?string $a_additional_id=null)
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)
setUpdateCallback($a_callback)
setYourRatingText(string $a_val)
getListGUIProperty(int $a_ref_id, bool $a_may_rate, string $a_ajax_hash, int $parent_ref_id)
getTooltipTopics(int $cnt=0, float $avg=0, int $user=0)
setExportCallback($a_callback, string $a_subobj_title)
enableCategories(bool $a_value)
string $export_subobj_title
static getNumberOfFinishedCategoryRatingsForWikis(int $a_obj_id, int $sub_obj_id, string $sub_obj_type, array $all_category_ids)
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.
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 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.
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.
special template class to simplify handling of ITX/PEAR
static getImagePath(string $image_name, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
return['delivery_method'=> 'php',]
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...
if(! $DIC->user() ->getId()||!ilLTIConsumerAccess::hasCustomProviderCreationAccess()) $params