4include_once(
"./Services/Rating/classes/class.ilRating.php");
 
    5include_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();
 
   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 = 
"")
 
   86        if (!trim($a_sub_obj_type)) {
 
   87            $a_sub_obj_type = 
"-";
 
   90        $this->obj_id = $a_obj_id;
 
   91        $this->obj_type = $a_obj_type;
 
   92        $this->sub_obj_id = $a_sub_obj_id;
 
   93        $this->sub_obj_type = $a_sub_obj_type;
 
   94        $this->
id = 
"rtg_" . $this->obj_id . 
"_" . $this->obj_type . 
"_" . $this->sub_obj_id . 
"_" .
 
  107        $this->userid = $a_userid;
 
  127        $this->your_rating_text = $a_val;
 
  137        return $this->your_rating_text;
 
  147        $this->enable_categories = (bool) $a_value;
 
  157        $this->ctrl_path = $a_value;
 
  170    protected function renderDetails($a_js_id, $a_may_rate, array $a_categories = 
null, $a_onclick = 
null, $a_average = 
false)
 
  175        $ttpl = 
new ilTemplate(
"tpl.rating_details.html", 
true, 
true, 
"Services/Rating");
 
  181                : 
$lng->txt(
"rating_your_rating");
 
  185        if (!$a_categories) {
 
  196                if ((
bool) $a_average) {
 
  206                for (
$i = 1; 
$i <= 5; 
$i++) {
 
  207                    if ((
bool) $a_average &&
 
  209                        $ttpl->setCurrentBlock(
"rating_mark_simple");
 
  214                        $ttpl->parseCurrentBlock();
 
  217                    $ttpl->setCurrentBlock(
"rating_link_simple");
 
  218                    if (stristr($a_onclick, 
"%rating%")) {
 
  221                        $ilCtrl->setParameter($this, 
"rating", 
$i);
 
  222                        if (!$this->ctrl_path) {
 
  223                            $url_save = 
$ilCtrl->getLinkTarget($this, 
"saveRating");
 
  225                            $url_save = 
$ilCtrl->getLinkTargetByClass($this->ctrl_path, 
"saveRating");
 
  228                    $ttpl->setVariable(
"HREF_RATING", $url_save);
 
  231                        $onclick = str_replace(
"%rating%", 
$i, $a_onclick);
 
  232                        $ttpl->setVariable(
"ONCLICK_RATING", 
' onclick="' . $onclick . 
'"');
 
  235                    if ((
bool) $a_average) {
 
  236                        $ref_rating = $overall_rating[
"avg"];
 
  238                        $ref_rating = $rating;
 
  241                    if ($ref_rating >= 
$i) {
 
  252                    $ttpl->setVariable(
"ALT_ICON", 
"(" . 
$i . 
"/5)");
 
  253                    $ttpl->parseCurrentBlock();
 
  258                    $ttpl->setCurrentBlock(
"rating_simple_del_bl");
 
  259                    $ttpl->setVariable(
"CAPTION_RATING_DEL", 
$lng->txt(
"rating_remove"));
 
  261                    if (stristr($a_onclick, 
"%rating%")) {
 
  264                        $ilCtrl->setParameter($this, 
"rating", 0);
 
  265                        if (!$this->ctrl_path) {
 
  266                            $url_save = 
$ilCtrl->getLinkTarget($this, 
"saveRating");
 
  268                            $url_save = 
$ilCtrl->getLinkTargetByClass($this->ctrl_path, 
"saveRating");
 
  271                    $ttpl->setVariable(
"HREF_RATING_DEL", $url_save);
 
  274                        $onclick = str_replace(
"%rating%", 0, $a_onclick);
 
  275                        $ttpl->setVariable(
"ONCLICK_RATING_DEL", 
' onclick="' . $onclick . 
'"');
 
  278                    $ttpl->parseCurrentBlock();
 
  282                    $ttpl->setCurrentBlock(
"rating_simple_title");
 
  283                    $ttpl->setVariable(
"TXT_RATING_SIMPLE", $rate_text);
 
  284                    $ttpl->parseCurrentBlock();
 
  288                $ttpl->setCurrentBlock(
"user_rating_simple");
 
  290                if ((
bool) $a_average &&
 
  291                    $overall_rating[
"cnt"]) {
 
  292                    $ttpl->setVariable(
"NUMBER_VOTES_SIMPLE", $overall_rating[
"cnt"]);
 
  295                $ttpl->parseCurrentBlock();
 
  300            $has_user_rating = 
false;
 
  301            foreach ($a_categories as $category) {
 
  319                for (
$i = 1; 
$i <= 5; 
$i++) {
 
  320                    if ($a_may_rate && 
$i == $user_rating) {
 
  321                        $has_user_rating = 
true;
 
  323                        $ttpl->setCurrentBlock(
"rating_mark");
 
  328                        $ttpl->parseCurrentBlock();
 
  331                    $ttpl->setCurrentBlock(
"user_rating_icon");
 
  332                    if ($overall_rating[
"avg"] >= 
$i) {
 
  337                    } elseif ($overall_rating[
"avg"] + 1 <= 
$i) {
 
  343                        $nr = round(($overall_rating[
"avg"] + 1 - 
$i) * 10);
 
  349                    $ttpl->setVariable(
"ALT_ICON", 
"(" . 
$i . 
"/5)");
 
  352                        $ttpl->setVariable(
"HREF_RATING", 
"il.Rating.setValue(" . $category[
"id"] . 
"," . 
$i . 
", '" . $a_js_id . 
"')");
 
  353                        $ttpl->setVariable(
"CATEGORY_ID", $category[
"id"]);
 
  354                        $ttpl->setVariable(
"ICON_VALUE", 
$i);
 
  355                        $ttpl->setVariable(
"JS_ID", $a_js_id);
 
  356                        $ttpl->setVariable(
"ICON_MOUSEACTION", 
" onmouseover=\"il.Rating.toggleIcon(this," . 
$i . 
")\"" .
 
  357                            " onmouseout=\"il.Rating.toggleIcon(this," . 
$i . 
",1)\"");
 
  360                    $ttpl->parseCurrentBlock();
 
  364                    $ttpl->setCurrentBlock(
"user_rating_category_column");
 
  365                    $ttpl->setVariable(
"JS_ID", $a_js_id);
 
  366                    $ttpl->setVariable(
"CATEGORY_ID", $category[
"id"]);
 
  367                    $ttpl->setVariable(
"CATEGORY_VALUE", $user_rating);
 
  368                    $ttpl->parseCurrentBlock();
 
  372                $ttpl->setCurrentBlock(
"user_rating_category");
 
  373                $ttpl->setVariable(
"TXT_RATING_CATEGORY", $category[
"title"]);
 
  374                $ttpl->parseCurrentBlock();
 
  377            if ($overall_rating[
"cnt"]) {
 
  378                $ttpl->setCurrentBlock(
"votes_number_bl");
 
  379                $ttpl->setVariable(
"NUMBER_VOTES", sprintf(
$lng->txt(
"rating_number_votes"), $overall_rating[
"cnt"]));
 
  380                $ttpl->parseCurrentBlock();
 
  385                if ($has_user_rating) {
 
  386                    $ttpl->setCurrentBlock(
"user_rating_categories_del_bl");
 
  387                    $ttpl->setVariable(
"CAPTION_RATING_DEL_CAT", 
$lng->txt(
"rating_remove"));
 
  389                    $ilCtrl->setParameter($this, 
"rating", 0);
 
  390                    if (!$this->ctrl_path) {
 
  391                        $url_save = 
$ilCtrl->getLinkTarget($this, 
"resetUserRating");
 
  393                        $url_save = 
$ilCtrl->getLinkTargetByClass($this->ctrl_path, 
"resetUserRating");
 
  395                    $ttpl->setVariable(
"HREF_RATING_DEL_CAT", $url_save);
 
  397                    $ttpl->parseCurrentBlock();
 
  400                if (!$this->ctrl_path) {
 
  401                    $url_form = 
$ilCtrl->getFormAction($this, 
"saveRating");
 
  403                    $url_form = 
$ilCtrl->getFormActionByClass($this->ctrl_path, 
"saveRating");
 
  405                $ttpl->setVariable(
"FORM_ACTION", $url_form);
 
  406                $ttpl->setVariable(
"TXT_SUBMIT", 
$lng->txt(
"rating_overlay_submit"));
 
  407                $ttpl->setVariable(
"CMD_SUBMIT", 
"saveRating");
 
  408                $ttpl->touchBlock(
"user_rating_categories_form_out");
 
  431    public function getHTML($a_show_overall = 
true, $a_may_rate = 
true, $a_onclick = 
null, $a_additional_id = 
null)
 
  436        if ($a_additional_id) {
 
  437            $unique_id .= 
"_" . $a_additional_id;
 
  440        $categories = array();
 
  441        if ($this->enable_categories) {
 
  445        $may_rate = ($this->
getUserId() != ANONYMOUS_USER_ID);
 
  446        if ($may_rate && !$a_may_rate) {
 
  450        $has_overlay = 
false;
 
  451        if ($may_rate || $categories) {
 
  455        $ttpl = 
new ilTemplate(
"tpl.rating_input.html", 
true, 
true, 
"Services/Rating");
 
  459        if ($may_rate || !$a_show_overall) {
 
  470        if ($a_show_overall) {
 
  478            $rating = array(
"avg" => $user_rating);
 
  481        for (
$i = 1; 
$i <= 5; 
$i++) {
 
  482            if ($a_show_overall &&
 
  483                $i == $user_rating) {
 
  484                $ttpl->setCurrentBlock(
"rating_mark");
 
  489                $ttpl->parseCurrentBlock();
 
  492            $ttpl->setCurrentBlock(
"rating_icon");
 
  493            if ($rating[
"avg"] >= 
$i) {
 
  498            } elseif ($rating[
"avg"] + 1 <= 
$i) {
 
  504                $nr = round(($rating[
"avg"] + 1 - 
$i) * 10);
 
  510            $ttpl->setVariable(
"ALT_ICON", 
"(" . 
$i . 
"/5)");
 
  511            $ttpl->parseCurrentBlock();
 
  513        $ttpl->setCurrentBlock(
"rating_icon");
 
  515        if ($a_show_overall) {
 
  516            if ($rating[
"cnt"] == 0) {
 
  517                $tt = 
$lng->txt(
"rat_not_rated_yet");
 
  518            } elseif ($rating[
"cnt"] == 1) {
 
  519                $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) {
 
  527                $ttpl->setCurrentBlock(
"rat_nr");
 
  528                $ttpl->setVariable(
"RT_NR", $rating[
"cnt"]);
 
  529                $ttpl->parseCurrentBlock();
 
  535            include_once(
"./Services/UIComponent/Overlay/classes/class.ilOverlayGUI.php");
 
  537            $ov->setTrigger(
"tr_" . $unique_id, 
"click", 
"tr_" . $unique_id);
 
  540            $ttpl->setCurrentBlock(
"act_rat_start");
 
  541            $ttpl->setVariable(
"ID", $unique_id);
 
  542            $ttpl->parseCurrentBlock();
 
  544            $ttpl->touchBlock(
"act_rat_end");
 
  547        $ttpl->parseCurrentBlock();
 
  555                $this->
renderDetails(
"rtov_", $may_rate, $categories, $a_onclick)
 
  558            $ttpl->setCurrentBlock(
"user_rating");
 
  559            $ttpl->setVariable(
"ID", $unique_id);
 
  560            $ttpl->parseCurrentBlock();
 
  563        $ttpl->setVariable(
"TTID", $unique_id);
 
  570        $categories = array();
 
  571        if ($this->enable_categories) {
 
  575        $may_rate = ($this->
getUserId() != ANONYMOUS_USER_ID);
 
  577        $ttpl = 
new ilTemplate(
"tpl.rating_block.html", 
true, 
true, 
"Services/Rating");
 
  579        $ttpl->setVariable(
"TITLE", $a_title);
 
  583            $this->
renderDetails(
"rtsb_", $may_rate, $categories, 
null, 
true)
 
  596        if (!is_array($_REQUEST[
"rating"])) {
 
  611            foreach (
$_POST[
"rating"] as $cat_id => $rating) {
 
  624        if ($this->update_callback) {
 
  626                $this->update_callback,
 
  641        $this->update_callback = $a_callback;
 
  660        $this->export_callback = $a_callback;
 
  661        $this->export_subobj_title = $a_subobj_title;
 
  678            "il.Object.saveRatingFromListGUI(" . $a_ref_id . 
", '" . $a_ajax_hash . 
"', %rating%);",
 
An exception for terminatinating execution or to throw for unit testing.
This is a utility class for the yui overlays.
Class ilRatingCategoryGUI.
static getAllForObject($a_parent_obj_id)
Get all categories for object.
enableCategories($a_value)
Toggle categories status.
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.
resetUserRating()
Reset Rating.
setCtrlPath(array $a_value)
ilCtrl path
executeCommand()
execute command
setUpdateCallback($a_callback)
setObject($a_obj_id, $a_obj_type, $a_sub_obj_id=0, $a_sub_obj_type="")
Set Object.
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.
setYourRatingText($a_val)
Set "Your Rating" text.
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)
getYourRatingText()
Get "Your Rating" text.
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.
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.
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.
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.
special template class to simplify handling of ITX/PEAR
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
if(empty($userids)) $userid