41 $ilDB = $DIC->database();
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") .
"," .
105 $ilDB = $DIC->database();
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
136 $ilDB = $DIC->database();
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)
169 $ilDB = $DIC->database();
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);
215 $ilDB = $DIC->database();
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);
242 $ilDB = $DIC->database();
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'));
274 $id =
"file/" .
$row[
"file_id"];
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'));
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'));
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]);
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.
if(!array_key_exists('StateId', $_REQUEST)) $id
static hasRatingInListGUI($a_obj_id, $a_obj_type)
static getExportData($a_obj_id, $a_obj_type, array $a_category_ids=null)
Get export data.
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.
foreach($_POST as $key=> $value) $res
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 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.
Create styles array
The data for the language used.
static preloadListGUIData(array $a_obj_ids)
Preload rating data for list guis.
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.