ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilRating.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2008 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
35 class ilRating
36 {
47  static function writeRatingForUserAndObject($a_obj_id, $a_obj_type, $a_sub_obj_id, $a_sub_obj_type,
48  $a_user_id, $a_rating)
49  {
50  global $ilDB;
51 
52  if ($a_user_id == ANONYMOUS_USER_ID)
53  {
54  return;
55  }
56 
57  $q = "REPLACE INTO il_rating (user_id, obj_id, obj_type,".
58  "sub_obj_id, sub_obj_type, rating) VALUES (".
59  $ilDB->quote($a_user_id).",".
60  $ilDB->quote($a_obj_id).",".
61  $ilDB->quote($a_obj_type).",".
62  $ilDB->quote($a_sub_obj_id).",".
63  $ilDB->quote($a_sub_obj_type).",".
64  $ilDB->quote($a_rating).")";
65  $ilDB->query($q);
66  }
67 
77  static function getRatingForUserAndObject($a_obj_id, $a_obj_type, $a_sub_obj_id, $a_sub_obj_type,
78  $a_user_id)
79  {
80  global $ilDB;
81 
82  $q = "SELECT * FROM il_rating WHERE ".
83  "user_id = ".$ilDB->quote($a_user_id)." AND ".
84  "obj_id = ".$ilDB->quote($a_obj_id)." AND ".
85  "obj_type = ".$ilDB->quote($a_obj_type)." AND ".
86  "sub_obj_id = ".$ilDB->quote($a_sub_obj_id)." AND ".
87  "sub_obj_type = ".$ilDB->quote($a_sub_obj_type);
88  $set = $ilDB->query($q);
89  $rec = $set->fetchRow(DB_FETCHMODE_ASSOC);
90  return $rec["rating"];
91  }
92 
101  static function getOverallRatingForObject($a_obj_id, $a_obj_type, $a_sub_obj_id, $a_sub_obj_type)
102  {
103  global $ilDB;
104 
105  $q = "SELECT count(*) as cnt, AVG(rating) as av FROM il_rating WHERE ".
106  "obj_id = ".$ilDB->quote($a_obj_id)." AND ".
107  "obj_type = ".$ilDB->quote($a_obj_type)." AND ".
108  "sub_obj_id = ".$ilDB->quote($a_sub_obj_id)." AND ".
109  "sub_obj_type = ".$ilDB->quote($a_sub_obj_type);
110  $set = $ilDB->query($q);
111  $rec = $set->fetchRow(DB_FETCHMODE_ASSOC);
112  return array("cnt" => $rec["cnt"], "avg" => $rec["av"]);
113  }
114 
115 }
116 
117 ?>