4 include_once(
"./Services/Rating/classes/class.ilRating.php");
5 include_once(
"./Services/Rating/classes/class.ilRatingCategory.php");
19 protected $id =
"rtg_";
28 $lng->loadLanguageModule(
"rating");
38 $next_class = $ilCtrl->getNextClass($this);
39 $cmd = $ilCtrl->getCmd();
43 case "ilratingcategorygui":
44 include_once(
"./Services/Rating/classes/class.ilRatingCategoryGUI.php");
45 $gui =
new ilRatingCategoryGUI($this->obj_id, $this->export_callback, $this->export_subobj_title);
46 $ilCtrl->forwardCommand($gui);
63 function setObject($a_obj_id, $a_obj_type, $a_sub_obj_id = 0, $a_sub_obj_type =
"")
68 if(!trim($a_sub_obj_type))
70 $a_sub_obj_type =
"-";
73 $this->obj_id = $a_obj_id;
74 $this->obj_type = $a_obj_type;
75 $this->sub_obj_id = $a_sub_obj_id;
76 $this->sub_obj_type = $a_sub_obj_type;
77 $this->
id =
"rtg_".$this->obj_id.
"_".$this->obj_type.
"_".$this->sub_obj_id.
"_".
90 $this->userid = $a_userid;
100 return $this->userid;
110 $this->your_rating_text = $a_val;
120 return $this->your_rating_text;
130 $this->enable_categories = (bool)$a_value;
140 $this->ctrl_path = $a_value;
153 protected function renderDetails($a_js_id, $a_may_rate, array $a_categories = null, $a_onclick = null, $a_average =
false)
157 $ttpl =
new ilTemplate(
"tpl.rating_details.html",
true,
true,
"Services/Rating");
164 : $lng->txt(
"rating_your_rating");
173 $this->sub_obj_id, $this->sub_obj_type, $this->
getUserId(), 0);
178 $this->sub_obj_id, $this->sub_obj_type);
182 for($i = 1; $i <= 5; $i++)
184 if ((
bool)$a_average &&
187 $ttpl->setCurrentBlock(
"rating_mark_simple");
188 $ttpl->setVariable(
"SRC_MARK_SIMPLE",
190 $ttpl->parseCurrentBlock();
193 $ttpl->setCurrentBlock(
"rating_link_simple");
194 if(stristr($a_onclick,
"%rating%"))
200 $ilCtrl->setParameter($this,
"rating", $i);
201 if(!$this->ctrl_path)
203 $url_save = $ilCtrl->getLinkTarget($this,
"saveRating");
207 $url_save = $ilCtrl->getLinkTargetByClass($this->ctrl_path,
"saveRating");
210 $ttpl->setVariable(
"HREF_RATING", $url_save);
214 $onclick = str_replace(
"%rating%", $i, $a_onclick);
215 $ttpl->setVariable(
"ONCLICK_RATING",
' onclick="'.$onclick.
'"');
220 $ref_rating = $overall_rating[
"avg"];
224 $ref_rating = $rating;
227 if ($ref_rating >= $i)
229 $ttpl->setVariable(
"SRC_ICON",
234 $ttpl->setVariable(
"SRC_ICON",
237 $ttpl->setVariable(
"ALT_ICON",
"(".$i.
"/5)");
238 $ttpl->parseCurrentBlock();
244 $ttpl->setCurrentBlock(
"rating_simple_del_bl");
245 $ttpl->setVariable(
"CAPTION_RATING_DEL", $lng->txt(
"rating_remove"));
247 if(stristr($a_onclick,
"%rating%"))
253 $ilCtrl->setParameter($this,
"rating", 0);
254 if(!$this->ctrl_path)
256 $url_save = $ilCtrl->getLinkTarget($this,
"saveRating");
260 $url_save = $ilCtrl->getLinkTargetByClass($this->ctrl_path,
"saveRating");
263 $ttpl->setVariable(
"HREF_RATING_DEL", $url_save);
267 $onclick = str_replace(
"%rating%", 0, $a_onclick);
268 $ttpl->setVariable(
"ONCLICK_RATING_DEL",
' onclick="'.$onclick.
'"');
271 $ttpl->parseCurrentBlock();
276 $ttpl->setCurrentBlock(
"rating_simple_title");
277 $ttpl->setVariable(
"TXT_RATING_SIMPLE", $rate_text);
278 $ttpl->parseCurrentBlock();
282 $ttpl->setCurrentBlock(
"user_rating_simple");
284 if((
bool)$a_average &&
285 $overall_rating[
"cnt"])
287 $ttpl->setVariable(
"NUMBER_VOTES_SIMPLE", $overall_rating[
"cnt"]);
290 $ttpl->parseCurrentBlock();
296 $has_user_rating =
false;
297 foreach($a_categories as $category)
300 $this->sub_obj_id, $this->sub_obj_type, $this->
getUserId(), $category[
"id"]));
303 $this->sub_obj_id, $this->sub_obj_type, $category[
"id"]);
305 for($i = 1; $i <= 5; $i++)
307 if ($a_may_rate && $i == $user_rating)
309 $has_user_rating =
true;
311 $ttpl->setCurrentBlock(
"rating_mark");
312 $ttpl->setVariable(
"SRC_MARK",
314 $ttpl->parseCurrentBlock();
317 $ttpl->setCurrentBlock(
"user_rating_icon");
318 if ($overall_rating[
"avg"] >= $i)
320 $ttpl->setVariable(
"SRC_ICON",
323 else if ($overall_rating[
"avg"] + 1 <= $i)
325 $ttpl->setVariable(
"SRC_ICON",
330 $nr = round(($overall_rating[
"avg"] + 1 - $i) * 10);
331 $ttpl->setVariable(
"SRC_ICON",
334 $ttpl->setVariable(
"ALT_ICON",
"(".$i.
"/5)");
338 $ttpl->setVariable(
"HREF_RATING",
"il.Rating.setValue(".$category[
"id"].
",".$i.
", '".$a_js_id.
"')");
339 $ttpl->setVariable(
"CATEGORY_ID", $category[
"id"]);
340 $ttpl->setVariable(
"ICON_VALUE", $i);
341 $ttpl->setVariable(
"JS_ID", $a_js_id);
342 $ttpl->setVariable(
"ICON_MOUSEACTION",
" onmouseover=\"il.Rating.toggleIcon(this,".$i.
")\"".
343 " onmouseout=\"il.Rating.toggleIcon(this,".$i.
",1)\"");
346 $ttpl->parseCurrentBlock();
351 $ttpl->setCurrentBlock(
"user_rating_category_column");
352 $ttpl->setVariable(
"JS_ID", $a_js_id);
353 $ttpl->setVariable(
"CATEGORY_ID", $category[
"id"]);
354 $ttpl->setVariable(
"CATEGORY_VALUE", $user_rating);
355 $ttpl->parseCurrentBlock();
359 $ttpl->setCurrentBlock(
"user_rating_category");
360 $ttpl->setVariable(
"TXT_RATING_CATEGORY", $category[
"title"]);
361 $ttpl->parseCurrentBlock();
364 if($overall_rating[
"cnt"])
366 $ttpl->setCurrentBlock(
"votes_number_bl");
367 $ttpl->setVariable(
"NUMBER_VOTES", sprintf($lng->txt(
"rating_number_votes"), $overall_rating[
"cnt"]));
368 $ttpl->parseCurrentBlock();
376 $ttpl->setCurrentBlock(
"user_rating_categories_del_bl");
377 $ttpl->setVariable(
"CAPTION_RATING_DEL_CAT", $lng->txt(
"rating_remove"));
379 $ilCtrl->setParameter($this,
"rating", 0);
380 if(!$this->ctrl_path)
382 $url_save = $ilCtrl->getLinkTarget($this,
"resetUserRating");
386 $url_save = $ilCtrl->getLinkTargetByClass($this->ctrl_path,
"resetUserRating");
388 $ttpl->setVariable(
"HREF_RATING_DEL_CAT", $url_save);
390 $ttpl->parseCurrentBlock();
393 if(!$this->ctrl_path)
395 $url_form = $ilCtrl->getFormAction($this,
"saveRating");
399 $url_form = $ilCtrl->getFormActionByClass($this->ctrl_path,
"saveRating");
401 $ttpl->setVariable(
"FORM_ACTION", $url_form);
402 $ttpl->setVariable(
"TXT_SUBMIT", $lng->txt(
"rating_overlay_submit"));
403 $ttpl->setVariable(
"CMD_SUBMIT",
"saveRating");
404 $ttpl->touchBlock(
"user_rating_categories_form_out");
427 function getHTML($a_show_overall =
true, $a_may_rate =
true, $a_onclick = null, $a_additional_id = null)
434 $unique_id .=
"_".$a_additional_id;
437 $categories = array();
438 if($this->enable_categories)
443 $may_rate = ($this->
getUserId() != ANONYMOUS_USER_ID);
444 if($may_rate && !$a_may_rate)
449 $has_overlay =
false;
450 if($may_rate || $categories)
455 $ttpl =
new ilTemplate(
"tpl.rating_input.html",
true,
true,
"Services/Rating");
459 if ($may_rate || !$a_show_overall)
462 $this->sub_obj_id, $this->sub_obj_type, $this->
getUserId()));
469 $this->sub_obj_id, $this->sub_obj_type);
473 $rating = array(
"avg"=>$user_rating);
476 for($i = 1; $i <= 5; $i++)
478 if ($a_show_overall &&
481 $ttpl->setCurrentBlock(
"rating_mark");
482 $ttpl->setVariable(
"SRC_MARK",
484 $ttpl->parseCurrentBlock();
487 $ttpl->setCurrentBlock(
"rating_icon");
488 if ($rating[
"avg"] >= $i)
490 $ttpl->setVariable(
"SRC_ICON",
493 else if ($rating[
"avg"] + 1 <= $i)
495 $ttpl->setVariable(
"SRC_ICON",
500 $nr = round(($rating[
"avg"] + 1 - $i) * 10);
501 $ttpl->setVariable(
"SRC_ICON",
504 $ttpl->setVariable(
"ALT_ICON",
"(".$i.
"/5)");
505 $ttpl->parseCurrentBlock();
507 $ttpl->setCurrentBlock(
"rating_icon");
511 if ($rating[
"cnt"] == 0)
513 $tt = $lng->txt(
"rat_not_rated_yet");
515 else if ($rating[
"cnt"] == 1)
517 $tt = $lng->txt(
"rat_one_rating");
521 $tt = sprintf($lng->txt(
"rat_nr_ratings"), $rating[
"cnt"]);
523 include_once(
"./Services/UIComponent/Tooltip/classes/class.ilTooltipGUI.php");
526 if ($rating[
"cnt"] > 0)
528 $ttpl->setCurrentBlock(
"rat_nr");
529 $ttpl->setVariable(
"RT_NR", $rating[
"cnt"]);
530 $ttpl->parseCurrentBlock();
537 include_once(
"./Services/UIComponent/Overlay/classes/class.ilOverlayGUI.php");
539 $ov->setTrigger(
"tr_".$unique_id,
"click",
"tr_".$unique_id);
542 $ttpl->setCurrentBlock(
"act_rat_start");
543 $ttpl->setVariable(
"ID", $unique_id);
545 $ttpl->parseCurrentBlock();
547 $ttpl->setCurrentBlock(
"act_rat_end");
549 $ttpl->parseCurrentBlock();
552 $ttpl->parseCurrentBlock();
559 $ttpl->setVariable(
"RATING_DETAILS",
560 $this->
renderDetails(
"rtov_", $may_rate, $categories, $a_onclick));
562 $ttpl->setCurrentBlock(
"user_rating");
563 $ttpl->setVariable(
"ID", $unique_id);
564 $ttpl->parseCurrentBlock();
567 $ttpl->setVariable(
"TTID", $unique_id);
574 $categories = array();
575 if($this->enable_categories)
580 $may_rate = ($this->
getUserId() != ANONYMOUS_USER_ID);
582 $ttpl =
new ilTemplate(
"tpl.rating_block.html",
true,
true,
"Services/Rating");
584 $ttpl->setVariable(
"TITLE", $a_title);
586 $ttpl->setVariable(
"RATING_DETAILS",
587 $this->
renderDetails(
"rtsb_", $may_rate, $categories, null,
true));
609 $this->sub_obj_id, $this->sub_obj_type, $this->
getUserId(),
615 foreach(
$_POST[
"rating"] as $cat_id => $rating)
618 $this->sub_obj_id, $this->sub_obj_type, $this->
getUserId(),
623 if($ilCtrl->isAsynch())
635 $this->sub_obj_id, $this->sub_obj_type, $this->
getUserId());
640 $this->export_callback = $a_callback;
641 $this->export_subobj_title = $a_subobj_title;
655 return $this->
getHTML(
true, $a_may_rate,
656 "il.Object.saveRatingFromListGUI(".$a_ref_id.
", '".$a_ajax_hash.
"', %rating%);",