ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
ilRatingGUI Class Reference

Class ilRatingGUI. More...

+ Collaboration diagram for ilRatingGUI:

Public Member Functions

 __construct ()
executeCommand ()
 execute command
 setObject ($a_obj_id, $a_obj_type, $a_sub_obj_id=0, $a_sub_obj_type="")
 Set Object.
 setUserId ($a_userid)
 Set User ID.
 getUserId ()
 Get User ID.
 setYourRatingText ($a_val)
 Set "Your Rating" text.
 getYourRatingText ()
 Get "Your Rating" text.
 enableCategories ($a_value)
 Toggle categories status.
 setCtrlPath (array $a_value)
 ilCtrl path
 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)
 getBlockHTML ($a_title)
 saveRating ()
 Save Rating.
 setUpdateCallback ($a_callback)
 resetUserRating ()
 Reset Rating.
 setExportCallback ($a_callback, $a_subobj_title)
 getListGUIProperty ($a_ref_id, $a_may_rate, $a_ajax_hash, $_parent_ref_id)
 Build list gui property for object.

Protected Member Functions

 renderDetails ($a_js_id, $a_may_rate, array $a_categories=null, $a_onclick=null, $a_average=false)
 Render rating details.

Protected Attributes

 $id = "rtg_"
 $export_callback
 $export_subobj_title
 $ctrl_path

Detailed Description

Class ilRatingGUI.

User interface class for rating.

Author
Alex Killing alex..nosp@m.kill.nosp@m.ing@g.nosp@m.mx.d.nosp@m.e
Version
$Id$

ilRatingGUI: ilRatingCategoryGUI

Definition at line 17 of file class.ilRatingGUI.php.

Constructor & Destructor Documentation

ilRatingGUI::__construct ( )

Definition at line 24 of file class.ilRatingGUI.php.

References $lng.

{
global $lng;
$lng->loadLanguageModule("rating");
}

Member Function Documentation

ilRatingGUI::enableCategories (   $a_value)

Toggle categories status.

Parameters
bool$a_value

Definition at line 128 of file class.ilRatingGUI.php.

{
$this->enable_categories = (bool)$a_value;
}
& ilRatingGUI::executeCommand ( )

execute command

Definition at line 34 of file class.ilRatingGUI.php.

References $cmd, and $ilCtrl.

{
global $ilCtrl;
$next_class = $ilCtrl->getNextClass($this);
$cmd = $ilCtrl->getCmd();
switch($next_class)
{
case "ilratingcategorygui":
include_once("./Services/Rating/classes/class.ilRatingCategoryGUI.php");
$gui = new ilRatingCategoryGUI($this->obj_id, $this->export_callback, $this->export_subobj_title);
$ilCtrl->forwardCommand($gui);
break;
default:
return $this->$cmd();
break;
}
}
ilRatingGUI::getBlockHTML (   $a_title)

Definition at line 569 of file class.ilRatingGUI.php.

References ilRatingCategory\getAllForObject(), getUserId(), and renderDetails().

{
$categories = array();
if($this->enable_categories)
{
$categories = ilRatingCategory::getAllForObject($this->obj_id);
}
$may_rate = ($this->getUserId() != ANONYMOUS_USER_ID);
$ttpl = new ilTemplate("tpl.rating_block.html", true, true, "Services/Rating");
$ttpl->setVariable("TITLE", $a_title);
$ttpl->setVariable("RATING_DETAILS",
$this->renderDetails("rtsb_", $may_rate, $categories, null, true));
return $ttpl->get();
}

+ Here is the call graph for this function:

ilRatingGUI::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)

Parameters
bool$a_show_overall
bool$a_may_rate
string$a_onclick
string$a_additional_id
Returns
string

Definition at line 427 of file class.ilRatingGUI.php.

References $id, $lng, ilTooltipGUI\addTooltip(), ilRatingCategory\getAllForObject(), ilUtil\getImagePath(), ilRating\getOverallRatingForObject(), ilRating\getRatingForUserAndObject(), getUserId(), and renderDetails().

Referenced by getListGUIProperty().

{
global $lng;
$unique_id = $this->id;
if($a_additional_id)
{
$unique_id .= "_".$a_additional_id;
}
$categories = array();
if($this->enable_categories)
{
$categories = ilRatingCategory::getAllForObject($this->obj_id);
}
$may_rate = ($this->getUserId() != ANONYMOUS_USER_ID);
if($may_rate && !$a_may_rate)
{
$may_rate = false;
}
$has_overlay = false;
if($may_rate || $categories)
{
$has_overlay = true;
}
$ttpl = new ilTemplate("tpl.rating_input.html", true, true, "Services/Rating");
// user rating
$user_rating = 0;
if ($may_rate || !$a_show_overall)
{
$user_rating = round(ilRating::getRatingForUserAndObject($this->obj_id, $this->obj_type,
$this->sub_obj_id, $this->sub_obj_type, $this->getUserId()));
}
// (1) overall rating
if($a_show_overall)
{
$rating = ilRating::getOverallRatingForObject($this->obj_id, $this->obj_type,
$this->sub_obj_id, $this->sub_obj_type);
}
else
{
$rating = array("avg"=>$user_rating);
}
for($i = 1; $i <= 5; $i++)
{
if ($a_show_overall &&
$i == $user_rating)
{
$ttpl->setCurrentBlock("rating_mark");
$ttpl->setVariable("SRC_MARK",
ilUtil::getImagePath("icon_rate_marker.svg"));
$ttpl->parseCurrentBlock();
}
$ttpl->setCurrentBlock("rating_icon");
if ($rating["avg"] >= $i)
{
$ttpl->setVariable("SRC_ICON",
ilUtil::getImagePath("icon_rate_on.svg"));
}
else if ($rating["avg"] + 1 <= $i)
{
$ttpl->setVariable("SRC_ICON",
ilUtil::getImagePath("icon_rate_off.svg"));
}
else
{
$nr = round(($rating["avg"] + 1 - $i) * 10);
$ttpl->setVariable("SRC_ICON",
ilUtil::getImagePath("icon_rate_$nr.svg"));
}
$ttpl->setVariable("ALT_ICON", "(".$i."/5)");
$ttpl->parseCurrentBlock();
}
$ttpl->setCurrentBlock("rating_icon");
if($a_show_overall)
{
if ($rating["cnt"] == 0)
{
$tt = $lng->txt("rat_not_rated_yet");
}
else if ($rating["cnt"] == 1)
{
$tt = $lng->txt("rat_one_rating");
}
else
{
$tt = sprintf($lng->txt("rat_nr_ratings"), $rating["cnt"]);
}
include_once("./Services/UIComponent/Tooltip/classes/class.ilTooltipGUI.php");
ilTooltipGUI::addTooltip($unique_id."_tt", $tt);
if ($rating["cnt"] > 0)
{
$ttpl->setCurrentBlock("rat_nr");
$ttpl->setVariable("RT_NR", $rating["cnt"]);
$ttpl->parseCurrentBlock();
}
}
// add overlay (trigger)
if ($has_overlay)
{
include_once("./Services/UIComponent/Overlay/classes/class.ilOverlayGUI.php");
$ov = new ilOverlayGUI($unique_id);
$ov->setTrigger("tr_".$unique_id, "click", "tr_".$unique_id);
$ov->add();
$ttpl->setCurrentBlock("act_rat_start");
$ttpl->setVariable("ID", $unique_id);
$ttpl->parseCurrentBlock();
$ttpl->touchBlock("act_rat_end");
}
$ttpl->parseCurrentBlock();
// (2) user rating
if($has_overlay)
{
$ttpl->setVariable("RATING_DETAILS",
$this->renderDetails("rtov_", $may_rate, $categories, $a_onclick));
$ttpl->setCurrentBlock("user_rating");
$ttpl->setVariable("ID", $unique_id);
$ttpl->parseCurrentBlock();
}
$ttpl->setVariable("TTID", $unique_id);
return $ttpl->get();
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilRatingGUI::getListGUIProperty (   $a_ref_id,
  $a_may_rate,
  $a_ajax_hash,
  $_parent_ref_id 
)

Build list gui property for object.

Parameters
int$a_ref_id
bool$a_may_rate
string$a_ajax_hash
int$_parent_ref_id
Returns
string

Definition at line 661 of file class.ilRatingGUI.php.

References getHTML().

{
return $this->getHTML(true, $a_may_rate,
"il.Object.saveRatingFromListGUI(".$a_ref_id.", '".$a_ajax_hash."', %rating%);",
$_parent_ref_id);
}

+ Here is the call graph for this function:

ilRatingGUI::getUserId ( )

Get User ID.

Returns
int User ID

Definition at line 98 of file class.ilRatingGUI.php.

Referenced by getBlockHTML(), getHTML(), renderDetails(), resetUserRating(), and saveRating().

{
return $this->userid;
}

+ Here is the caller graph for this function:

ilRatingGUI::getYourRatingText ( )

Get "Your Rating" text.

Returns
string text

Definition at line 118 of file class.ilRatingGUI.php.

Referenced by renderDetails().

{
return $this->your_rating_text;
}

+ Here is the caller graph for this function:

ilRatingGUI::renderDetails (   $a_js_id,
  $a_may_rate,
array  $a_categories = null,
  $a_onclick = null,
  $a_average = false 
)
protected

Render rating details.

Parameters
string$a_js_id
bool$a_may_rate
array$a_categories
bool$a_onclick
bool$a_average
Returns
string

Definition at line 153 of file class.ilRatingGUI.php.

References $ilCtrl, $lng, ilUtil\getImagePath(), ilRating\getOverallRatingForObject(), ilRating\getRatingForUserAndObject(), getUserId(), and getYourRatingText().

Referenced by getBlockHTML(), and getHTML().

{
global $lng, $ilCtrl;
$ttpl = new ilTemplate("tpl.rating_details.html", true, true, "Services/Rating");
$rate_text = null;
if($this->getYourRatingText() != "#")
{
$rate_text = ($this->getYourRatingText() != "")
? $this->getYourRatingText()
: $lng->txt("rating_your_rating");
}
// no categories: 1 simple rating (link)
if(!$a_categories)
{
if ($a_may_rate)
{
$rating = ilRating::getRatingForUserAndObject($this->obj_id, $this->obj_type,
$this->sub_obj_id, $this->sub_obj_type, $this->getUserId(), 0);
if((bool)$a_average)
{
$overall_rating = ilRating::getOverallRatingForObject($this->obj_id, $this->obj_type,
$this->sub_obj_id, $this->sub_obj_type);
}
// user rating links
for($i = 1; $i <= 5; $i++)
{
if ((bool)$a_average &&
$i == $rating)
{
$ttpl->setCurrentBlock("rating_mark_simple");
$ttpl->setVariable("SRC_MARK_SIMPLE",
ilUtil::getImagePath("icon_rate_marker.svg"));
$ttpl->parseCurrentBlock();
}
$ttpl->setCurrentBlock("rating_link_simple");
if(stristr($a_onclick, "%rating%"))
{
$url_save = "#";
}
else
{
$ilCtrl->setParameter($this, "rating", $i);
if(!$this->ctrl_path)
{
$url_save = $ilCtrl->getLinkTarget($this, "saveRating");
}
else
{
$url_save = $ilCtrl->getLinkTargetByClass($this->ctrl_path, "saveRating");
}
}
$ttpl->setVariable("HREF_RATING", $url_save);
if($a_onclick)
{
$onclick = str_replace("%rating%", $i, $a_onclick);
$ttpl->setVariable("ONCLICK_RATING", ' onclick="'.$onclick.'"');
}
if((bool)$a_average)
{
$ref_rating = $overall_rating["avg"];
}
else
{
$ref_rating = $rating;
}
if ($ref_rating >= $i)
{
$ttpl->setVariable("SRC_ICON",
ilUtil::getImagePath("icon_rate_on.svg"));
}
else
{
$ttpl->setVariable("SRC_ICON",
ilUtil::getImagePath("icon_rate_off.svg"));
}
$ttpl->setVariable("ALT_ICON", "(".$i."/5)");
$ttpl->parseCurrentBlock();
}
// remove
if($rating)
{
$ttpl->setCurrentBlock("rating_simple_del_bl");
$ttpl->setVariable("CAPTION_RATING_DEL", $lng->txt("rating_remove"));
if(stristr($a_onclick, "%rating%"))
{
$url_save = "#";
}
else
{
$ilCtrl->setParameter($this, "rating", 0);
if(!$this->ctrl_path)
{
$url_save = $ilCtrl->getLinkTarget($this, "saveRating");
}
else
{
$url_save = $ilCtrl->getLinkTargetByClass($this->ctrl_path, "saveRating");
}
}
$ttpl->setVariable("HREF_RATING_DEL", $url_save);
if($a_onclick)
{
$onclick = str_replace("%rating%", 0, $a_onclick);
$ttpl->setVariable("ONCLICK_RATING_DEL", ' onclick="'.$onclick.'"');
}
$ttpl->parseCurrentBlock();
}
if($rate_text)
{
$ttpl->setCurrentBlock("rating_simple_title");
$ttpl->setVariable("TXT_RATING_SIMPLE", $rate_text);
$ttpl->parseCurrentBlock();
}
// user rating text
$ttpl->setCurrentBlock("user_rating_simple");
if((bool)$a_average &&
$overall_rating["cnt"])
{
$ttpl->setVariable("NUMBER_VOTES_SIMPLE", $overall_rating["cnt"]);
}
$ttpl->parseCurrentBlock();
}
}
// categories: overall & user (form)
else
{
$has_user_rating = false;
foreach($a_categories as $category)
{
$user_rating = round(ilRating::getRatingForUserAndObject($this->obj_id, $this->obj_type,
$this->sub_obj_id, $this->sub_obj_type, $this->getUserId(), $category["id"]));
$overall_rating = ilRating::getOverallRatingForObject($this->obj_id, $this->obj_type,
$this->sub_obj_id, $this->sub_obj_type, $category["id"]);
for($i = 1; $i <= 5; $i++)
{
if ($a_may_rate && $i == $user_rating)
{
$has_user_rating = true;
$ttpl->setCurrentBlock("rating_mark");
$ttpl->setVariable("SRC_MARK",
ilUtil::getImagePath("icon_rate_marker.svg"));
$ttpl->parseCurrentBlock();
}
$ttpl->setCurrentBlock("user_rating_icon");
if ($overall_rating["avg"] >= $i)
{
$ttpl->setVariable("SRC_ICON",
ilUtil::getImagePath("icon_rate_on.svg"));
}
else if ($overall_rating["avg"] + 1 <= $i)
{
$ttpl->setVariable("SRC_ICON",
ilUtil::getImagePath("icon_rate_off.svg"));
}
else
{
$nr = round(($overall_rating["avg"] + 1 - $i) * 10);
$ttpl->setVariable("SRC_ICON",
ilUtil::getImagePath("icon_rate_$nr.svg"));
}
$ttpl->setVariable("ALT_ICON", "(".$i."/5)");
if ($a_may_rate)
{
$ttpl->setVariable("HREF_RATING", "il.Rating.setValue(".$category["id"].",".$i.", '".$a_js_id."')");
$ttpl->setVariable("CATEGORY_ID", $category["id"]);
$ttpl->setVariable("ICON_VALUE", $i);
$ttpl->setVariable("JS_ID", $a_js_id);
$ttpl->setVariable("ICON_MOUSEACTION", " onmouseover=\"il.Rating.toggleIcon(this,".$i.")\"".
" onmouseout=\"il.Rating.toggleIcon(this,".$i.",1)\"");
}
$ttpl->parseCurrentBlock();
}
if($a_may_rate)
{
$ttpl->setCurrentBlock("user_rating_category_column");
$ttpl->setVariable("JS_ID", $a_js_id);
$ttpl->setVariable("CATEGORY_ID", $category["id"]);
$ttpl->setVariable("CATEGORY_VALUE", $user_rating);
$ttpl->parseCurrentBlock();
}
// category title
$ttpl->setCurrentBlock("user_rating_category");
$ttpl->setVariable("TXT_RATING_CATEGORY", $category["title"]);
$ttpl->parseCurrentBlock();
}
if($overall_rating["cnt"])
{
$ttpl->setCurrentBlock("votes_number_bl");
$ttpl->setVariable("NUMBER_VOTES", sprintf($lng->txt("rating_number_votes"), $overall_rating["cnt"]));
$ttpl->parseCurrentBlock();
}
if($a_may_rate)
{
// remove
if($has_user_rating)
{
$ttpl->setCurrentBlock("user_rating_categories_del_bl");
$ttpl->setVariable("CAPTION_RATING_DEL_CAT", $lng->txt("rating_remove"));
$ilCtrl->setParameter($this, "rating", 0);
if(!$this->ctrl_path)
{
$url_save = $ilCtrl->getLinkTarget($this, "resetUserRating");
}
else
{
$url_save = $ilCtrl->getLinkTargetByClass($this->ctrl_path, "resetUserRating");
}
$ttpl->setVariable("HREF_RATING_DEL_CAT", $url_save);
$ttpl->parseCurrentBlock();
}
if(!$this->ctrl_path)
{
$url_form = $ilCtrl->getFormAction($this, "saveRating");
}
else
{
$url_form = $ilCtrl->getFormActionByClass($this->ctrl_path, "saveRating");
}
$ttpl->setVariable("FORM_ACTION", $url_form);
$ttpl->setVariable("TXT_SUBMIT", $lng->txt("rating_overlay_submit"));
$ttpl->setVariable("CMD_SUBMIT", "saveRating");
$ttpl->touchBlock("user_rating_categories_form_out");
// overall / user title
/*
$ttpl->setCurrentBlock("user_rating_categories");
$ttpl->setVariable("TXT_RATING_OVERALL", $lng->txt("rating_overlay_title_overall"));
$ttpl->parseCurrentBlock();
*/
}
}
return $ttpl->get();
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilRatingGUI::resetUserRating ( )

Reset Rating.

Definition at line 640 of file class.ilRatingGUI.php.

References getUserId(), and ilRating\resetRatingForUserAndObject().

Referenced by saveRating().

{
ilRating::resetRatingForUserAndObject($this->obj_id, $this->obj_type,
$this->sub_obj_id, $this->sub_obj_type, $this->getUserId());
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilRatingGUI::saveRating ( )

Save Rating.

Definition at line 592 of file class.ilRatingGUI.php.

References $_GET, $_POST, $_REQUEST, $ilCtrl, exit, getUserId(), resetUserRating(), ilUtil\stripSlashes(), and ilRating\writeRatingForUserAndObject().

{
global $ilCtrl;
if(!is_array($_REQUEST["rating"]))
{
$rating = (int)ilUtil::stripSlashes($_GET["rating"]);
if(!$rating)
{
$this->resetUserRating();
}
else
{
ilRating::writeRatingForUserAndObject($this->obj_id, $this->obj_type,
$this->sub_obj_id, $this->sub_obj_type, $this->getUserId(),
$rating);
}
}
else
{
foreach($_POST["rating"] as $cat_id => $rating)
{
ilRating::writeRatingForUserAndObject($this->obj_id, $this->obj_type,
$this->sub_obj_id, $this->sub_obj_type, $this->getUserId(),
$rating, $cat_id);
}
}
if($this->update_callback)
{
call_user_func($this->update_callback, $this->obj_id, $this->obj_type,
$this->sub_obj_id, $this->sub_obj_type);
}
if($ilCtrl->isAsynch())
{
exit();
}
}

+ Here is the call graph for this function:

ilRatingGUI::setCtrlPath ( array  $a_value)

ilCtrl path

Parameters
array$a_value

Definition at line 138 of file class.ilRatingGUI.php.

{
$this->ctrl_path = $a_value;
}
ilRatingGUI::setExportCallback (   $a_callback,
  $a_subobj_title 
)

Definition at line 646 of file class.ilRatingGUI.php.

{
$this->export_callback = $a_callback;
$this->export_subobj_title = $a_subobj_title;
}
ilRatingGUI::setObject (   $a_obj_id,
  $a_obj_type,
  $a_sub_obj_id = 0,
  $a_sub_obj_type = "" 
)

Set Object.

Parameters
int$a_obj_idObject ID
string$a_obj_typeObject Type
int$a_sub_obj_idSubobject ID
string$a_sub_obj_typeSubobject Type

Definition at line 63 of file class.ilRatingGUI.php.

References $ilUser, and setUserId().

{
global $ilUser;
// db-column is defined as not null, el stupido
if(!trim($a_sub_obj_type))
{
$a_sub_obj_type = "-";
}
$this->obj_id = $a_obj_id;
$this->obj_type = $a_obj_type;
$this->sub_obj_id = $a_sub_obj_id;
$this->sub_obj_type = $a_sub_obj_type;
$this->id = "rtg_".$this->obj_id."_".$this->obj_type."_".$this->sub_obj_id."_".
$this->sub_obj_type;
$this->setUserId($ilUser->getId());
}

+ Here is the call graph for this function:

ilRatingGUI::setUpdateCallback (   $a_callback)

Definition at line 632 of file class.ilRatingGUI.php.

{
$this->update_callback = $a_callback;
}
ilRatingGUI::setUserId (   $a_userid)

Set User ID.

Parameters
int$a_useridUser ID

Definition at line 88 of file class.ilRatingGUI.php.

Referenced by setObject().

{
$this->userid = $a_userid;
}

+ Here is the caller graph for this function:

ilRatingGUI::setYourRatingText (   $a_val)

Set "Your Rating" text.

Parameters
string$a_valtext

Definition at line 108 of file class.ilRatingGUI.php.

{
$this->your_rating_text = $a_val;
}

Field Documentation

ilRatingGUI::$ctrl_path
protected

Definition at line 22 of file class.ilRatingGUI.php.

ilRatingGUI::$export_callback
protected

Definition at line 20 of file class.ilRatingGUI.php.

ilRatingGUI::$export_subobj_title
protected

Definition at line 21 of file class.ilRatingGUI.php.

ilRatingGUI::$id = "rtg_"
protected

Definition at line 19 of file class.ilRatingGUI.php.

Referenced by getHTML().


The documentation for this class was generated from the following file: