174 : string {
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;
186 :
$lng->
txt(
"rating_your_rating");
187 }
188
189
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,
198 0
199 );
200 $overall_rating = [
201 "avg" => 0,
202 "cnt" => 0
203 ];
204 if ($a_average) {
206 $this->obj_id,
207 $this->obj_type,
208 $this->sub_obj_id,
209 $this->sub_obj_type
210 );
211 }
212
213
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",
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",
257 );
258 } else {
259 $star_tpl->setVariable(
260 "SRC_ICON",
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) {
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
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
325 $ttpl->setCurrentBlock("user_rating_simple");
326 $ttpl->parseCurrentBlock();
327 }
328 }
329
330 else {
331 $has_user_rating = false;
332 $overall_rating = [
333 "avg" => 0,
334 "cnt" => 0
335 ];
336 foreach ($a_categories as $category) {
338 $this->obj_id,
339 $this->obj_type,
340 $this->sub_obj_id,
341 $this->sub_obj_type,
343 $category["id"]
344 ));
345
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",
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",
372 );
373 $star_tpl->setVariable('RATING_FRACTION', 10);
374 } elseif ($overall_rating["avg"] + 1 <= $i) {
375 $star_tpl->setVariable(
376 "SRC_ICON",
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",
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
406
407 }
408 if ($add_tooltip) {
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
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
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 }