ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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=null, $a_sub_obj_type=null, $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 194 of file class.ilRating.php.

References $ilDB, $res, $row, and array.

Referenced by ilRatingCategoryGUI\export().

195  {
196  global $ilDB;
197 
198  $res = array();
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").
203  " ORDER BY tstamp";
204  if($a_category_ids)
205  {
206  $q .= " AND ".$ilDB->in("category_id", $a_category_ids, "", "integer");
207  }
208  $set = $ilDB->query($q);
209  while($row = $ilDB->fetchAssoc($set))
210  {
211  $res[] = $row;
212  }
213  return $res;
214  }
Create styles array
The data for the language used.
global $ilDB
+ Here is the caller graph for this function:

◆ getOverallRatingForObject()

static ilRating::getOverallRatingForObject (   $a_obj_id,
  $a_obj_type,
  $a_sub_obj_id = null,
  $a_sub_obj_type = null,
  $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.

References $ilDB, and array.

Referenced by ilWikiStat\getAverageRating(), ilDclRatingRecordFieldModel\getExportValue(), ilRatingGUI\getHTML(), ilDclRatingRecordFieldModel\getValue(), ilObjForumGUI\isTopLevelReplyCommand(), 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".
151  " WHERE obj_id = ".$ilDB->quote((int) $a_obj_id, "integer").
152  " AND obj_type = ".$ilDB->quote($a_obj_type, "text");
153  if($a_sub_obj_id)
154  {
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);
157  }
158  else
159  {
160  $q .= " AND sub_obj_type = ".$ilDB->quote("-", "text"); // #13913
161  }
162 
163  if ($a_category_id !== null)
164  {
165  $q .= " AND category_id = ".$ilDB->quote((int) $a_category_id, "integer");
166  }
167  $q .= " GROUP BY user_id";
168  $set = $ilDB->query($q);
169  $avg = $cnt = 0;
170  while($rec = $ilDB->fetchAssoc($set))
171  {
172  $cnt++;
173  $avg += $rec["av"];
174  }
175  if ($cnt > 0)
176  {
177  $avg = $avg/$cnt;
178  }
179  else
180  {
181  $avg = 0;
182  }
183  return array("cnt" => $cnt, "avg" => $avg);
184  }
Create styles array
The data for the language used.
global $ilDB
+ 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.

References $ilDB.

Referenced by ilRatingGUI\getHTML(), ilExcCriteriaRating\hasValue(), 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  }
global $ilDB
+ Here is the caller graph for this function:

◆ hasRatingInListGUI()

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

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

Referenced by ilObjectListGUI\getListItemHTML().

305  {
306  return isset(self::$list_data["all"][$a_obj_type."/".$a_obj_id]);
307  }
+ 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 221 of file class.ilRating.php.

References $ilDB, $ilUser, $res, $row, and array.

Referenced by ilObjectListGUIPreloader\preload().

222  {
223  global $ilDB, $ilUser;
224 
225  $tmp = $res = $tmp_user = $res_user = array();
226 
227  // collapse by categories
228  $q = "SELECT obj_id, obj_type, user_id, AVG(rating) av".
229  " FROM il_rating".
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))
235  {
236  $tmp[$rec["obj_type"]."/".$rec["obj_id"]][$rec["user_id"]] = (float)$rec["av"];
237  if($rec["user_id"] == $ilUser->getId())
238  {
239  // add final average to user result (no sub-objects)
240  $res_user[$rec["obj_type"]."/".$rec["obj_id"]] = (float)$rec["av"];
241  }
242  }
243 
244  // average for main objects without sub-objects
245  foreach($tmp as $obj_id => $votes)
246  {
247  $res[$obj_id] = array("avg"=>array_sum($votes)/sizeof($votes),
248  "cnt"=>sizeof($votes));
249  }
250 
251  // file/wiki/lm rating toggles
252 
253  $set = $ilDB->query("SELECT file_id, rating".
254  " FROM file_data".
255  " WHERE ".$ilDB->in("file_id", $a_obj_ids, "", integer));
256  while($row = $ilDB->fetchAssoc($set))
257  {
258  $id = "file/".$row["file_id"];
259  if($row["rating"] && !isset($res[$id]))
260  {
261  $res[$id] = array("avg"=>0, "cnt"=>0);
262  }
263  else if(!$row["rating"] && isset($res[$id]))
264  {
265  unset($res[$id]);
266  }
267  }
268 
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))
273  {
274  $id = "wiki/".$row["id"];
275  if($row["rating_overall"] && !isset($res[$id]))
276  {
277  $res[$id] = array("avg"=>0, "cnt"=>0);
278  }
279  else if(!$row["rating_overall"] && isset($res[$id]))
280  {
281  unset($res[$id]);
282  }
283  }
284 
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))
289  {
290  $id = "lm/".$row["id"];
291  if($row["rating"] && !isset($res[$id]))
292  {
293  $res[$id] = array("avg"=>0, "cnt"=>0);
294  }
295  else if(!$row["rating"] && isset($res[$id]))
296  {
297  unset($res[$id]);
298  }
299  }
300 
301  self::$list_data = array("all"=>$res, "user"=>$res_user);
302  }
$ilUser
Definition: imgupload.php:18
Create styles array
The data for the language used.
global $ilDB
+ 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.

References $ilDB.

Referenced by ilExcCriteriaRating\resetReview(), 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  }
global $ilDB
+ 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.

References $ilDB, and time.

Referenced by ilRatingGUI\saveRating(), ilExcCriteriaRating\updateFromAjax(), and ilLMPresentationGUI\updatePageRating().

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  }
global $ilDB
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
+ 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: