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;
336 foreach ($a_categories as $category) {
354 for ($i = 1; $i <= 5; $i++) {
355 $star_tpl =
new ilTemplate(
"tpl.js_rating_star.html",
true,
true,
"components/ILIAS/Rating");
356 if ($a_may_rate && $i == $user_rating) {
357 $has_user_rating =
true;
359 $star_tpl->setCurrentBlock(
"rating_mark");
360 $star_tpl->setVariable(
364 $star_tpl->parseCurrentBlock();
367 $ttpl->setCurrentBlock(
"user_rating_icon");
368 if ($overall_rating[
"avg"] >= $i) {
369 $star_tpl->setVariable(
373 $star_tpl->setVariable(
'RATING_FRACTION', 10);
374 } elseif ($overall_rating[
"avg"] + 1 <= $i) {
375 $star_tpl->setVariable(
379 $star_tpl->setVariable(
'RATING_FRACTION', 0);
381 $nr = round(($overall_rating[
"avg"] + 1 - $i) * 10);
382 $star_tpl->setVariable(
386 $star_tpl->setVariable(
"RATING_FRACTION", $nr);
388 $star_tpl->setVariable(
390 sprintf(
$lng->txt(
"rating_rate_x_of_5"), $i)
393 $b =
$f->button()->shy(
"###star###",
"#");
395 $ttpl->setVariable(
"HREF_RATING",
"il.Rating.setValue(" . $category[
"id"] .
"," . $i .
", '" . $a_js_id .
"')");
396 $star_tpl->setVariable(
"CATEGORY_ID", $category[
"id"]);
397 $star_tpl->setVariable(
"ICON_VALUE", $i);
398 $star_tpl->setVariable(
"JS_ID", $a_js_id);
399 $b =
$b->withOnLoadCode(
function (
$id) use ($category, $i, $a_js_id) {
401 "$('#" .
$id .
"').click(function() { il.Rating.setValue(" . $category[
"id"] .
"," . $i .
", '" . $a_js_id .
"'); return false;});";
409 $topics = $this->getTooltipTopics(
410 (
int) ($overall_rating[
"cnt"] ?? 0),
411 (
float) ($overall_rating[
"avg"] ?? 0),
412 (
int) ($user_rating ?? 0)
414 $b =
$b->withHelpTopics(...
$f->helpTopics(...$topics));
416 $button_html = $r->render(
$b);
417 $button_html = str_replace(
"###star###", $star_tpl->get(), $button_html);
418 $ttpl->setVariable(
"RATE_BUTTON", $button_html);
419 $ttpl->parseCurrentBlock();
423 $ttpl->setCurrentBlock(
"user_rating_category_column");
424 $ttpl->setVariable(
"JS_ID", $a_js_id);
425 $ttpl->setVariable(
"CATEGORY_ID", $category[
"id"]);
426 $ttpl->setVariable(
"CATEGORY_VALUE", $user_rating);
427 $ttpl->parseCurrentBlock();
432 $ttpl->setCurrentBlock(
"user_rating_category");
433 $ttpl->setVariable(
"TXT_RATING_CATEGORY", $category[
"title"]);
434 $ttpl->parseCurrentBlock();
437 if ($overall_rating[
"cnt"] > 0) {
438 $ttpl->setCurrentBlock(
"votes_number_bl");
439 $ttpl->setVariable(
"NUMBER_VOTES", sprintf(
$lng->txt(
"rating_number_votes"), $overall_rating[
"cnt"]));
440 $ttpl->parseCurrentBlock();
445 if ($has_user_rating) {
446 $ttpl->setCurrentBlock(
"user_rating_categories_del_bl");
447 $ttpl->setVariable(
"CAPTION_RATING_DEL_CAT",
$lng->txt(
"rating_remove"));
449 $ilCtrl->setParameter($this,
"rating", 0);
450 if (!$this->ctrl_path) {
451 $url_save = $ilCtrl->getLinkTarget($this,
"resetUserRating");
453 $url_save = $ilCtrl->getLinkTargetByClass($this->ctrl_path,
"resetUserRating");
455 $ttpl->setVariable(
"HREF_RATING_DEL_CAT", $url_save);
457 $ttpl->parseCurrentBlock();
460 if (!$this->ctrl_path) {
461 $url_form = $ilCtrl->getFormAction($this,
"saveRating");
463 $url_form = $ilCtrl->getFormActionByClass($this->ctrl_path,
"saveRating");
465 $ttpl->setVariable(
"FORM_ACTION", $url_form);
466 $ttpl->setVariable(
"TXT_SUBMIT",
$lng->txt(
"rating_overlay_submit"));
467 $ttpl->setVariable(
"CMD_SUBMIT",
"saveRating");
468 $ttpl->touchBlock(
"user_rating_categories_form_out");
477 bool $a_show_overall =
true,
478 bool $a_may_rate =
true,
479 ?
string $a_onclick =
null,
480 ?
string $a_additional_id =
null
483 $r = $this->
ui->renderer();
486 if ($a_additional_id) {
487 $unique_id .=
"_" . $a_additional_id;
490 $categories = array();
491 if ($this->enable_categories) {
496 if ($may_rate && !$a_may_rate) {
500 $has_overlay =
false;
501 if ($may_rate || $categories) {
505 $ttpl =
new ilTemplate(
"tpl.rating_input.html",
true,
true,
"components/ILIAS/Rating");
509 if ($may_rate || !$a_show_overall) {
520 if ($a_show_overall) {
528 $rating = array(
"avg" => $user_rating);
531 for ($i = 1; $i <= 5; $i++) {
532 if ($a_show_overall &&
533 $i == $user_rating) {
534 $ttpl->setCurrentBlock(
"rating_mark");
539 $ttpl->parseCurrentBlock();
542 $ttpl->setCurrentBlock(
"rating_icon");
543 if ($rating[
"avg"] >= $i) {
548 } elseif ($rating[
"avg"] + 1 <= $i) {
554 $nr = round(($rating[
"avg"] + 1 - $i) * 10);
560 $ttpl->setVariable(
"ALT_ICON",
"");
561 $ttpl->parseCurrentBlock();
563 $ttpl->setCurrentBlock(
"rating_icon");
565 if ($a_show_overall) {
566 if ($rating[
"cnt"] > 0) {
567 $ttpl->setCurrentBlock(
"rat_nr");
568 $ttpl->setVariable(
"RT_NR", $rating[
"cnt"]);
569 $ttpl->parseCurrentBlock();
575 $ttpl->setCurrentBlock(
"act_rat_start");
576 $ttpl->setVariable(
"ID", $unique_id);
577 $ttpl->setVariable(
"TXT_OPEN_DIALOG",
$lng->txt(
"rating_open_dialog"));
578 $ttpl->parseCurrentBlock();
580 $ttpl->touchBlock(
"act_rat_end");
583 $ttpl->parseCurrentBlock();
588 $ttpl->setVariable(
"TTID", $unique_id);
589 $rating_html = $ttpl->get();
591 $tt_topics = $this->getTooltipTopics(
592 (
int) ($rating[
"cnt"] ?? 0),
593 (
float) ($rating[
"avg"] ?? 0),
594 (
int) ($user_rating ?? 0)
598 $button =
$f->button()->shy(
'###button###',
'#')
599 ->withOnLoadCode(
function (
string $id):
string {
600 return "document.getElementById('$id').classList.add('ilRating');";
605 $this->renderDetails(
"rtov_", $may_rate, $categories, $a_onclick)
608 $popover =
$f->popover()->standard(
609 $f->legacy()->content($this->renderDetails(
"rtov_", $may_rate, $categories, $a_onclick))
611 $button = $button->withOnClick($popover->getShowSignal());
612 $button = $button->withHelpTopics(
613 ...
$f->helpTopics(...$tt_topics)
615 $elements = [$popover, $button];
620 $button = $button->withHelpTopics(
621 ...
$f->helpTopics(...$tt_topics)
623 $elements = [$button];
625 $html = $r->render($elements);
626 $html = str_replace(
"###button###", $rating_html, $html);
645 $topics[] = sprintf(
$lng->txt(
"rat_nr_ratings"), $cnt);
647 $topics[] =
$lng->txt(
"rating_avg_rating") .
": " . round($avg, 1);
651 $topics[] =
$lng->txt(
"rating_personal_rating") .
": " . $user;
660 $categories = array();
661 if ($this->enable_categories) {
668 $panel = $ui->factory()->panel()->secondary()->legacy(
670 $ui->factory()->legacy()->content(
671 $this->renderDetails(
"rtsb_", $may_rate, $categories,
null,
true,
true)
675 return $ui->renderer()->render($panel);
683 $ilCtrl = $this->ctrl;
685 if (!is_array($this->requested_ratings)) {
686 $rating = $this->requested_rating;
688 $this->resetUserRating();
700 foreach ($this->requested_ratings as $cat_id => $rating) {
713 if ($this->update_callback) {
715 $this->update_callback,
723 if ($ilCtrl->isAsynch()) {
730 $this->update_callback = $a_callback;
738 (
int) $this->sub_obj_id,
746 $this->export_callback = $a_callback;
747 $this->export_subobj_title = $a_subobj_title;
760 "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 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