51        if ($a_user_id == ANONYMOUS_USER_ID) {
 
   56            $ilDB->manipulate(
"DELETE FROM il_rating WHERE " .
 
   57                "user_id = " . 
$ilDB->quote($a_user_id, 
"integer") . 
" AND " .
 
   58                "obj_id = " . 
$ilDB->quote((
int) $a_obj_id, 
"integer") . 
" AND " .
 
   59                "obj_type = " . 
$ilDB->quote($a_obj_type, 
"text") . 
" AND " .
 
   60                "sub_obj_id = " . 
$ilDB->quote((
int) $a_sub_obj_id, 
"integer") . 
" AND " .
 
   61                $ilDB->equals(
"sub_obj_type", $a_sub_obj_type, 
"text", 
true) . 
" AND " .
 
   62                "category_id = " . 
$ilDB->quote(0, 
"integer"));
 
   65        $ilDB->manipulate(
"DELETE FROM il_rating WHERE " .
 
   66            "user_id = " . 
$ilDB->quote($a_user_id, 
"integer") . 
" AND " .
 
   67            "obj_id = " . 
$ilDB->quote((
int) $a_obj_id, 
"integer") . 
" AND " .
 
   68            "obj_type = " . 
$ilDB->quote($a_obj_type, 
"text") . 
" AND " .
 
   69            "sub_obj_id = " . 
$ilDB->quote((
int) $a_sub_obj_id, 
"integer") . 
" AND " .
 
   70            $ilDB->equals(
"sub_obj_type", $a_sub_obj_type, 
"text", 
true) . 
" AND " .
 
   71            "category_id = " . 
$ilDB->quote((
int) $a_category_id, 
"integer"));
 
   73        if ((
int) $a_rating) {
 
   74            $ilDB->manipulate(
"INSERT INTO il_rating (user_id, obj_id, obj_type," .
 
   75                "sub_obj_id, sub_obj_type, category_id, rating, tstamp) VALUES (" .
 
   76                $ilDB->quote($a_user_id, 
"integer") . 
"," .
 
   77                $ilDB->quote((
int) $a_obj_id, 
"integer") . 
"," .
 
   78                $ilDB->quote($a_obj_type, 
"text") . 
"," .
 
   79                $ilDB->quote((
int) $a_sub_obj_id, 
"integer") . 
"," .
 
   80                $ilDB->quote($a_sub_obj_type, 
"text") . 
"," .
 
   81                $ilDB->quote($a_category_id, 
"integer") . 
"," .
 
   82                $ilDB->quote((
int) $a_rating, 
"integer") . 
"," .
 
   83                $ilDB->quote(time(), 
"integer") . 
")");
 
  107        $ilDB->manipulate(
"DELETE FROM il_rating WHERE " .
 
  108            "user_id = " . 
$ilDB->quote($a_user_id, 
"integer") . 
" AND " .
 
  109            "obj_id = " . 
$ilDB->quote((
int) $a_obj_id, 
"integer") . 
" AND " .
 
  110            "obj_type = " . 
$ilDB->quote($a_obj_type, 
"text") . 
" AND " .
 
  111            "sub_obj_id = " . 
$ilDB->quote((
int) $a_sub_obj_id, 
"integer") . 
" AND " .
 
  112            $ilDB->equals(
"sub_obj_type", $a_sub_obj_type, 
"text", 
true));
 
  132        $a_category_id = 
null 
  138        if (is_array(self::$list_data)) {
 
  139            return self::$list_data[
"user"][$a_obj_type . 
"/" . $a_obj_id];
 
  142        $q = 
"SELECT AVG(rating) av FROM il_rating WHERE " .
 
  143            "user_id = " . 
$ilDB->quote($a_user_id, 
"integer") . 
" AND " .
 
  144            "obj_id = " . 
$ilDB->quote((
int) $a_obj_id, 
"integer") . 
" AND " .
 
  145            "obj_type = " . 
$ilDB->quote($a_obj_type, 
"text") . 
" AND " .
 
  146            "sub_obj_id = " . 
$ilDB->quote((
int) $a_sub_obj_id, 
"integer") . 
" AND " .
 
  147            $ilDB->equals(
"sub_obj_type", $a_sub_obj_type, 
"text", 
true);
 
  148        if ($a_category_id !== 
null) {
 
  149            $q .= 
" AND category_id = " . 
$ilDB->quote((
int) $a_category_id, 
"integer");
 
  151        $set = 
$ilDB->query($q);
 
  152        $rec = 
$ilDB->fetchAssoc($set);
 
  165    public static function getOverallRatingForObject($a_obj_id, $a_obj_type, $a_sub_obj_id = 
null, $a_sub_obj_type = 
null, $a_category_id = 
null)
 
  171        if (is_array(self::$list_data)) {
 
  172            return self::$list_data[
"all"][$a_obj_type . 
"/" . $a_obj_id];
 
  175        $q = 
"SELECT AVG(rating) av FROM il_rating" .
 
  176            " WHERE obj_id = " . 
$ilDB->quote((
int) $a_obj_id, 
"integer") .
 
  177            " AND obj_type = " . 
$ilDB->quote($a_obj_type, 
"text");
 
  179            $q .= 
" AND sub_obj_id = " . 
$ilDB->quote((
int) $a_sub_obj_id, 
"integer") .
 
  180                " AND " . 
$ilDB->equals(
"sub_obj_type", $a_sub_obj_type, 
"text", 
true);
 
  182            $q .= 
" AND sub_obj_type = " . 
$ilDB->quote(
"-", 
"text"); 
 
  185        if ($a_category_id !== 
null) {
 
  186            $q .= 
" AND category_id = " . 
$ilDB->quote((
int) $a_category_id, 
"integer");
 
  188        $q .= 
" GROUP BY user_id";
 
  189        $set = 
$ilDB->query($q);
 
  191        while ($rec = 
$ilDB->fetchAssoc($set)) {
 
  200        return array(
"cnt" => $cnt, 
"avg" => $avg);
 
  211    public static function getExportData($a_obj_id, $a_obj_type, array $a_category_ids = 
null)
 
  218        $q = 
"SELECT sub_obj_id, sub_obj_type, rating, category_id, user_id, tstamp " .
 
  219            "FROM il_rating WHERE " .
 
  220            "obj_id = " . 
$ilDB->quote((
int) $a_obj_id, 
"integer") . 
" AND " .
 
  221            "obj_type = " . 
$ilDB->quote($a_obj_type, 
"text") .
 
  223        if ($a_category_ids) {
 
  224            $q .= 
" AND " . 
$ilDB->in(
"category_id", $a_category_ids, 
"", 
"integer");
 
  226        $set = 
$ilDB->query($q);
 
  227        while ($row = 
$ilDB->fetchAssoc($set)) {
 
  245        $tmp = 
$res = $tmp_user = $res_user = array();
 
  248        $q = 
"SELECT obj_id, obj_type, user_id, AVG(rating) av" .
 
  250            " WHERE " . 
$ilDB->in(
"obj_id", $a_obj_ids, 
"", 
"integer") .
 
  251            " AND sub_obj_id = " . 
$ilDB->quote(0, 
"integer") .
 
  252            " GROUP BY obj_id, obj_type, user_id";
 
  253        $set = 
$ilDB->query($q);
 
  254        while ($rec = 
$ilDB->fetchAssoc($set)) {
 
  255            $tmp[$rec[
"obj_type"] . 
"/" . $rec[
"obj_id"]][$rec[
"user_id"]] = (float) $rec[
"av"];
 
  256            if ($rec[
"user_id"] == 
$ilUser->getId()) {
 
  258                $res_user[$rec[
"obj_type"] . 
"/" . $rec[
"obj_id"]] = (float) $rec[
"av"];
 
  263        foreach ($tmp as $obj_id => $votes) {
 
  264            $res[$obj_id] = array(
"avg" => array_sum($votes) / 
sizeof($votes),
 
  265                "cnt" => 
sizeof($votes));
 
  270        $set = 
$ilDB->query(
"SELECT file_id, rating" .
 
  272            " WHERE " . 
$ilDB->in(
"file_id", $a_obj_ids, 
"", 
'integer'));
 
  273        while ($row = 
$ilDB->fetchAssoc($set)) {
 
  274            $id = 
"file/" . $row[
"file_id"];
 
  275            if ($row[
"rating"] && !isset(
$res[$id])) {
 
  276                $res[$id] = array(
"avg" => 0, 
"cnt" => 0);
 
  277            } elseif (!$row[
"rating"] && isset(
$res[$id])) {
 
  282        $set = 
$ilDB->query(
"SELECT id, rating_overall" .
 
  283            " FROM il_wiki_data" .
 
  284            " WHERE " . 
$ilDB->in(
"id", $a_obj_ids, 
"", 
'integer'));
 
  285        while ($row = 
$ilDB->fetchAssoc($set)) {
 
  286            $id = 
"wiki/" . $row[
"id"];
 
  287            if ($row[
"rating_overall"] && !isset(
$res[$id])) {
 
  288                $res[$id] = array(
"avg" => 0, 
"cnt" => 0);
 
  289            } elseif (!$row[
"rating_overall"] && isset(
$res[$id])) {
 
  294        $set = 
$ilDB->query(
"SELECT id, rating" .
 
  295            " FROM content_object" .
 
  296            " WHERE " . 
$ilDB->in(
"id", $a_obj_ids, 
"", 
'integer'));
 
  297        while ($row = 
$ilDB->fetchAssoc($set)) {
 
  298            $id = 
"lm/" . $row[
"id"];
 
  299            if ($row[
"rating"] && !isset(
$res[$id])) {
 
  300                $res[$id] = array(
"avg" => 0, 
"cnt" => 0);
 
  301            } elseif (!$row[
"rating"] && isset(
$res[$id])) {
 
  306        self::$list_data = array(
"all" => 
$res, 
"user" => $res_user);
 
  311        return isset(self::$list_data[
"all"][$a_obj_type . 
"/" . $a_obj_id]);
 
An exception for terminatinating execution or to throw for unit testing.
static hasRatingInListGUI($a_obj_id, $a_obj_type)
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 preloadListGUIData(array $a_obj_ids)
Preload rating data for list guis.
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 getExportData($a_obj_id, $a_obj_type, array $a_category_ids=null)
Get export data.
foreach($_POST as $key=> $value) $res