ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 211 of file class.ilRating.php.

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

Referenced by ilRatingCategoryGUI\export().

212  {
213  global $DIC;
214 
215  $ilDB = $DIC->database();
216 
217  $res = array();
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") .
222  " ORDER BY tstamp";
223  if ($a_category_ids) {
224  $q .= " AND " . $ilDB->in("category_id", $a_category_ids, "", "integer");
225  }
226  $set = $ilDB->query($q);
227  while ($row = $ilDB->fetchAssoc($set)) {
228  $res[] = $row;
229  }
230  return $res;
231  }
global $DIC
Definition: saml.php:7
foreach($_POST as $key=> $value) $res
$row
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 165 of file class.ilRating.php.

References $DIC, and $ilDB.

Referenced by ilObjForumGUI\executeCommand(), ilWikiStat\getAverageRating(), ilDclRatingRecordFieldModel\getExportValue(), ilRatingGUI\getHTML(), ilDclRatingRecordFieldModel\getValue(), and ilRatingGUI\renderDetails().

166  {
167  global $DIC;
168 
169  $ilDB = $DIC->database();
170 
171  if (is_array(self::$list_data)) {
172  return self::$list_data["all"][$a_obj_type . "/" . $a_obj_id];
173  }
174 
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");
178  if ($a_sub_obj_id) {
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);
181  } else {
182  $q .= " AND sub_obj_type = " . $ilDB->quote("-", "text"); // #13913
183  }
184 
185  if ($a_category_id !== null) {
186  $q .= " AND category_id = " . $ilDB->quote((int) $a_category_id, "integer");
187  }
188  $q .= " GROUP BY user_id";
189  $set = $ilDB->query($q);
190  $avg = $cnt = 0;
191  while ($rec = $ilDB->fetchAssoc($set)) {
192  $cnt++;
193  $avg += $rec["av"];
194  }
195  if ($cnt > 0) {
196  $avg = $avg / $cnt;
197  } else {
198  $avg = 0;
199  }
200  return array("cnt" => $cnt, "avg" => $avg);
201  }
global $DIC
Definition: saml.php:7
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 126 of file class.ilRating.php.

References $DIC, and $ilDB.

Referenced by ilExerciseManagementCollectFilesJob\addCriteriaToExcel(), ilRatingGUI\getHTML(), ilExcCriteriaRating\hasValue(), and ilRatingGUI\renderDetails().

133  {
134  global $DIC;
135 
136  $ilDB = $DIC->database();
137 
138  if (is_array(self::$list_data)) {
139  return self::$list_data["user"][$a_obj_type . "/" . $a_obj_id];
140  }
141 
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");
150  }
151  $set = $ilDB->query($q);
152  $rec = $ilDB->fetchAssoc($set);
153  return $rec["av"];
154  }
global $DIC
Definition: saml.php:7
global $ilDB
+ Here is the caller graph for this function:

◆ hasRatingInListGUI()

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

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

Referenced by ilObjectListGUI\getListItemHTML().

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

References $DIC, $id, $ilDB, $ilUser, $res, and $row.

Referenced by ilObjectListGUIPreloader\preload().

239  {
240  global $DIC;
241 
242  $ilDB = $DIC->database();
243  $ilUser = $DIC->user();
244 
245  $tmp = $res = $tmp_user = $res_user = array();
246 
247  // collapse by categories
248  $q = "SELECT obj_id, obj_type, user_id, AVG(rating) av" .
249  " FROM il_rating" .
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()) {
257  // add final average to user result (no sub-objects)
258  $res_user[$rec["obj_type"] . "/" . $rec["obj_id"]] = (float) $rec["av"];
259  }
260  }
261 
262  // average for main objects without sub-objects
263  foreach ($tmp as $obj_id => $votes) {
264  $res[$obj_id] = array("avg" => array_sum($votes) / sizeof($votes),
265  "cnt" => sizeof($votes));
266  }
267 
268  // file/wiki/lm rating toggles
269 
270  $set = $ilDB->query("SELECT file_id, rating" .
271  " FROM file_data" .
272  " WHERE " . $ilDB->in("file_id", $a_obj_ids, "", 'integer'));
273  while ($row = $ilDB->fetchAssoc($set)) {
274  $id = "file/" . $row["file_id"];
275  if ($row["rating"] && !isset($res[$id])) {
276  $res[$id] = array("avg" => 0, "cnt" => 0);
277  } elseif (!$row["rating"] && isset($res[$id])) {
278  unset($res[$id]);
279  }
280  }
281 
282  $set = $ilDB->query("SELECT id, rating_overall" .
283  " FROM il_wiki_data" .
284  " WHERE " . $ilDB->in("id", $a_obj_ids, "", 'integer'));
285  while ($row = $ilDB->fetchAssoc($set)) {
286  $id = "wiki/" . $row["id"];
287  if ($row["rating_overall"] && !isset($res[$id])) {
288  $res[$id] = array("avg" => 0, "cnt" => 0);
289  } elseif (!$row["rating_overall"] && isset($res[$id])) {
290  unset($res[$id]);
291  }
292  }
293 
294  $set = $ilDB->query("SELECT id, rating" .
295  " FROM content_object" .
296  " WHERE " . $ilDB->in("id", $a_obj_ids, "", 'integer'));
297  while ($row = $ilDB->fetchAssoc($set)) {
298  $id = "lm/" . $row["id"];
299  if ($row["rating"] && !isset($res[$id])) {
300  $res[$id] = array("avg" => 0, "cnt" => 0);
301  } elseif (!$row["rating"] && isset($res[$id])) {
302  unset($res[$id]);
303  }
304  }
305 
306  self::$list_data = array("all" => $res, "user" => $res_user);
307  }
global $DIC
Definition: saml.php:7
if(!array_key_exists('StateId', $_REQUEST)) $id
foreach($_POST as $key=> $value) $res
$ilUser
Definition: imgupload.php:18
$row
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 96 of file class.ilRating.php.

References $DIC, and $ilDB.

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

102  {
103  global $DIC;
104 
105  $ilDB = $DIC->database();
106 
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));
113  }
global $DIC
Definition: saml.php:7
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 $DIC, and $ilDB.

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

38  {
39  global $DIC;
40 
41  $ilDB = $DIC->database();
42 
43  if ($a_rating < 0) {
44  $a_rating = 0;
45  }
46 
47  if ($a_rating > 5) {
48  $a_rating = 5;
49  }
50 
51  if ($a_user_id == ANONYMOUS_USER_ID) {
52  return;
53  }
54 
55  if ($a_category_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"));
63  }
64 
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"));
72 
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") . "," .
83  $ilDB->quote(time(), "integer") . ")");
84  }
85  }
global $DIC
Definition: saml.php:7
global $ilDB
+ 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: