31 $a_user_id, $a_rating, $a_category_id = 0)
35 if ($a_user_id == ANONYMOUS_USER_ID)
42 $ilDB->manipulate(
"DELETE FROM il_rating WHERE ".
43 "user_id = ".$ilDB->quote($a_user_id,
"integer").
" AND ".
44 "obj_id = ".$ilDB->quote((
int) $a_obj_id,
"integer").
" AND ".
45 "obj_type = ".$ilDB->quote($a_obj_type,
"text").
" AND ".
46 "sub_obj_id = ".$ilDB->quote((
int) $a_sub_obj_id,
"integer").
" AND ".
47 $ilDB->equals(
"sub_obj_type", $a_sub_obj_type,
"text",
true).
" AND ".
48 "category_id = ".$ilDB->quote(0,
"integer"));
51 $ilDB->manipulate(
"DELETE FROM il_rating WHERE ".
52 "user_id = ".$ilDB->quote($a_user_id,
"integer").
" AND ".
53 "obj_id = ".$ilDB->quote((
int) $a_obj_id,
"integer").
" AND ".
54 "obj_type = ".$ilDB->quote($a_obj_type,
"text").
" AND ".
55 "sub_obj_id = ".$ilDB->quote((
int) $a_sub_obj_id,
"integer").
" AND ".
56 $ilDB->equals(
"sub_obj_type", $a_sub_obj_type,
"text",
true).
" AND ".
57 "category_id = ".$ilDB->quote((
int) $a_category_id,
"integer"));
61 $ilDB->manipulate(
"INSERT INTO il_rating (user_id, obj_id, obj_type,".
62 "sub_obj_id, sub_obj_type, category_id, rating, tstamp) VALUES (".
63 $ilDB->quote($a_user_id,
"integer").
",".
64 $ilDB->quote((
int) $a_obj_id,
"integer").
",".
65 $ilDB->quote($a_obj_type,
"text").
",".
66 $ilDB->quote((
int) $a_sub_obj_id,
"integer").
",".
67 $ilDB->quote($a_sub_obj_type,
"text").
",".
68 $ilDB->quote($a_category_id,
"integer").
",".
69 $ilDB->quote((
int) $a_rating,
"integer").
",".
70 $ilDB->quote(time(),
"integer").
")");
88 $ilDB->manipulate(
"DELETE FROM il_rating WHERE ".
89 "user_id = ".$ilDB->quote($a_user_id,
"integer").
" AND ".
90 "obj_id = ".$ilDB->quote((
int) $a_obj_id,
"integer").
" AND ".
91 "obj_type = ".$ilDB->quote($a_obj_type,
"text").
" AND ".
92 "sub_obj_id = ".$ilDB->quote((
int) $a_sub_obj_id,
"integer").
" AND ".
93 $ilDB->equals(
"sub_obj_type", $a_sub_obj_type,
"text",
true));
108 $a_user_id, $a_category_id = null)
112 if(is_array(self::$list_data))
114 return self::$list_data[
"user"][$a_obj_type.
"/".$a_obj_id];
117 $q =
"SELECT AVG(rating) av FROM il_rating WHERE ".
118 "user_id = ".$ilDB->quote($a_user_id,
"integer").
" AND ".
119 "obj_id = ".$ilDB->quote((
int) $a_obj_id,
"integer").
" AND ".
120 "obj_type = ".$ilDB->quote($a_obj_type,
"text").
" AND ".
121 "sub_obj_id = ".$ilDB->quote((
int) $a_sub_obj_id,
"integer").
" AND ".
122 $ilDB->equals(
"sub_obj_type", $a_sub_obj_type,
"text",
true);
123 if ($a_category_id !== null)
125 $q .=
" AND category_id = ".$ilDB->quote((
int) $a_category_id,
"integer");
127 $set = $ilDB->query($q);
128 $rec = $ilDB->fetchAssoc($set);
141 public static function getOverallRatingForObject($a_obj_id, $a_obj_type, $a_sub_obj_id = null, $a_sub_obj_type = null, $a_category_id = null)
145 if(is_array(self::$list_data))
147 return self::$list_data[
"all"][$a_obj_type.
"/".$a_obj_id];
150 $q =
"SELECT AVG(rating) av FROM il_rating".
151 " WHERE obj_id = ".$ilDB->quote((
int) $a_obj_id,
"integer").
152 " AND obj_type = ".$ilDB->quote($a_obj_type,
"text");
155 $q .=
" AND sub_obj_id = ".$ilDB->quote((
int) $a_sub_obj_id,
"integer").
156 " AND ".$ilDB->equals(
"sub_obj_type", $a_sub_obj_type,
"text",
true);
160 $q .=
" AND sub_obj_type = ".$ilDB->quote(
"-",
"text");
163 if ($a_category_id !== null)
165 $q .=
" AND category_id = ".$ilDB->quote((
int) $a_category_id,
"integer");
167 $q .=
" GROUP BY user_id";
168 $set = $ilDB->query($q);
170 while($rec = $ilDB->fetchAssoc($set))
183 return array(
"cnt" => $cnt,
"avg" => $avg);
194 public static function getExportData($a_obj_id, $a_obj_type, array $a_category_ids = null)
199 $q =
"SELECT sub_obj_id, sub_obj_type, rating, category_id, user_id, tstamp ".
200 "FROM il_rating WHERE ".
201 "obj_id = ".$ilDB->quote((
int) $a_obj_id,
"integer").
" AND ".
202 "obj_type = ".$ilDB->quote($a_obj_type,
"text").
206 $q .=
" AND ".$ilDB->in(
"category_id", $a_category_ids,
"",
"integer");
208 $set = $ilDB->query($q);
209 while(
$row = $ilDB->fetchAssoc($set))
225 $tmp =
$res = $tmp_user = $res_user = array();
228 $q =
"SELECT obj_id, obj_type, user_id, AVG(rating) av".
230 " WHERE ".$ilDB->in(
"obj_id", $a_obj_ids,
"",
"integer").
231 " AND sub_obj_id = ".$ilDB->quote(0,
"integer").
232 " GROUP BY obj_id, obj_type, user_id";
233 $set = $ilDB->query($q);
234 while($rec = $ilDB->fetchAssoc($set))
236 $tmp[$rec[
"obj_type"].
"/".$rec[
"obj_id"]][$rec[
"user_id"]] = (float)$rec[
"av"];
237 if($rec[
"user_id"] == $ilUser->getId())
240 $res_user[$rec[
"obj_type"].
"/".$rec[
"obj_id"]] = (float)$rec[
"av"];
245 foreach($tmp as $obj_id => $votes)
247 $res[$obj_id] = array(
"avg"=>array_sum($votes)/
sizeof($votes),
248 "cnt"=>
sizeof($votes));
253 $set = $ilDB->query(
"SELECT file_id, rating".
255 " WHERE ".$ilDB->in(
"file_id", $a_obj_ids,
"", integer));
256 while(
$row = $ilDB->fetchAssoc($set))
258 $id =
"file/".$row[
"file_id"];
259 if(
$row[
"rating"] && !isset(
$res[$id]))
261 $res[$id] = array(
"avg"=>0,
"cnt"=>0);
263 else if(!
$row[
"rating"] && isset(
$res[$id]))
269 $set = $ilDB->query(
"SELECT id, rating_overall".
270 " FROM il_wiki_data".
271 " WHERE ".$ilDB->in(
"id", $a_obj_ids,
"", integer));
272 while(
$row = $ilDB->fetchAssoc($set))
274 $id =
"wiki/".$row[
"id"];
275 if(
$row[
"rating_overall"] && !isset(
$res[$id]))
277 $res[$id] = array(
"avg"=>0,
"cnt"=>0);
279 else if(!
$row[
"rating_overall"] && isset(
$res[$id]))
285 $set = $ilDB->query(
"SELECT id, rating".
286 " FROM content_object".
287 " WHERE ".$ilDB->in(
"id", $a_obj_ids,
"", integer));
288 while(
$row = $ilDB->fetchAssoc($set))
290 $id =
"lm/".$row[
"id"];
291 if(
$row[
"rating"] && !isset(
$res[$id]))
293 $res[$id] = array(
"avg"=>0,
"cnt"=>0);
295 else if(!
$row[
"rating"] && isset(
$res[$id]))
301 self::$list_data = array(
"all"=>
$res,
"user"=>$res_user);
306 return isset(self::$list_data[
"all"][$a_obj_type.
"/".$a_obj_id]);