4include_once(
"./Services/Rating/classes/class.ilRating.php");
 
    5include_once(
"./Services/Rating/classes/class.ilRatingCategory.php");
 
   19        protected $id = 
"rtg_";
 
   28                $lng->loadLanguageModule(
"rating");
 
   38                $next_class = 
$ilCtrl->getNextClass($this);
 
   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);
 
   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);
 
  544                        $ttpl->parseCurrentBlock();
 
  546                        $ttpl->touchBlock(
"act_rat_end");               
 
  549                $ttpl->parseCurrentBlock();
 
  556                        $ttpl->setVariable(
"RATING_DETAILS", 
 
  557                                $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)
 
  577                $may_rate = ($this->
getUserId() != ANONYMOUS_USER_ID);          
 
  579                $ttpl = 
new ilTemplate(
"tpl.rating_block.html", 
true, 
true, 
"Services/Rating");         
 
  581                $ttpl->setVariable(
"TITLE", $a_title);
 
  583                $ttpl->setVariable(
"RATING_DETAILS", 
 
  584                                $this->
renderDetails(
"rtsb_", $may_rate, $categories, 
null, 
true));
 
  596                if(!is_array($_REQUEST[
"rating"]))
 
  606                                        $this->sub_obj_id, $this->sub_obj_type, $this->
getUserId(),
 
  612                        foreach(
$_POST[
"rating"] as $cat_id => $rating)
 
  615                                        $this->sub_obj_id, $this->sub_obj_type, $this->
getUserId(),
 
  620                if($this->update_callback)
 
  622                        call_user_func($this->update_callback, $this->obj_id, $this->obj_type,
 
  623                                $this->sub_obj_id, $this->sub_obj_type);                        
 
  634                $this->update_callback = $a_callback;
 
  643                                $this->sub_obj_id, $this->sub_obj_type, $this->
getUserId());                    
 
  648                $this->export_callback = $a_callback;
 
  649                $this->export_subobj_title = $a_subobj_title;
 
  663                return $this->
getHTML(
true, $a_may_rate, 
 
  664                        "il.Object.saveRatingFromListGUI(".$a_ref_id.
", '".$a_ajax_hash.
"', %rating%);",
 
sprintf('%.4f', $callTime)
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 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.
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.
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)