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
337
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) {
348 $this->obj_id,
349 $this->obj_type,
350 $this->sub_obj_id,
351 $this->sub_obj_type,
353 $category["id"]
354 ));
355
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",
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",
382 );
383 $star_tpl->setVariable('RATING_FRACTION', 10);
384 } elseif ($overall_rating["avg"] + 1 <= $i) {
385 $star_tpl->setVariable(
386 "SRC_ICON",
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",
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
416
417 }
418 if ($add_tooltip) {
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
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
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)