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

Class ilRating. More...

+ Collaboration diagram for ilRating:

Static Public Member Functions

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 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 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 getExportData ($a_obj_id, $a_obj_type, array $a_category_ids=null)
 Get export data.
static preloadListGUIData (array $a_obj_ids)
 Preload rating data for list guis.
static hasRatingInListGUI ($a_obj_id, $a_obj_type)

Static Protected Attributes

static $list_data

Detailed Description

Class ilRating.

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

Definition at line 15 of file class.ilRating.php.

Member Function Documentation

static ilRating::getExportData (   $a_obj_id,
  $a_obj_type,
array  $a_category_ids = null 
)
static

Get export data.

Parameters
int$a_obj_id
string$a_obj_type
array$a_category_ids
Returns
array

Definition at line 194 of file class.ilRating.php.

References $ilDB, $res, and $row.

Referenced by ilRatingCategoryGUI\export().

{
global $ilDB;
$res = array();
$q = "SELECT sub_obj_id, sub_obj_type, rating, category_id, user_id, tstamp ".
"FROM il_rating WHERE ".
"obj_id = ".$ilDB->quote((int) $a_obj_id, "integer")." AND ".
"obj_type = ".$ilDB->quote($a_obj_type, "text").
" ORDER BY tstamp";
if($a_category_ids)
{
$q .= " AND ".$ilDB->in("category_id", $a_category_ids, "", "integer");
}
$set = $ilDB->query($q);
while($row = $ilDB->fetchAssoc($set))
{
$res[] = $row;
}
return $res;
}

+ Here is the caller graph for this function:

static ilRating::getOverallRatingForObject (   $a_obj_id,
  $a_obj_type,
  $a_sub_obj_id = null,
  $a_sub_obj_type = null,
  $a_category_id = null 
)
static

Get overall rating for an object.

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

Definition at line 141 of file class.ilRating.php.

References $ilDB.

Referenced by ilWikiStat\getAverageRating(), ilDataCollectionRatingField\getExportValue(), ilRatingGUI\getHTML(), ilDataCollectionRatingField\getValue(), and ilRatingGUI\renderDetails().

{
global $ilDB;
if(is_array(self::$list_data))
{
return self::$list_data["all"][$a_obj_type."/".$a_obj_id];
}
$q = "SELECT AVG(rating) av FROM il_rating".
" WHERE obj_id = ".$ilDB->quote((int) $a_obj_id, "integer").
" AND obj_type = ".$ilDB->quote($a_obj_type, "text");
if($a_sub_obj_id)
{
$q .= " AND sub_obj_id = ".$ilDB->quote((int) $a_sub_obj_id, "integer").
" AND ".$ilDB->equals("sub_obj_type", $a_sub_obj_type, "text", true);
}
else
{
$q .= " AND sub_obj_type = ".$ilDB->quote("-", "text"); // #13913
}
if ($a_category_id !== null)
{
$q .= " AND category_id = ".$ilDB->quote((int) $a_category_id, "integer");
}
$q .= " GROUP BY user_id";
$set = $ilDB->query($q);
$avg = $cnt = 0;
while($rec = $ilDB->fetchAssoc($set))
{
$cnt++;
$avg += $rec["av"];
}
if ($cnt > 0)
{
$avg = $avg/$cnt;
}
else
{
$avg = 0;
}
return array("cnt" => $cnt, "avg" => $avg);
}

+ Here is the caller graph for this function:

static ilRating::getRatingForUserAndObject (   $a_obj_id,
  $a_obj_type,
  $a_sub_obj_id,
  $a_sub_obj_type,
  $a_user_id,
  $a_category_id = null 
)
static

Get rating for a user and an object.

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

Definition at line 107 of file class.ilRating.php.

References $ilDB.

Referenced by ilExAssignment\getAllPeerReviews(), ilRatingGUI\getHTML(), ilExAssignmentPeerReviewTableGUI\getItems(), ilRatingGUI\renderDetails(), and ilExAssignment\validatePeerReview().

{
global $ilDB;
if(is_array(self::$list_data))
{
return self::$list_data["user"][$a_obj_type."/".$a_obj_id];
}
$q = "SELECT AVG(rating) av FROM il_rating WHERE ".
"user_id = ".$ilDB->quote($a_user_id, "integer")." AND ".
"obj_id = ".$ilDB->quote((int) $a_obj_id, "integer")." AND ".
"obj_type = ".$ilDB->quote($a_obj_type, "text")." AND ".
"sub_obj_id = ".$ilDB->quote((int) $a_sub_obj_id, "integer")." AND ".
$ilDB->equals("sub_obj_type", $a_sub_obj_type, "text", true);
if ($a_category_id !== null)
{
$q .= " AND category_id = ".$ilDB->quote((int) $a_category_id, "integer");
}
$set = $ilDB->query($q);
$rec = $ilDB->fetchAssoc($set);
return $rec["av"];
}

+ Here is the caller graph for this function:

static ilRating::hasRatingInListGUI (   $a_obj_id,
  $a_obj_type 
)
static

Definition at line 304 of file class.ilRating.php.

Referenced by ilObjectListGUI\getListItemHTML().

{
return isset(self::$list_data["all"][$a_obj_type."/".$a_obj_id]);
}

+ Here is the caller graph for this function:

static ilRating::preloadListGUIData ( array  $a_obj_ids)
static

Preload rating data for list guis.

Parameters
array$a_obj_ids

Definition at line 221 of file class.ilRating.php.

References $ilDB, $ilUser, $res, and $row.

Referenced by ilObjectListGUIPreloader\preload().

{
global $ilDB, $ilUser;
$tmp = $res = $tmp_user = $res_user = array();
// collapse by categories
$q = "SELECT obj_id, obj_type, user_id, AVG(rating) av".
" FROM il_rating".
" WHERE ".$ilDB->in("obj_id", $a_obj_ids, "", "integer").
" AND sub_obj_id = ".$ilDB->quote(0, "integer").
" GROUP BY obj_id, obj_type, user_id";
$set = $ilDB->query($q);
while($rec = $ilDB->fetchAssoc($set))
{
$tmp[$rec["obj_type"]."/".$rec["obj_id"]][$rec["user_id"]] = (float)$rec["av"];
if($rec["user_id"] == $ilUser->getId())
{
// add final average to user result (no sub-objects)
$res_user[$rec["obj_type"]."/".$rec["obj_id"]] = (float)$rec["av"];
}
}
// average for main objects without sub-objects
foreach($tmp as $obj_id => $votes)
{
$res[$obj_id] = array("avg"=>array_sum($votes)/sizeof($votes),
"cnt"=>sizeof($votes));
}
// file/wiki/lm rating toggles
$set = $ilDB->query("SELECT file_id, rating".
" FROM file_data".
" WHERE ".$ilDB->in("file_id", $a_obj_ids, "", integer));
while($row = $ilDB->fetchAssoc($set))
{
$id = "file/".$row["file_id"];
if($row["rating"] && !isset($res[$id]))
{
$res[$id] = array("avg"=>0, "cnt"=>0);
}
else if(!$row["rating"] && isset($res[$id]))
{
unset($res[$id]);
}
}
$set = $ilDB->query("SELECT id, rating_overall".
" FROM il_wiki_data".
" WHERE ".$ilDB->in("id", $a_obj_ids, "", integer));
while($row = $ilDB->fetchAssoc($set))
{
$id = "wiki/".$row["id"];
if($row["rating_overall"] && !isset($res[$id]))
{
$res[$id] = array("avg"=>0, "cnt"=>0);
}
else if(!$row["rating_overall"] && isset($res[$id]))
{
unset($res[$id]);
}
}
$set = $ilDB->query("SELECT id, rating".
" FROM content_object".
" WHERE ".$ilDB->in("id", $a_obj_ids, "", integer));
while($row = $ilDB->fetchAssoc($set))
{
$id = "lm/".$row["id"];
if($row["rating"] && !isset($res[$id]))
{
$res[$id] = array("avg"=>0, "cnt"=>0);
}
else if(!$row["rating"] && isset($res[$id]))
{
unset($res[$id]);
}
}
self::$list_data = array("all"=>$res, "user"=>$res_user);
}

+ Here is the caller graph for this function:

static ilRating::resetRatingForUserAndObject (   $a_obj_id,
  $a_obj_type,
  $a_sub_obj_id,
  $a_sub_obj_type,
  $a_user_id 
)
static

Reset rating for a user and an object.

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

Definition at line 83 of file class.ilRating.php.

References $ilDB.

Referenced by ilExAssignment\resetPeerReviews(), ilRatingGUI\resetUserRating(), and ilLMPresentationGUI\updatePageRating().

{
global $ilDB;
$ilDB->manipulate("DELETE FROM il_rating WHERE ".
"user_id = ".$ilDB->quote($a_user_id, "integer")." AND ".
"obj_id = ".$ilDB->quote((int) $a_obj_id, "integer")." AND ".
"obj_type = ".$ilDB->quote($a_obj_type, "text")." AND ".
"sub_obj_id = ".$ilDB->quote((int) $a_sub_obj_id, "integer")." AND ".
$ilDB->equals("sub_obj_type", $a_sub_obj_type, "text", true));
}

+ Here is the caller graph for this function:

static ilRating::writeRatingForUserAndObject (   $a_obj_id,
  $a_obj_type,
  $a_sub_obj_id,
  $a_sub_obj_type,
  $a_user_id,
  $a_rating,
  $a_category_id = 0 
)
static

Write rating for a user and an object.

Parameters
int$a_obj_idObject ID
string$a_obj_typeObject Type
int$a_sub_obj_idSubobject ID
string$a_sub_obj_typeSubobject Type
int$a_user_idUser ID
int$a_ratingRating
int$a_category_idCategory ID

Definition at line 30 of file class.ilRating.php.

References $ilDB.

Referenced by ilRatingGUI\saveRating(), ilLMPresentationGUI\updatePageRating(), and ilObjExerciseGUI\updatePeerReviewCommentsObject().

{
global $ilDB;
if ($a_user_id == ANONYMOUS_USER_ID)
{
return;
}
if($a_category_id)
{
$ilDB->manipulate("DELETE FROM il_rating WHERE ".
"user_id = ".$ilDB->quote($a_user_id, "integer")." AND ".
"obj_id = ".$ilDB->quote((int) $a_obj_id, "integer")." AND ".
"obj_type = ".$ilDB->quote($a_obj_type, "text")." AND ".
"sub_obj_id = ".$ilDB->quote((int) $a_sub_obj_id, "integer")." AND ".
$ilDB->equals("sub_obj_type", $a_sub_obj_type, "text", true)." AND ".
"category_id = ".$ilDB->quote(0, "integer"));
}
$ilDB->manipulate("DELETE FROM il_rating WHERE ".
"user_id = ".$ilDB->quote($a_user_id, "integer")." AND ".
"obj_id = ".$ilDB->quote((int) $a_obj_id, "integer")." AND ".
"obj_type = ".$ilDB->quote($a_obj_type, "text")." AND ".
"sub_obj_id = ".$ilDB->quote((int) $a_sub_obj_id, "integer")." AND ".
$ilDB->equals("sub_obj_type", $a_sub_obj_type, "text", true)." AND ".
"category_id = ".$ilDB->quote((int) $a_category_id, "integer"));
if((int)$a_rating)
{
$ilDB->manipulate("INSERT INTO il_rating (user_id, obj_id, obj_type,".
"sub_obj_id, sub_obj_type, category_id, rating, tstamp) VALUES (".
$ilDB->quote($a_user_id, "integer").",".
$ilDB->quote((int) $a_obj_id, "integer").",".
$ilDB->quote($a_obj_type, "text").",".
$ilDB->quote((int) $a_sub_obj_id, "integer").",".
$ilDB->quote($a_sub_obj_type, "text").",".
$ilDB->quote($a_category_id, "integer").",".
$ilDB->quote((int) $a_rating, "integer").",".
$ilDB->quote(time(), "integer").")");
}
}

+ Here is the caller graph for this function:

Field Documentation

ilRating::$list_data
staticprotected

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


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