ILIAS  release_4-3 Revision
 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.
 getHTML ()
 Get HTML for rating of an object (and a user)
 getBlockHTML ($a_title)
 saveRating ()
 Save Rating.
 setExportCallback ($a_callback, $a_subobj_title)

Protected Member Functions

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

Protected Attributes

 $id = "rtg_"
 $export_callback
 $export_subobj_title

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 23 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 121 of file class.ilRatingGUI.php.

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

execute command

Definition at line 33 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 395 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));
return $ttpl->get();
}

+ Here is the call graph for this function:

ilRatingGUI::getHTML ( )

Get HTML for rating of an object (and a user)

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

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

{
global $lng;
$categories = array();
if($this->enable_categories)
{
$categories = ilRatingCategory::getAllForObject($this->obj_id);
}
$may_rate = ($this->getUserId() != ANONYMOUS_USER_ID);
$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)
{
$user_rating = round(ilRating::getRatingForUserAndObject($this->obj_id, $this->obj_type,
$this->sub_obj_id, $this->sub_obj_type, $this->getUserId()));
}
// (1) overall rating
$rating = ilRating::getOverallRatingForObject($this->obj_id, $this->obj_type,
$this->sub_obj_id, $this->sub_obj_type);
for($i = 1; $i <= 5; $i++)
{
if ($i == $user_rating)
{
$ttpl->setCurrentBlock("rating_mark");
$ttpl->setVariable("SRC_MARK",
ilUtil::getImagePath("icon_rate_marker.png"));
$ttpl->parseCurrentBlock();
}
$ttpl->setCurrentBlock("rating_icon");
if ($rating["avg"] >= $i)
{
$ttpl->setVariable("SRC_ICON",
ilUtil::getImagePath("icon_rate_on.png"));
}
else if ($rating["avg"] + 1 <= $i)
{
$ttpl->setVariable("SRC_ICON",
ilUtil::getImagePath("icon_rate_off.png"));
}
else
{
$nr = round(($rating["avg"] + 1 - $i) * 10);
$ttpl->setVariable("SRC_ICON",
ilUtil::getImagePath("icon_rate_$nr.png"));
}
$ttpl->setVariable("ALT_ICON", "(".$i."/5)");
$ttpl->parseCurrentBlock();
}
$ttpl->setCurrentBlock("rating_icon");
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($this->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($this->id);
$ov->setTrigger("tr_".$this->id, "click", "tr_".$this->id);
$ov->add();
$ttpl->setCurrentBlock("act_rat_start");
$ttpl->setVariable("ID", $this->id);
$ttpl->setVariable("SRC_ARROW", ilUtil::getImagePath("mm_down_arrow_dark.png"));
$ttpl->parseCurrentBlock();
$ttpl->setCurrentBlock("act_rat_end");
$ttpl->setVariable("SRC_ARROW", ilUtil::getImagePath("mm_down_arrow_dark.png"));
$ttpl->parseCurrentBlock();
}
$ttpl->parseCurrentBlock();
// (2) user rating
if($has_overlay)
{
$ttpl->setVariable("RATING_DETAILS",
$this->renderDetails("rtov_", $may_rate, $categories));
$ttpl->setCurrentBlock("user_rating");
$ttpl->setVariable("ID", $this->id);
$ttpl->parseCurrentBlock();
}
$ttpl->setVariable("TTID", $this->id);
return $ttpl->get();
}

+ Here is the call graph for this function:

ilRatingGUI::getUserId ( )

Get User ID.

Returns
int User ID

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

Referenced by getBlockHTML(), getHTML(), renderDetails(), 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 111 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 
)
protected

Render rating details.

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

Definition at line 134 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 = ($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);
// user rating links
for($i = 1; $i <= 5; $i++)
{
$ttpl->setCurrentBlock("rating_link_simple");
$ilCtrl->setParameter($this, "rating", $i);
$ttpl->setVariable("HREF_RATING", $ilCtrl->getLinkTarget($this, "saveRating"));
if ($rating >= $i)
{
$ttpl->setVariable("SRC_ICON",
ilUtil::getImagePath("icon_rate_on.png"));
}
else
{
$ttpl->setVariable("SRC_ICON",
ilUtil::getImagePath("icon_rate_off.png"));
}
$ttpl->setVariable("ALT_ICON", "(".$i."/5)");
$ttpl->parseCurrentBlock();
}
// user rating text
$ttpl->setCurrentBlock("user_rating_simple");
$ttpl->setVariable("TXT_RATING_SIMPLE", $rate_text);
$ttpl->parseCurrentBlock();
}
}
// categories: overall & user (form)
else
{
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)
{
$ttpl->setCurrentBlock("rating_mark");
$ttpl->setVariable("SRC_MARK",
ilUtil::getImagePath("icon_rate_marker.png"));
$ttpl->parseCurrentBlock();
}
$ttpl->setCurrentBlock("user_rating_icon");
if ($overall_rating["avg"] >= $i)
{
$ttpl->setVariable("SRC_ICON",
ilUtil::getImagePath("icon_rate_on.png"));
}
else if ($overall_rating["avg"] + 1 <= $i)
{
$ttpl->setVariable("SRC_ICON",
ilUtil::getImagePath("icon_rate_off.png"));
}
else
{
$nr = round(($overall_rating["avg"] + 1 - $i) * 10);
$ttpl->setVariable("SRC_ICON",
ilUtil::getImagePath("icon_rate_$nr.png"));
}
$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)
{
$ttpl->setVariable("FORM_ACTION", $ilCtrl->getFormAction($this, "saveRating"));
$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::saveRating ( )

Save Rating.

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

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

{
if(!is_array($_REQUEST["rating"]))
{
ilRating::writeRatingForUserAndObject($this->obj_id, $this->obj_type,
$this->sub_obj_id, $this->sub_obj_type, $this->getUserId(),
}
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);
}
}
}

+ Here is the call graph for this function:

ilRatingGUI::setExportCallback (   $a_callback,
  $a_subobj_title 
)

Definition at line 437 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 62 of file class.ilRatingGUI.php.

References $ilUser, and setUserId().

{
global $ilUser;
$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::setUserId (   $a_userid)

Set User ID.

Parameters
int$a_useridUser ID

Definition at line 81 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 101 of file class.ilRatingGUI.php.

{
$this->your_rating_text = $a_val;
}

Field Documentation

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.


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