ILIAS  release_4-3 Revision
 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 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, $a_sub_obj_type, $a_category_id=null)
 Get overall rating for an object.
static getExportData ($a_obj_id, $a_obj_type, array $a_category_ids=null)

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

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

References $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,
  $a_sub_obj_type,
  $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 108 of file class.ilRating.php.

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

{
global $ilDB;
$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")." 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");
}
$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 79 of file class.ilRating.php.

Referenced by ilRatingGUI\getHTML(), and ilRatingGUI\renderDetails().

{
global $ilDB;
$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::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 28 of file class.ilRating.php.

Referenced by ilRatingGUI\saveRating().

{
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"));
$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:


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