174 : string {
177
178 $ttpl =
new ilTemplate(
"tpl.rating_details.html",
true,
true,
"Services/Rating");
179
180 $rate_text = null;
184 :
$lng->txt(
"rating_your_rating");
185 }
186
187
188 if (!$a_categories) {
189 if ($a_may_rate) {
191 $this->obj_id,
192 $this->obj_type,
193 $this->sub_obj_id,
194 $this->sub_obj_type,
196 0
197 );
198 $overall_rating = [
199 "avg" => 0,
200 "cnt" => 0
201 ];
202 if ($a_average) {
204 $this->obj_id,
205 $this->obj_type,
206 $this->sub_obj_id,
207 $this->sub_obj_type
208 );
209 }
210
211
212 for (
$i = 1;
$i <= 5;
$i++) {
213 if ($a_average &&
215 $ttpl->setCurrentBlock("rating_mark_simple");
216 $ttpl->setVariable(
217 "SRC_MARK_SIMPLE",
219 );
220 $ttpl->parseCurrentBlock();
221 }
222
223 $ttpl->setCurrentBlock("rating_link_simple");
224 if (stristr($a_onclick, "%rating%")) {
225 $url_save = "#";
226 } else {
227 $ilCtrl->setParameter($this,
"rating",
$i);
228 if (!$this->ctrl_path) {
229 $url_save = $ilCtrl->getLinkTarget($this, "saveRating");
230 } else {
231 $url_save = $ilCtrl->getLinkTargetByClass($this->ctrl_path, "saveRating");
232 }
233 }
234 $ttpl->setVariable("HREF_RATING", $url_save);
235
236 if ($a_onclick) {
237 $onclick = str_replace(
"%rating%",
$i, $a_onclick);
238 $ttpl->setVariable("ONCLICK_RATING", ' onclick="' . $onclick . '"');
239 }
240
241 if ($a_average) {
242 $ref_rating = $overall_rating["avg"];
243 } else {
244 $ref_rating = $rating;
245 }
246
247 if ($ref_rating >=
$i) {
248 $ttpl->setVariable(
249 "SRC_ICON",
251 );
252 } else {
253 $ttpl->setVariable(
254 "SRC_ICON",
256 );
257 }
258 $ttpl->setVariable(
259 "ALT_ICON",
260 sprintf(
$lng->txt(
"rating_rate_x_of_5"),
$i)
261 );
262 $ttpl->parseCurrentBlock();
263 }
264
265
266 if ($rating) {
267 $ttpl->setCurrentBlock("rating_simple_del_bl");
268 $ttpl->setVariable(
"CAPTION_RATING_DEL",
$lng->txt(
"rating_remove"));
269
270 if (stristr($a_onclick, "%rating%")) {
271 $url_save = "#";
272 } else {
273 $ilCtrl->setParameter($this, "rating", 0);
274 if (!$this->ctrl_path) {
275 $url_save = $ilCtrl->getLinkTarget($this, "saveRating");
276 } else {
277 $url_save = $ilCtrl->getLinkTargetByClass($this->ctrl_path, "saveRating");
278 }
279 }
280 $ttpl->setVariable("HREF_RATING_DEL", $url_save);
281
282 if ($a_onclick) {
283 $onclick = str_replace("%rating%", 0, $a_onclick);
284 $ttpl->setVariable("ONCLICK_RATING_DEL", ' onclick="' . $onclick . '"');
285 }
286
287 $ttpl->parseCurrentBlock();
288 }
289
290 if ($rate_text) {
291 $ttpl->setCurrentBlock("rating_simple_title");
292 $ttpl->setVariable("TXT_RATING_SIMPLE", $rate_text);
293 $ttpl->parseCurrentBlock();
294 }
295
296 if ($a_average &&
297 $overall_rating["cnt"]) {
298 $ttpl->setCurrentBlock("number_votes_simple");
299 $ttpl->setVariable("NUMBER_VOTES_SIMPLE", $overall_rating["cnt"]);
300 $ttpl->parseCurrentBlock();
301 }
302
303 if ($add_tooltip) {
304 $unique_id = $this->id . "_block";
305 $ttpl->setVariable("TTID", $unique_id);
307 $unique_id,
308 (int) ($overall_rating["cnt"] ?? 0),
309 (float) ($overall_rating["avg"] ?? 0),
310 (int) ($rating ?? 0)
311 );
312 }
313
314
315 $ttpl->setCurrentBlock("user_rating_simple");
316 $ttpl->parseCurrentBlock();
317 }
318 }
319
320 else {
321 $has_user_rating = false;
322 $overall_rating = [
323 "avg" => 0,
324 "cnt" => 0
325 ];
326 foreach ($a_categories as $category) {
328 $this->obj_id,
329 $this->obj_type,
330 $this->sub_obj_id,
331 $this->sub_obj_type,
333 $category["id"]
334 ));
335
337 $this->obj_id,
338 $this->obj_type,
339 $this->sub_obj_id,
340 $this->sub_obj_type,
341 $category["id"]
342 );
343
344 for (
$i = 1;
$i <= 5;
$i++) {
345 if ($a_may_rate &&
$i == $user_rating) {
346 $has_user_rating = true;
347
348 $ttpl->setCurrentBlock("rating_mark");
349 $ttpl->setVariable(
350 "SRC_MARK",
352 );
353 $ttpl->parseCurrentBlock();
354 }
355
356 $ttpl->setCurrentBlock("user_rating_icon");
357 if ($overall_rating[
"avg"] >=
$i) {
358 $ttpl->setVariable(
359 "SRC_ICON",
361 );
362 } elseif ($overall_rating[
"avg"] + 1 <=
$i) {
363 $ttpl->setVariable(
364 "SRC_ICON",
366 );
367 } else {
368 $nr = round(($overall_rating[
"avg"] + 1 -
$i) * 10);
369 $ttpl->setVariable(
370 "SRC_ICON",
372 );
373 }
374 $ttpl->setVariable(
375 "ALT_ICON",
376 sprintf(
$lng->txt(
"rating_rate_x_of_5"),
$i)
377 );
378
379 if ($a_may_rate) {
380 $ttpl->setVariable(
"HREF_RATING",
"il.Rating.setValue(" . $category[
"id"] .
"," .
$i .
", '" . $a_js_id .
"')");
381 $ttpl->setVariable("CATEGORY_ID", $category["id"]);
382 $ttpl->setVariable(
"ICON_VALUE",
$i);
383 $ttpl->setVariable("JS_ID", $a_js_id);
384 $ttpl->setVariable(
"ICON_MOUSEACTION",
" onmouseover=\"il.Rating.toggleIcon(this," .
$i .
")\"" .
385 " onmouseout=\"il.Rating.toggleIcon(this," .
$i .
",1)\"");
386 }
387
388 $ttpl->parseCurrentBlock();
389 }
390
391 if ($a_may_rate) {
392 $ttpl->setCurrentBlock("user_rating_category_column");
393 $ttpl->setVariable("JS_ID", $a_js_id);
394 $ttpl->setVariable("CATEGORY_ID", $category["id"]);
395 $ttpl->setVariable("CATEGORY_VALUE", $user_rating);
396 if ($add_tooltip) {
397 $unique_id = $this->id . "_block_" . $category["id"];
398 $ttpl->setVariable("CAT_TTID", $unique_id);
400 $unique_id,
401 (int) ($overall_rating["cnt"] ?? 0),
402 (float) ($overall_rating["avg"] ?? 0),
403 (int) ($user_rating ?? 0)
404 );
405 }
406 $ttpl->parseCurrentBlock();
407 }
408
409
410
411 $ttpl->setCurrentBlock("user_rating_category");
412 $ttpl->setVariable("TXT_RATING_CATEGORY", $category["title"]);
413 $ttpl->parseCurrentBlock();
414 }
415
416 if ($overall_rating["cnt"] > 0) {
417 $ttpl->setCurrentBlock("votes_number_bl");
418 $ttpl->setVariable(
"NUMBER_VOTES", sprintf(
$lng->txt(
"rating_number_votes"), $overall_rating[
"cnt"]));
419 $ttpl->parseCurrentBlock();
420 }
421
422 if ($a_may_rate) {
423
424 if ($has_user_rating) {
425 $ttpl->setCurrentBlock("user_rating_categories_del_bl");
426 $ttpl->setVariable(
"CAPTION_RATING_DEL_CAT",
$lng->txt(
"rating_remove"));
427
428 $ilCtrl->setParameter($this, "rating", 0);
429 if (!$this->ctrl_path) {
430 $url_save = $ilCtrl->getLinkTarget($this, "resetUserRating");
431 } else {
432 $url_save = $ilCtrl->getLinkTargetByClass($this->ctrl_path, "resetUserRating");
433 }
434 $ttpl->setVariable("HREF_RATING_DEL_CAT", $url_save);
435
436 $ttpl->parseCurrentBlock();
437 }
438
439 if (!$this->ctrl_path) {
440 $url_form = $ilCtrl->getFormAction($this, "saveRating");
441 } else {
442 $url_form = $ilCtrl->getFormActionByClass($this->ctrl_path, "saveRating");
443 }
444 $ttpl->setVariable("FORM_ACTION", $url_form);
445 $ttpl->setVariable(
"TXT_SUBMIT",
$lng->txt(
"rating_overlay_submit"));
446 $ttpl->setVariable("CMD_SUBMIT", "saveRating");
447 $ttpl->touchBlock("user_rating_categories_form_out");
448 }
449 }
450
451 return $ttpl->get();
452 }