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);
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 WHERE ".
151 "obj_id = ".$ilDB->quote((
int) $a_obj_id,
"integer").
" AND ".
152 "obj_type = ".$ilDB->quote($a_obj_type,
"text").
" AND ".
153 "sub_obj_id = ".$ilDB->quote((
int) $a_sub_obj_id,
"integer").
" AND ".
154 $ilDB->equals(
"sub_obj_type", $a_sub_obj_type,
"text",
true);
155 if ($a_category_id !== null)
157 $q .=
" AND category_id = ".$ilDB->quote((
int) $a_category_id,
"integer");
159 $q .=
" GROUP BY user_id";
160 $set = $ilDB->query($q);
162 while($rec = $ilDB->fetchAssoc($set))
175 return array(
"cnt" => $cnt,
"avg" => $avg);
186 public static function getExportData($a_obj_id, $a_obj_type, array $a_category_ids = null)
191 $q =
"SELECT sub_obj_id, sub_obj_type, rating, category_id, user_id, tstamp ".
192 "FROM il_rating WHERE ".
193 "obj_id = ".$ilDB->quote((
int) $a_obj_id,
"integer").
" AND ".
194 "obj_type = ".$ilDB->quote($a_obj_type,
"text").
198 $q .=
" AND ".$ilDB->in(
"category_id", $a_category_ids,
"",
"integer");
200 $set = $ilDB->query($q);
201 while(
$row = $ilDB->fetchAssoc($set))
217 $tmp =
$res = $tmp_user = $res_user = array();
220 $q =
"SELECT obj_id, obj_type, user_id, AVG(rating) av".
222 " WHERE ".$ilDB->in(
"obj_id", $a_obj_ids,
"",
"integer").
223 " AND sub_obj_id = ".$ilDB->quote(0,
"integer").
224 " GROUP BY obj_id, obj_type, user_id";
225 $set = $ilDB->query($q);
226 while($rec = $ilDB->fetchAssoc($set))
228 $tmp[$rec[
"obj_type"].
"/".$rec[
"obj_id"]][$rec[
"user_id"]] = (float)$rec[
"av"];
229 if($rec[
"user_id"] == $ilUser->getId())
232 $res_user[$rec[
"obj_type"].
"/".$rec[
"obj_id"]] = (float)$rec[
"av"];
237 foreach($tmp as $obj_id => $votes)
239 $res[$obj_id] = array(
"avg"=>array_sum($votes)/
sizeof($votes),
240 "cnt"=>
sizeof($votes));
245 $set = $ilDB->query(
"SELECT file_id, rating".
247 " WHERE ".$ilDB->in(
"file_id", $a_obj_ids,
"", integer));
248 while(
$row = $ilDB->fetchAssoc($set))
250 $id =
"file/".$row[
"file_id"];
251 if(
$row[
"rating"] && !isset(
$res[$id]))
253 $res[$id] = array(
"avg"=>0,
"cnt"=>0);
255 else if(!
$row[
"rating"] && isset(
$res[$id]))
261 $set = $ilDB->query(
"SELECT id, rating_overall".
262 " FROM il_wiki_data".
263 " WHERE ".$ilDB->in(
"id", $a_obj_ids,
"", integer));
264 while(
$row = $ilDB->fetchAssoc($set))
266 $id =
"wiki/".$row[
"id"];
267 if(
$row[
"rating_overall"] && !isset(
$res[$id]))
269 $res[$id] = array(
"avg"=>0,
"cnt"=>0);
271 else if(!
$row[
"rating_overall"] && isset(
$res[$id]))
277 $set = $ilDB->query(
"SELECT id, rating".
278 " FROM content_object".
279 " WHERE ".$ilDB->in(
"id", $a_obj_ids,
"", integer));
280 while(
$row = $ilDB->fetchAssoc($set))
282 $id =
"lm/".$row[
"id"];
283 if(
$row[
"rating"] && !isset(
$res[$id]))
285 $res[$id] = array(
"avg"=>0,
"cnt"=>0);
287 else if(!
$row[
"rating"] && isset(
$res[$id]))
293 self::$list_data = array(
"all"=>
$res,
"user"=>$res_user);
298 return isset(self::$list_data[
"all"][$a_obj_type.
"/".$a_obj_id]);