29 $a_user_id, $a_rating, $a_category_id = 0)
33 if ($a_user_id == ANONYMOUS_USER_ID)
40 $ilDB->manipulate(
"DELETE FROM il_rating WHERE ".
41 "user_id = ".$ilDB->quote($a_user_id,
"integer").
" AND ".
42 "obj_id = ".$ilDB->quote((
int) $a_obj_id,
"integer").
" AND ".
43 "obj_type = ".$ilDB->quote($a_obj_type,
"text").
" AND ".
44 "sub_obj_id = ".$ilDB->quote((
int) $a_sub_obj_id,
"integer").
" AND ".
45 $ilDB->equals(
"sub_obj_type", $a_sub_obj_type,
"text",
true).
" AND ".
46 "category_id = ".$ilDB->quote(0,
"integer"));
49 $ilDB->manipulate(
"DELETE FROM il_rating WHERE ".
50 "user_id = ".$ilDB->quote($a_user_id,
"integer").
" AND ".
51 "obj_id = ".$ilDB->quote((
int) $a_obj_id,
"integer").
" AND ".
52 "obj_type = ".$ilDB->quote($a_obj_type,
"text").
" AND ".
53 "sub_obj_id = ".$ilDB->quote((
int) $a_sub_obj_id,
"integer").
" AND ".
54 $ilDB->equals(
"sub_obj_type", $a_sub_obj_type,
"text",
true).
" AND ".
55 "category_id = ".$ilDB->quote((
int) $a_category_id,
"integer"));
57 $ilDB->manipulate(
"INSERT INTO il_rating (user_id, obj_id, obj_type,".
58 "sub_obj_id, sub_obj_type, category_id, rating, tstamp) VALUES (".
59 $ilDB->quote($a_user_id,
"integer").
",".
60 $ilDB->quote((
int) $a_obj_id,
"integer").
",".
61 $ilDB->quote($a_obj_type,
"text").
",".
62 $ilDB->quote((
int) $a_sub_obj_id,
"integer").
",".
63 $ilDB->quote($a_sub_obj_type,
"text").
",".
64 $ilDB->quote($a_category_id,
"integer").
",".
65 $ilDB->quote((
int) $a_rating,
"integer").
",".
66 $ilDB->quote(time(),
"integer").
")");
80 $a_user_id, $a_category_id = null)
84 $q =
"SELECT AVG(rating) av FROM il_rating WHERE ".
85 "user_id = ".$ilDB->quote($a_user_id,
"integer").
" AND ".
86 "obj_id = ".$ilDB->quote((
int) $a_obj_id,
"integer").
" AND ".
87 "obj_type = ".$ilDB->quote($a_obj_type,
"text").
" AND ".
88 "sub_obj_id = ".$ilDB->quote((
int) $a_sub_obj_id,
"integer").
" AND ".
89 $ilDB->equals(
"sub_obj_type", $a_sub_obj_type,
"text",
true);
90 if ($a_category_id !== null)
92 $q .=
" AND category_id = ".$ilDB->quote((
int) $a_category_id,
"integer");
94 $set = $ilDB->query($q);
95 $rec = $ilDB->fetchAssoc($set);
112 $q =
"SELECT AVG(rating) av FROM il_rating WHERE ".
113 "obj_id = ".$ilDB->quote((
int) $a_obj_id,
"integer").
" AND ".
114 "obj_type = ".$ilDB->quote($a_obj_type,
"text").
" AND ".
115 "sub_obj_id = ".$ilDB->quote((
int) $a_sub_obj_id,
"integer").
" AND ".
116 $ilDB->equals(
"sub_obj_type", $a_sub_obj_type,
"text",
true);
117 if ($a_category_id !== null)
119 $q .=
" AND category_id = ".$ilDB->quote((
int) $a_category_id,
"integer");
121 $q .=
" GROUP BY user_id";
122 $set = $ilDB->query($q);
124 while($rec = $ilDB->fetchAssoc($set))
137 return array(
"cnt" => $cnt,
"avg" => $avg);
143 static function getExportData($a_obj_id, $a_obj_type, array $a_category_ids = null)
148 $q =
"SELECT sub_obj_id, sub_obj_type, rating, category_id, user_id, tstamp ".
149 "FROM il_rating WHERE ".
150 "obj_id = ".$ilDB->quote((
int) $a_obj_id,
"integer").
" AND ".
151 "obj_type = ".$ilDB->quote($a_obj_type,
"text").
155 $q .=
" AND ".$ilDB->in(
"category_id", $a_category_ids,
"",
"integer");
157 $set = $ilDB->query($q);
158 while(
$row = $ilDB->fetchAssoc($set))