ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilRatingGUI Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

+ Inheritance diagram for ilRatingGUI:
+ Collaboration diagram for ilRatingGUI:

Public Member Functions

 __construct ()
 
 executeCommand ()
 execute command More...
 
 getUnsafeGetCommands ()
 This method must return a list of unsafe GET commands. More...
 
 getSafePostCommands ()
 This method must return a list of safe POST commands. 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)
 
 getUnsafeGetCommands ()
 This method must return a list of unsafe GET commands. More...
 
 getSafePostCommands ()
 This method must return a list of safe POST commands. More...
 

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 @ilCtrl_Calls 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.

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'])) {
62 if (is_array($body['rating'])) {
63 $this->requested_ratings = ($body['rating'] ?? null);
64 } else {
65 $this->requested_rating = (int) ($body['rating'] ?? 0);
66 }
67 } else {
68 $this->requested_rating = (int) ($params['rating'] ?? 0);
69 }
70
71 $lng->loadLanguageModule("rating");
72 }
loadLanguageModule(string $a_module)
Load language module.
ilLanguage $lng
if(! $DIC->user() ->getId()||!ilLTIConsumerAccess::hasCustomProviderCreationAccess()) $params
Definition: ltiregstart.php:31
global $DIC
Definition: shib_login.php:26

References $DIC, $lng, $params, ILIAS\Repository\ctrl(), ILIAS\Repository\int(), ILIAS\Repository\lng(), ilLanguage\loadLanguageModule(), ILIAS\Repository\ui(), and ILIAS\Repository\user().

+ Here is the call graph for this function:

Member Function Documentation

◆ enableCategories()

ilRatingGUI::enableCategories ( bool  $a_value)

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

156 : void
157 {
158 $this->enable_categories = $a_value;
159 }

◆ executeCommand()

ilRatingGUI::executeCommand ( )

execute command

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

77 : void
78 {
79 $ilCtrl = $this->ctrl;
80
81 $next_class = $ilCtrl->getNextClass($this);
82 $cmd = $ilCtrl->getCmd();
83
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);
88 break;
89
90 default:
91 $this->$cmd();
92 break;
93 }
94 }
getNextClass($a_gui_class=null)
@inheritDoc
Class ilRatingCategoryGUI.

References $ctrl, and ilCtrl\getNextClass().

+ Here is the call graph for this function:

◆ getBlockHTML()

ilRatingGUI::getBlockHTML ( string  $a_title)

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

656 : string
657 {
658 $ui = $this->ui;
659
660 $categories = array();
661 if ($this->enable_categories) {
662 $categories = ilRatingCategory::getAllForObject($this->obj_id);
663 }
664
665 $may_rate = ($this->getUserId() != ANONYMOUS_USER_ID);
666
667
668 $panel = $ui->factory()->panel()->secondary()->legacy(
669 $a_title,
670 $ui->factory()->legacy()->content(
671 $this->renderDetails("rtsb_", $may_rate, $categories, null, true, true)
672 )
673 );
674
675 return $ui->renderer()->render($panel);
676 }
static getAllForObject(int $a_parent_obj_id)
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)
ILIAS DI UIServices $ui
const ANONYMOUS_USER_ID
Definition: constants.php:27

References ANONYMOUS_USER_ID, and ilRatingCategory\getAllForObject().

+ 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 476 of file class.ilRatingGUI.php.

481 : string {
482 $f = $this->ui->factory();
483 $r = $this->ui->renderer();
485 $unique_id = $this->id;
486 if ($a_additional_id) {
487 $unique_id .= "_" . $a_additional_id;
488 }
489
490 $categories = array();
491 if ($this->enable_categories) {
492 $categories = ilRatingCategory::getAllForObject($this->obj_id);
493 }
494
495 $may_rate = ($this->getUserId() != ANONYMOUS_USER_ID);
496 if ($may_rate && !$a_may_rate) {
497 $may_rate = false;
498 }
499
500 $has_overlay = false;
501 if ($may_rate || $categories) {
502 $has_overlay = true;
503 }
504
505 $ttpl = new ilTemplate("tpl.rating_input.html", true, true, "components/ILIAS/Rating");
506
507 // user rating
508 $user_rating = 0;
509 if ($may_rate || !$a_show_overall) {
510 $user_rating = round(ilRating::getRatingForUserAndObject(
511 $this->obj_id,
512 $this->obj_type,
513 $this->sub_obj_id,
514 $this->sub_obj_type,
515 $this->getUserId()
516 ));
517 }
518
519 // (1) overall rating
520 if ($a_show_overall) {
522 $this->obj_id,
523 $this->obj_type,
524 $this->sub_obj_id,
525 $this->sub_obj_type
526 );
527 } else {
528 $rating = array("avg" => $user_rating);
529 }
530
531 for ($i = 1; $i <= 5; $i++) {
532 if ($a_show_overall &&
533 $i == $user_rating) {
534 $ttpl->setCurrentBlock("rating_mark");
535 $ttpl->setVariable(
536 "SRC_MARK",
537 ilUtil::getImagePath("standard/icon_rate_marker.svg")
538 );
539 $ttpl->parseCurrentBlock();
540 }
541
542 $ttpl->setCurrentBlock("rating_icon");
543 if ($rating["avg"] >= $i) {
544 $ttpl->setVariable(
545 "SRC_ICON",
546 ilUtil::getImagePath("standard/icon_rate_on.svg")
547 );
548 } elseif ($rating["avg"] + 1 <= $i) {
549 $ttpl->setVariable(
550 "SRC_ICON",
551 ilUtil::getImagePath("standard/icon_rate_off.svg")
552 );
553 } else {
554 $nr = round(($rating["avg"] + 1 - $i) * 10);
555 $ttpl->setVariable(
556 "SRC_ICON",
557 ilUtil::getImagePath("standard/icon_rate_$nr.svg")
558 );
559 }
560 $ttpl->setVariable("ALT_ICON", "");
561 $ttpl->parseCurrentBlock();
562 }
563 $ttpl->setCurrentBlock("rating_icon");
564
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();
570 }
571 }
572
573 // add overlay (trigger)
574 if ($has_overlay) {
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();
579
580 $ttpl->touchBlock("act_rat_end");
581 }
582
583 $ttpl->parseCurrentBlock();
584
585
586 // (2) user rating
587
588 $ttpl->setVariable("TTID", $unique_id);
589 $rating_html = $ttpl->get();
590
591 $tt_topics = $this->getTooltipTopics(
592 (int) ($rating["cnt"] ?? 0),
593 (float) ($rating["avg"] ?? 0),
594 (int) ($user_rating ?? 0)
595 );
596
597
598 $button = $f->button()->shy('###button###', '#')
599 ->withOnLoadCode(function (string $id): string {
600 return "document.getElementById('$id').classList.add('ilRating');";
601 });
602 if ($has_overlay) {
603 $ttpl->setVariable(
604 "RATING_DETAILS",
605 $this->renderDetails("rtov_", $may_rate, $categories, $a_onclick)
606 );
607
608 $popover = $f->popover()->standard(
609 $f->legacy()->content($this->renderDetails("rtov_", $may_rate, $categories, $a_onclick))
610 );
611 $button = $button->withOnClick($popover->getShowSignal());
612 $button = $button->withHelpTopics(
613 ...$f->helpTopics(...$tt_topics)
614 );
615 $elements = [$popover, $button];
616 } else {
617 /*$button = $button->withOnLoadCode(function ($id) {
618 return "";
619 });*/
620 $button = $button->withHelpTopics(
621 ...$f->helpTopics(...$tt_topics)
622 );
623 $elements = [$button];
624 }
625 $html = $r->render($elements);
626 $html = str_replace("###button###", $rating_html, $html);
627
628 return $html;
629 }
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...
getTooltipTopics(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.
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)

◆ getListGUIProperty()

ilRatingGUI::getListGUIProperty ( int  $a_ref_id,
bool  $a_may_rate,
string  $a_ajax_hash,
int  $parent_ref_id 
)

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

756 : string {
757 return $this->getHTML(
758 true,
759 $a_may_rate,
760 "il.Object.saveRatingFromListGUI(" . $a_ref_id . ", '" . $a_ajax_hash . "', %rating%);",
761 $parent_ref_id
762 );
763 }
getHTML(bool $a_show_overall=true, bool $a_may_rate=true, ?string $a_onclick=null, ?string $a_additional_id=null)

◆ getSafePostCommands()

ilRatingGUI::getSafePostCommands ( )

This method must return a list of safe POST commands.

Safe post commands returned by this method will no longer be CSRF protected and will NOT be appended by an ilCtrlToken.

Returns
string[]

Implements ilCtrlSecurityInterface.

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

101 : array
102 {
103 return [];
104 }

◆ getTooltipTopics()

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

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

635 : array {
636 $topics = [];
638
639 if ($cnt == 0) {
640 $topics[] = $lng->txt("rat_not_rated_yet");
641 } else {
642 if ($cnt == 1) {
643 $topics[] = $lng->txt("rat_one_rating");
644 } else {
645 $topics[] = sprintf($lng->txt("rat_nr_ratings"), $cnt);
646 }
647 $topics[] = $lng->txt("rating_avg_rating") . ": " . round($avg, 1);
648 }
649
650 if ($user > 0) {
651 $topics[] = $lng->txt("rating_personal_rating") . ": " . $user;
652 }
653 return $topics;
654 }

References $lng, and ILIAS\GlobalScreen\Scope\$topics.

◆ getUnsafeGetCommands()

ilRatingGUI::getUnsafeGetCommands ( )

This method must return a list of unsafe GET commands.

Unsafe get commands returned by this method will now be CSRF protected, which means an ilCtrlToken is appended each time a link-target is generated to the class implementing this interface with a command from that list.

Tokens will be validated in

See also
ilCtrlInterface::getCmd(), whereas the fallback command will be used if the CSRF validation fails.
Returns
string[]

Implements ilCtrlSecurityInterface.

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

96 : array
97 {
98 return ['saveRating'];
99 }

◆ getUserId()

ilRatingGUI::getUserId ( )

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

141 : int
142 {
143 return $this->userid;
144 }

◆ getYourRatingText()

ilRatingGUI::getYourRatingText ( )

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

151 : string
152 {
154 }
string $your_rating_text

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

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

◆ resetUserRating()

ilRatingGUI::resetUserRating ( )

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

733 : void
734 {
736 $this->obj_id,
737 $this->obj_type,
738 (int) $this->sub_obj_id,
739 $this->sub_obj_type,
740 $this->getUserId()
741 );
742 }
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.

References ilRating\resetRatingForUserAndObject().

+ Here is the call graph for this function:

◆ saveRating()

ilRatingGUI::saveRating ( )

Save Rating.

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

681 : void
682 {
683 $ilCtrl = $this->ctrl;
684
685 if (!is_array($this->requested_ratings)) {
686 $rating = $this->requested_rating;
687 if ($rating == 0) {
688 $this->resetUserRating();
689 } else {
691 $this->obj_id,
692 $this->obj_type,
693 $this->sub_obj_id,
694 $this->sub_obj_type,
695 $this->getUserId(),
696 $rating
697 );
698 }
699 } else {
700 foreach ($this->requested_ratings as $cat_id => $rating) {
702 $this->obj_id,
703 $this->obj_type,
704 $this->sub_obj_id,
705 $this->sub_obj_type,
706 $this->getUserId(),
707 $rating,
708 $cat_id
709 );
710 }
711 }
712
713 if ($this->update_callback) {
714 call_user_func(
715 $this->update_callback,
716 $this->obj_id,
717 $this->obj_type,
718 $this->sub_obj_id,
719 $this->sub_obj_type
720 );
721 }
722
723 if ($ilCtrl->isAsynch()) {
724 exit();
725 }
726 }
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

References exit, and ilRating\writeRatingForUserAndObject().

+ Here is the call graph for this function:

◆ setCtrlPath()

ilRatingGUI::setCtrlPath ( array  $a_value)

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

161 : void
162 {
163 $this->ctrl_path = $a_value;
164 }

◆ setExportCallback()

ilRatingGUI::setExportCallback (   $a_callback,
string  $a_subobj_title 
)

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

744 : void
745 {
746 $this->export_callback = $a_callback;
747 $this->export_subobj_title = $a_subobj_title;
748 }

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

119 : void {
120 $ilUser = $this->user;
121
122 if (!trim((string) $a_sub_obj_type)) {
123 $a_sub_obj_type = "-";
124 }
125
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 . "_" .
132
133 $this->setUserId($ilUser->getId());
134 }
setUserId(int $a_userid)

◆ setUpdateCallback()

ilRatingGUI::setUpdateCallback (   $a_callback)

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

728 : void
729 {
730 $this->update_callback = $a_callback;
731 }

◆ setUserId()

ilRatingGUI::setUserId ( int  $a_userid)

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

136 : void
137 {
138 $this->userid = $a_userid;
139 }

◆ setYourRatingText()

ilRatingGUI::setYourRatingText ( string  $a_val)

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

146 : void
147 {
148 $this->your_rating_text = $a_val;
149 }

Field Documentation

◆ $ctrl

ilCtrl ilRatingGUI::$ctrl
protected

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

Referenced by executeCommand().

◆ $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.

◆ $lng

ilLanguage ilRatingGUI::$lng
protected

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

Referenced by __construct().

◆ $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.

◆ $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.

◆ $ui

ILIAS DI UIServices ilRatingGUI::$ui
protected

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

◆ $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.

◆ $userid

int ilRatingGUI::$userid
protected

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

◆ $your_rating_text

string ilRatingGUI::$your_rating_text = ""
protected

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


The documentation for this class was generated from the following file: