ILIAS  trunk Revision v12.0_alpha-1221-g4e438232683
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 666 of file class.ilRatingGUI.php.

666 : string
667 {
668 $ui = $this->ui;
669
670 $categories = array();
671 if ($this->enable_categories) {
672 $categories = ilRatingCategory::getAllForObject($this->obj_id);
673 }
674
675 $may_rate = ($this->getUserId() != ANONYMOUS_USER_ID);
676
677
678 $panel = $ui->factory()->panel()->secondary()->legacy(
679 $a_title,
680 $ui->factory()->legacy()->content(
681 $this->renderDetails("rtsb_", $may_rate, $categories, null, true, true)
682 )
683 );
684
685 return $ui->renderer()->render($panel);
686 }
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 486 of file class.ilRatingGUI.php.

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

766 : string {
767 return $this->getHTML(
768 true,
769 $a_may_rate,
770 "il.Object.saveRatingFromListGUI(" . $a_ref_id . ", '" . $a_ajax_hash . "', %rating%);",
771 $parent_ref_id
772 );
773 }
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 641 of file class.ilRatingGUI.php.

645 : array {
646 $topics = [];
648
649 if ($cnt == 0) {
650 $topics[] = $lng->txt("rat_not_rated_yet");
651 } else {
652 if ($cnt == 1) {
653 $topics[] = $lng->txt("rat_one_rating");
654 } else {
655 $topics[] = sprintf($lng->txt("rat_nr_ratings"), $cnt);
656 }
657 $topics[] = $lng->txt("rating_avg_rating") . ": " . round($avg, 1);
658 }
659
660 if ($user > 0) {
661 $topics[] = $lng->txt("rating_personal_rating") . ": " . $user;
662 }
663 return $topics;
664 }

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
337 // Collect all category IDs
338 $category_ids = array_column($a_categories, "id");
340 $this->obj_id,
341 $this->sub_obj_id,
342 $this->sub_obj_type,
343 $category_ids
344 );
345
346 foreach ($a_categories as $category) {
347 $user_rating = round(ilRating::getRatingForUserAndObject(
348 $this->obj_id,
349 $this->obj_type,
350 $this->sub_obj_id,
351 $this->sub_obj_type,
352 $this->getUserId(),
353 $category["id"]
354 ));
355
356 $overall_rating = ilRating::getOverallRatingForObject(
357 $this->obj_id,
358 $this->obj_type,
359 $this->sub_obj_id,
360 $this->sub_obj_type,
361 $category["id"]
362 );
363
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;
368
369 $star_tpl->setCurrentBlock("rating_mark");
370 $star_tpl->setVariable(
371 "SRC_MARK",
372 ilUtil::getImagePath("standard/icon_rate_marker.svg")
373 );
374 $star_tpl->parseCurrentBlock();
375 }
376
377 $ttpl->setCurrentBlock("user_rating_icon");
378 if ($overall_rating["avg"] >= $i) {
379 $star_tpl->setVariable(
380 "SRC_ICON",
381 ilUtil::getImagePath("standard/icon_rate_on.svg")
382 );
383 $star_tpl->setVariable('RATING_FRACTION', 10);
384 } elseif ($overall_rating["avg"] + 1 <= $i) {
385 $star_tpl->setVariable(
386 "SRC_ICON",
387 ilUtil::getImagePath("standard/icon_rate_off.svg")
388 );
389 $star_tpl->setVariable('RATING_FRACTION', 0);
390 } else {
391 $nr = round(($overall_rating["avg"] + 1 - $i) * 10);
392 $star_tpl->setVariable(
393 "SRC_ICON",
394 ilUtil::getImagePath("standard/icon_rate_$nr.svg")
395 );
396 $star_tpl->setVariable("RATING_FRACTION", $nr);
397 }
398 $star_tpl->setVariable(
399 "ALT_ICON",
400 sprintf($lng->txt("rating_rate_x_of_5"), $i)
401 );
402
403 $b = $f->button()->shy("###star###", "#");
404 if ($a_may_rate) {
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) {
410 return
411 "$('#" . $id . "').click(function() { il.Rating.setValue(" . $category["id"] . "," . $i . ", '" . $a_js_id . "'); return false;});";
412 });
413
414 /*
415 $ttpl->setVariable("ICON_MOUSEACTION", " onmouseover=\"il.Rating.toggleIcon(this," . $i . ")\"" .
416 " onmouseout=\"il.Rating.toggleIcon(this," . $i . ",1)\"");*/
417 }
418 if ($add_tooltip) {
419 $topics = $this->getTooltipTopics(
420 (int) ($overall_rating["cnt"] ?? 0),
421 (float) ($overall_rating["avg"] ?? 0),
422 (int) ($user_rating ?? 0)
423 );
424 $b = $b->withHelpTopics(...$f->helpTopics(...$topics));
425 }
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();
430 }
431
432 if ($a_may_rate) {
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();
438 }
439
440
441 // category title
442 $ttpl->setCurrentBlock("user_rating_category");
443 $ttpl->setVariable("TXT_RATING_CATEGORY", $category["title"]);
444 $ttpl->parseCurrentBlock();
445 }
446
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();
451 }
452
453 if ($a_may_rate) {
454 // remove
455 if ($has_user_rating) {
456 $ttpl->setCurrentBlock("user_rating_categories_del_bl");
457 $ttpl->setVariable("CAPTION_RATING_DEL_CAT", $lng->txt("rating_remove"));
458
459 $ilCtrl->setParameter($this, "rating", 0);
460 if (!$this->ctrl_path) {
461 $url_save = $ilCtrl->getLinkTarget($this, "resetUserRating");
462 } else {
463 $url_save = $ilCtrl->getLinkTargetByClass($this->ctrl_path, "resetUserRating");
464 }
465 $ttpl->setVariable("HREF_RATING_DEL_CAT", $url_save);
466
467 $ttpl->parseCurrentBlock();
468 }
469
470 if (!$this->ctrl_path) {
471 $url_form = $ilCtrl->getFormAction($this, "saveRating");
472 } else {
473 $url_form = $ilCtrl->getFormActionByClass($this->ctrl_path, "saveRating");
474 }
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");
479 }
480 }
481
482 return $ttpl->get();
483 }
static getNumberOfFinishedCategoryRatingsForWikis(int $a_obj_id, int $sub_obj_id, string $sub_obj_type, array $all_category_ids)

◆ resetUserRating()

ilRatingGUI::resetUserRating ( )

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

743 : void
744 {
746 $this->obj_id,
747 $this->obj_type,
748 (int) $this->sub_obj_id,
749 $this->sub_obj_type,
750 $this->getUserId()
751 );
752 }
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 691 of file class.ilRatingGUI.php.

691 : void
692 {
693 $ilCtrl = $this->ctrl;
694
695 if (!is_array($this->requested_ratings)) {
696 $rating = $this->requested_rating;
697 if ($rating == 0) {
698 $this->resetUserRating();
699 } else {
701 $this->obj_id,
702 $this->obj_type,
703 $this->sub_obj_id,
704 $this->sub_obj_type,
705 $this->getUserId(),
706 $rating
707 );
708 }
709 } else {
710 foreach ($this->requested_ratings as $cat_id => $rating) {
712 $this->obj_id,
713 $this->obj_type,
714 $this->sub_obj_id,
715 $this->sub_obj_type,
716 $this->getUserId(),
717 $rating,
718 $cat_id
719 );
720 }
721 }
722
723 if ($this->update_callback) {
724 call_user_func(
725 $this->update_callback,
726 $this->obj_id,
727 $this->obj_type,
728 $this->sub_obj_id,
729 $this->sub_obj_type
730 );
731 }
732
733 if ($ilCtrl->isAsynch()) {
734 exit();
735 }
736 }
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 754 of file class.ilRatingGUI.php.

754 : void
755 {
756 $this->export_callback = $a_callback;
757 $this->export_subobj_title = $a_subobj_title;
758 }

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

738 : void
739 {
740 $this->update_callback = $a_callback;
741 }

◆ 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: