4 include_once(
"./Services/Rating/classes/class.ilRating.php");
5 include_once(
"./Services/Rating/classes/class.ilRatingCategory.php");
34 protected $id =
"rtg_";
43 $this->lng = $DIC->language();
44 $this->ctrl = $DIC->ctrl();
45 $this->
user = $DIC->user();
46 $lng = $DIC->language();
48 $lng->loadLanguageModule(
"rating");
58 $next_class =
$ilCtrl->getNextClass($this);
61 switch ($next_class) {
62 case "ilratingcategorygui":
63 include_once(
"./Services/Rating/classes/class.ilRatingCategoryGUI.php");
64 $gui =
new ilRatingCategoryGUI($this->obj_id, $this->export_callback, $this->export_subobj_title);
82 public function setObject($a_obj_id, $a_obj_type, $a_sub_obj_id = 0, $a_sub_obj_type =
"")
87 if (!trim($a_sub_obj_type)) {
88 $a_sub_obj_type =
"-";
91 $this->obj_id = $a_obj_id;
92 $this->obj_type = $a_obj_type;
93 $this->sub_obj_id = $a_sub_obj_id;
94 $this->sub_obj_type = $a_sub_obj_type;
95 $this->
id =
"rtg_" . $this->obj_id .
"_" . $this->obj_type .
"_" . $this->sub_obj_id .
"_" .
108 $this->userid = $a_userid;
128 $this->your_rating_text = $a_val;
138 return $this->your_rating_text;
148 $this->enable_categories = (bool) $a_value;
158 $this->ctrl_path = $a_value;
171 protected function renderDetails($a_js_id, $a_may_rate,
array $a_categories = null, $a_onclick = null, $a_average =
false)
176 $ttpl =
new ilTemplate(
"tpl.rating_details.html",
true,
true,
"Services/Rating");
182 :
$lng->txt(
"rating_your_rating");
186 if (!$a_categories) {
197 if ((
bool) $a_average) {
207 for (
$i = 1;
$i <= 5;
$i++) {
208 if ((
bool) $a_average &&
210 $ttpl->setCurrentBlock(
"rating_mark_simple");
215 $ttpl->parseCurrentBlock();
218 $ttpl->setCurrentBlock(
"rating_link_simple");
219 if (stristr($a_onclick,
"%rating%")) {
222 $ilCtrl->setParameter($this,
"rating",
$i);
223 if (!$this->ctrl_path) {
224 $url_save =
$ilCtrl->getLinkTarget($this,
"saveRating");
226 $url_save =
$ilCtrl->getLinkTargetByClass($this->ctrl_path,
"saveRating");
229 $ttpl->setVariable(
"HREF_RATING", $url_save);
232 $onclick = str_replace(
"%rating%",
$i, $a_onclick);
233 $ttpl->setVariable(
"ONCLICK_RATING",
' onclick="' . $onclick .
'"');
236 if ((
bool) $a_average) {
237 $ref_rating = $overall_rating[
"avg"];
239 $ref_rating = $rating;
242 if ($ref_rating >=
$i) {
253 $ttpl->setVariable(
"ALT_ICON",
"(" .
$i .
"/5)");
254 $ttpl->parseCurrentBlock();
259 $ttpl->setCurrentBlock(
"rating_simple_del_bl");
260 $ttpl->setVariable(
"CAPTION_RATING_DEL",
$lng->txt(
"rating_remove"));
262 if (stristr($a_onclick,
"%rating%")) {
265 $ilCtrl->setParameter($this,
"rating", 0);
266 if (!$this->ctrl_path) {
267 $url_save =
$ilCtrl->getLinkTarget($this,
"saveRating");
269 $url_save =
$ilCtrl->getLinkTargetByClass($this->ctrl_path,
"saveRating");
272 $ttpl->setVariable(
"HREF_RATING_DEL", $url_save);
275 $onclick = str_replace(
"%rating%", 0, $a_onclick);
276 $ttpl->setVariable(
"ONCLICK_RATING_DEL",
' onclick="' . $onclick .
'"');
279 $ttpl->parseCurrentBlock();
283 $ttpl->setCurrentBlock(
"rating_simple_title");
284 $ttpl->setVariable(
"TXT_RATING_SIMPLE", $rate_text);
285 $ttpl->parseCurrentBlock();
289 $ttpl->setCurrentBlock(
"user_rating_simple");
291 if ((
bool) $a_average &&
292 $overall_rating[
"cnt"]) {
293 $ttpl->setVariable(
"NUMBER_VOTES_SIMPLE", $overall_rating[
"cnt"]);
296 $ttpl->parseCurrentBlock();
301 $has_user_rating =
false;
302 foreach ($a_categories as $category) {
320 for (
$i = 1;
$i <= 5;
$i++) {
321 if ($a_may_rate &&
$i == $user_rating) {
322 $has_user_rating =
true;
324 $ttpl->setCurrentBlock(
"rating_mark");
329 $ttpl->parseCurrentBlock();
332 $ttpl->setCurrentBlock(
"user_rating_icon");
333 if ($overall_rating[
"avg"] >=
$i) {
338 } elseif ($overall_rating[
"avg"] + 1 <=
$i) {
344 $nr = round(($overall_rating[
"avg"] + 1 -
$i) * 10);
350 $ttpl->setVariable(
"ALT_ICON",
"(" .
$i .
"/5)");
353 $ttpl->setVariable(
"HREF_RATING",
"il.Rating.setValue(" . $category[
"id"] .
"," .
$i .
", '" . $a_js_id .
"')");
354 $ttpl->setVariable(
"CATEGORY_ID", $category[
"id"]);
355 $ttpl->setVariable(
"ICON_VALUE",
$i);
356 $ttpl->setVariable(
"JS_ID", $a_js_id);
357 $ttpl->setVariable(
"ICON_MOUSEACTION",
" onmouseover=\"il.Rating.toggleIcon(this," .
$i .
")\"" .
358 " onmouseout=\"il.Rating.toggleIcon(this," .
$i .
",1)\"");
361 $ttpl->parseCurrentBlock();
365 $ttpl->setCurrentBlock(
"user_rating_category_column");
366 $ttpl->setVariable(
"JS_ID", $a_js_id);
367 $ttpl->setVariable(
"CATEGORY_ID", $category[
"id"]);
368 $ttpl->setVariable(
"CATEGORY_VALUE", $user_rating);
369 $ttpl->parseCurrentBlock();
373 $ttpl->setCurrentBlock(
"user_rating_category");
374 $ttpl->setVariable(
"TXT_RATING_CATEGORY", $category[
"title"]);
375 $ttpl->parseCurrentBlock();
378 if ($overall_rating[
"cnt"]) {
379 $ttpl->setCurrentBlock(
"votes_number_bl");
380 $ttpl->setVariable(
"NUMBER_VOTES", sprintf(
$lng->txt(
"rating_number_votes"), $overall_rating[
"cnt"]));
381 $ttpl->parseCurrentBlock();
386 if ($has_user_rating) {
387 $ttpl->setCurrentBlock(
"user_rating_categories_del_bl");
388 $ttpl->setVariable(
"CAPTION_RATING_DEL_CAT",
$lng->txt(
"rating_remove"));
390 $ilCtrl->setParameter($this,
"rating", 0);
391 if (!$this->ctrl_path) {
392 $url_save =
$ilCtrl->getLinkTarget($this,
"resetUserRating");
394 $url_save =
$ilCtrl->getLinkTargetByClass($this->ctrl_path,
"resetUserRating");
396 $ttpl->setVariable(
"HREF_RATING_DEL_CAT", $url_save);
398 $ttpl->parseCurrentBlock();
401 if (!$this->ctrl_path) {
402 $url_form =
$ilCtrl->getFormAction($this,
"saveRating");
404 $url_form =
$ilCtrl->getFormActionByClass($this->ctrl_path,
"saveRating");
406 $ttpl->setVariable(
"FORM_ACTION", $url_form);
407 $ttpl->setVariable(
"TXT_SUBMIT",
$lng->txt(
"rating_overlay_submit"));
408 $ttpl->setVariable(
"CMD_SUBMIT",
"saveRating");
409 $ttpl->touchBlock(
"user_rating_categories_form_out");
432 public function getHTML($a_show_overall =
true, $a_may_rate =
true, $a_onclick = null, $a_additional_id = null)
437 if ($a_additional_id) {
438 $unique_id .=
"_" . $a_additional_id;
441 $categories =
array();
442 if ($this->enable_categories) {
446 $may_rate = ($this->
getUserId() != ANONYMOUS_USER_ID);
447 if ($may_rate && !$a_may_rate) {
451 $has_overlay =
false;
452 if ($may_rate || $categories) {
456 $ttpl =
new ilTemplate(
"tpl.rating_input.html",
true,
true,
"Services/Rating");
460 if ($may_rate || !$a_show_overall) {
471 if ($a_show_overall) {
479 $rating =
array(
"avg"=>$user_rating);
482 for (
$i = 1;
$i <= 5;
$i++) {
483 if ($a_show_overall &&
484 $i == $user_rating) {
485 $ttpl->setCurrentBlock(
"rating_mark");
490 $ttpl->parseCurrentBlock();
493 $ttpl->setCurrentBlock(
"rating_icon");
494 if ($rating[
"avg"] >=
$i) {
499 } elseif ($rating[
"avg"] + 1 <=
$i) {
505 $nr = round(($rating[
"avg"] + 1 -
$i) * 10);
511 $ttpl->setVariable(
"ALT_ICON",
"(" .
$i .
"/5)");
512 $ttpl->parseCurrentBlock();
514 $ttpl->setCurrentBlock(
"rating_icon");
516 if ($a_show_overall) {
517 if ($rating[
"cnt"] == 0) {
518 $tt =
$lng->txt(
"rat_not_rated_yet");
519 } elseif ($rating[
"cnt"] == 1) {
520 $tt =
$lng->txt(
"rat_one_rating");
522 $tt = sprintf(
$lng->txt(
"rat_nr_ratings"), $rating[
"cnt"]);
524 include_once(
"./Services/UIComponent/Tooltip/classes/class.ilTooltipGUI.php");
527 if ($rating[
"cnt"] > 0) {
528 $ttpl->setCurrentBlock(
"rat_nr");
529 $ttpl->setVariable(
"RT_NR", $rating[
"cnt"]);
530 $ttpl->parseCurrentBlock();
536 include_once(
"./Services/UIComponent/Overlay/classes/class.ilOverlayGUI.php");
538 $ov->setTrigger(
"tr_" . $unique_id,
"click",
"tr_" . $unique_id);
541 $ttpl->setCurrentBlock(
"act_rat_start");
542 $ttpl->setVariable(
"ID", $unique_id);
543 $ttpl->parseCurrentBlock();
545 $ttpl->touchBlock(
"act_rat_end");
548 $ttpl->parseCurrentBlock();
556 $this->
renderDetails(
"rtov_", $may_rate, $categories, $a_onclick)
559 $ttpl->setCurrentBlock(
"user_rating");
560 $ttpl->setVariable(
"ID", $unique_id);
561 $ttpl->parseCurrentBlock();
564 $ttpl->setVariable(
"TTID", $unique_id);
571 $categories =
array();
572 if ($this->enable_categories) {
576 $may_rate = ($this->
getUserId() != ANONYMOUS_USER_ID);
578 $ttpl =
new ilTemplate(
"tpl.rating_block.html",
true,
true,
"Services/Rating");
580 $ttpl->setVariable(
"TITLE", $a_title);
584 $this->
renderDetails(
"rtsb_", $may_rate, $categories, null,
true)
597 if (!is_array($_REQUEST[
"rating"])) {
612 foreach (
$_POST[
"rating"] as $cat_id => $rating) {
625 if ($this->update_callback) {
627 $this->update_callback,
642 $this->update_callback = $a_callback;
661 $this->export_callback = $a_callback;
662 $this->export_subobj_title = $a_subobj_title;
679 "il.Object.saveRatingFromListGUI(" . $a_ref_id .
", '" . $a_ajax_hash .
"', %rating%);",
static writeRatingForUserAndObject( $a_obj_id, $a_obj_type, $a_sub_obj_id, $a_sub_obj_type, $a_user_id, $a_rating, $a_category_id=0)
Write rating for a user and an object.
setYourRatingText($a_val)
Set "Your Rating" text.
resetUserRating()
Reset Rating.
setUpdateCallback($a_callback)
if(empty($userids)) $userid
setExportCallback($a_callback, $a_subobj_title)
renderDetails($a_js_id, $a_may_rate, array $a_categories=null, $a_onclick=null, $a_average=false)
Render rating details.
setUserId($a_userid)
Set User ID.
static getAllForObject($a_parent_obj_id)
Get all categories for object.
static getRatingForUserAndObject( $a_obj_id, $a_obj_type, $a_sub_obj_id, $a_sub_obj_type, $a_user_id, $a_category_id=null)
Get rating for a user and an object.
setCtrlPath(array $a_value)
ilCtrl path
Class ilRatingCategoryGUI.
getHTML($a_show_overall=true, $a_may_rate=true, $a_onclick=null, $a_additional_id=null)
Get HTML for rating of an object (and a user)
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
static resetRatingForUserAndObject( $a_obj_id, $a_obj_type, $a_sub_obj_id, $a_sub_obj_type, $a_user_id)
Reset rating for a user and an object.
getListGUIProperty($a_ref_id, $a_may_rate, $a_ajax_hash, $_parent_ref_id)
Build list gui property for object.
special template class to simplify handling of ITX/PEAR
setObject($a_obj_id, $a_obj_type, $a_sub_obj_id=0, $a_sub_obj_type="")
Set Object.
This is a utility class for the yui overlays.
getYourRatingText()
Get "Your Rating" text.
static getOverallRatingForObject($a_obj_id, $a_obj_type, $a_sub_obj_id=null, $a_sub_obj_type=null, $a_category_id=null)
Get overall rating for an object.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
Create styles array
The data for the language used.
executeCommand()
execute command
enableCategories($a_value)
Toggle categories status.