ILIAS  release_4-4 Revision
ilRating Class Reference

Class ilRating. More...

+ Collaboration diagram for ilRating:

Static Public Member Functions

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. More...
 
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. More...
 
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. More...
 
static getOverallRatingForObject ($a_obj_id, $a_obj_type, $a_sub_obj_id, $a_sub_obj_type, $a_category_id=null)
 Get overall rating for an object. More...
 
static getExportData ($a_obj_id, $a_obj_type, array $a_category_ids=null)
 Get export data. More...
 
static preloadListGUIData (array $a_obj_ids)
 Preload rating data for list guis. More...
 
static hasRatingInListGUI ($a_obj_id, $a_obj_type)
 

Static Protected Attributes

static $list_data
 

Detailed Description

Class ilRating.

Author
Alex Killing alex..nosp@m.kill.nosp@m.ing@g.nosp@m.mx.d.nosp@m.e
Version
$Id$

Definition at line 15 of file class.ilRating.php.

Member Function Documentation

◆ getExportData()

static ilRating::getExportData (   $a_obj_id,
  $a_obj_type,
array  $a_category_ids = null 
)
static

Get export data.

Parameters
int$a_obj_id
string$a_obj_type
array$a_category_ids
Returns
array

Definition at line 186 of file class.ilRating.php.

References $res, and $row.

Referenced by ilRatingCategoryGUI\export().

187  {
188  global $ilDB;
189 
190  $res = array();
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").
195  " ORDER BY tstamp";
196  if($a_category_ids)
197  {
198  $q .= " AND ".$ilDB->in("category_id", $a_category_ids, "", "integer");
199  }
200  $set = $ilDB->query($q);
201  while($row = $ilDB->fetchAssoc($set))
202  {
203  $res[] = $row;
204  }
205  return $res;
206  }
+ Here is the caller graph for this function:

◆ getOverallRatingForObject()

static ilRating::getOverallRatingForObject (   $a_obj_id,
  $a_obj_type,
  $a_sub_obj_id,
  $a_sub_obj_type,
  $a_category_id = null 
)
static

Get overall rating for an object.

Parameters
int$a_obj_idObject ID
string$a_obj_typeObject Type
int$a_sub_obj_idSubobject ID
string$a_sub_obj_typeSubobject Type
int$a_category_idCategory ID

Definition at line 141 of file class.ilRating.php.

Referenced by ilDataCollectionRatingField\getExportValue(), ilRatingGUI\getHTML(), ilDataCollectionRatingField\getValue(), and ilRatingGUI\renderDetails().

142  {
143  global $ilDB;
144 
145  if(is_array(self::$list_data))
146  {
147  return self::$list_data["all"][$a_obj_type."/".$a_obj_id];
148  }
149 
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)
156  {
157  $q .= " AND category_id = ".$ilDB->quote((int) $a_category_id, "integer");
158  }
159  $q .= " GROUP BY user_id";
160  $set = $ilDB->query($q);
161  $avg = $cnt = 0;
162  while($rec = $ilDB->fetchAssoc($set))
163  {
164  $cnt++;
165  $avg += $rec["av"];
166  }
167  if ($cnt > 0)
168  {
169  $avg = $avg/$cnt;
170  }
171  else
172  {
173  $avg = 0;
174  }
175  return array("cnt" => $cnt, "avg" => $avg);
176  }
+ Here is the caller graph for this function:

◆ getRatingForUserAndObject()

static ilRating::getRatingForUserAndObject (   $a_obj_id,
  $a_obj_type,
  $a_sub_obj_id,
  $a_sub_obj_type,
  $a_user_id,
  $a_category_id = null 
)
static

Get rating for a user and an object.

Parameters
int$a_obj_idObject ID
string$a_obj_typeObject Type
int$a_sub_obj_idSubobject ID
string$a_sub_obj_typeSubobject Type
int$a_user_idUser ID
int$a_category_idCategory ID

Definition at line 107 of file class.ilRating.php.

Referenced by ilExAssignment\countGivenFeedback(), ilExAssignment\getAllPeerReviews(), ilRatingGUI\getHTML(), ilExAssignmentPeerReviewTableGUI\getItems(), ilExAssignment\getPeerReviewsByPeerId(), and ilRatingGUI\renderDetails().

109  {
110  global $ilDB;
111 
112  if(is_array(self::$list_data))
113  {
114  return self::$list_data["user"][$a_obj_type."/".$a_obj_id];
115  }
116 
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)
124  {
125  $q .= " AND category_id = ".$ilDB->quote((int) $a_category_id, "integer");
126  }
127  $set = $ilDB->query($q);
128  $rec = $ilDB->fetchAssoc($set);
129  return $rec["av"];
130  }
+ Here is the caller graph for this function:

◆ hasRatingInListGUI()

static ilRating::hasRatingInListGUI (   $a_obj_id,
  $a_obj_type 
)
static

Definition at line 296 of file class.ilRating.php.

Referenced by ilObjectListGUI\getListItemHTML().

297  {
298  return isset(self::$list_data["all"][$a_obj_type."/".$a_obj_id]);
299  }
+ Here is the caller graph for this function:

◆ preloadListGUIData()

static ilRating::preloadListGUIData ( array  $a_obj_ids)
static

Preload rating data for list guis.

Parameters
array$a_obj_ids

Definition at line 213 of file class.ilRating.php.

References $ilUser, $res, and $row.

Referenced by ilObjectListGUIPreloader\preload().

214  {
215  global $ilDB, $ilUser;
216 
217  $tmp = $res = $tmp_user = $res_user = array();
218 
219  // collapse by categories
220  $q = "SELECT obj_id, obj_type, user_id, AVG(rating) av".
221  " FROM il_rating".
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))
227  {
228  $tmp[$rec["obj_type"]."/".$rec["obj_id"]][$rec["user_id"]] = (float)$rec["av"];
229  if($rec["user_id"] == $ilUser->getId())
230  {
231  // add final average to user result (no sub-objects)
232  $res_user[$rec["obj_type"]."/".$rec["obj_id"]] = (float)$rec["av"];
233  }
234  }
235 
236  // average for main objects without sub-objects
237  foreach($tmp as $obj_id => $votes)
238  {
239  $res[$obj_id] = array("avg"=>array_sum($votes)/sizeof($votes),
240  "cnt"=>sizeof($votes));
241  }
242 
243  // file/wiki/lm rating toggles
244 
245  $set = $ilDB->query("SELECT file_id, rating".
246  " FROM file_data".
247  " WHERE ".$ilDB->in("file_id", $a_obj_ids, "", integer));
248  while($row = $ilDB->fetchAssoc($set))
249  {
250  $id = "file/".$row["file_id"];
251  if($row["rating"] && !isset($res[$id]))
252  {
253  $res[$id] = array("avg"=>0, "cnt"=>0);
254  }
255  else if(!$row["rating"] && isset($res[$id]))
256  {
257  unset($res[$id]);
258  }
259  }
260 
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))
265  {
266  $id = "wiki/".$row["id"];
267  if($row["rating_overall"] && !isset($res[$id]))
268  {
269  $res[$id] = array("avg"=>0, "cnt"=>0);
270  }
271  else if(!$row["rating_overall"] && isset($res[$id]))
272  {
273  unset($res[$id]);
274  }
275  }
276 
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))
281  {
282  $id = "lm/".$row["id"];
283  if($row["rating"] && !isset($res[$id]))
284  {
285  $res[$id] = array("avg"=>0, "cnt"=>0);
286  }
287  else if(!$row["rating"] && isset($res[$id]))
288  {
289  unset($res[$id]);
290  }
291  }
292 
293  self::$list_data = array("all"=>$res, "user"=>$res_user);
294  }
global $ilUser
Definition: imgupload.php:15
+ Here is the caller graph for this function:

◆ resetRatingForUserAndObject()

static ilRating::resetRatingForUserAndObject (   $a_obj_id,
  $a_obj_type,
  $a_sub_obj_id,
  $a_sub_obj_type,
  $a_user_id 
)
static

Reset rating for a user and an object.

Parameters
int$a_obj_idObject ID
string$a_obj_typeObject Type
int$a_sub_obj_idSubobject ID
string$a_sub_obj_typeSubobject Type
int$a_user_idUser ID

Definition at line 83 of file class.ilRating.php.

Referenced by ilRatingGUI\resetUserRating(), and ilLMPresentationGUI\updatePageRating().

85  {
86  global $ilDB;
87 
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));
94  }
+ Here is the caller graph for this function:

◆ writeRatingForUserAndObject()

static ilRating::writeRatingForUserAndObject (   $a_obj_id,
  $a_obj_type,
  $a_sub_obj_id,
  $a_sub_obj_type,
  $a_user_id,
  $a_rating,
  $a_category_id = 0 
)
static

Write rating for a user and an object.

Parameters
int$a_obj_idObject ID
string$a_obj_typeObject Type
int$a_sub_obj_idSubobject ID
string$a_sub_obj_typeSubobject Type
int$a_user_idUser ID
int$a_ratingRating
int$a_category_idCategory ID

Definition at line 30 of file class.ilRating.php.

Referenced by ilRatingGUI\saveRating(), ilLMPresentationGUI\updatePageRating(), and ilObjExerciseGUI\updatePeerReviewCommentsObject().

32  {
33  global $ilDB;
34 
35  if ($a_user_id == ANONYMOUS_USER_ID)
36  {
37  return;
38  }
39 
40  if($a_category_id)
41  {
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"));
49  }
50 
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"));
58 
59  if((int)$a_rating)
60  {
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").")");
71  }
72  }
+ Here is the caller graph for this function:

Field Documentation

◆ $list_data

ilRating::$list_data
staticprotected

Definition at line 17 of file class.ilRating.php.


The documentation for this class was generated from the following file: