summaryrefslogtreecommitdiffstats
path: root/lib/class/rating.class.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/class/rating.class.php')
-rw-r--r--lib/class/rating.class.php64
1 files changed, 31 insertions, 33 deletions
diff --git a/lib/class/rating.class.php b/lib/class/rating.class.php
index d1b34822..045be750 100644
--- a/lib/class/rating.class.php
+++ b/lib/class/rating.class.php
@@ -65,45 +65,43 @@ class Rating extends database_object {
*/
public static function build_cache($type, $ids) {
- if ($ids) {
- $user_id = Dba::escape($GLOBALS['user']->id);
+ if (!is_array($ids) OR !count($ids)) { return false; }
- $idlist = '(' . implode(',', $ids) . ')';
- $sql = "SELECT `rating`, `object_id`,`rating`.`rating` FROM `rating` WHERE `user`='$user_id' AND `object_id` IN $idlist " .
- "AND `object_type`='$type'";
- $db_results = Dba::read($sql);
+ $user_id = Dba::escape($GLOBALS['user']->id);
- while ($row = Dba::fetch_assoc($db_results)) {
- $user[$row['object_id']] = $row['rating'];
- }
+ $idlist = '(' . implode(',', $ids) . ')';
+ $sql = "SELECT `rating`, `object_id`,`rating`.`rating` FROM `rating` WHERE `user`='$user_id' AND `object_id` IN $idlist " .
+ "AND `object_type`='$type'";
+ $db_results = Dba::read($sql);
+
+ while ($row = Dba::fetch_assoc($db_results)) {
+ $user[$row['object_id']] = $row['rating'];
+ }
- $sql = "SELECT `rating`,`object_id` FROM `rating` WHERE `object_id` IN $idlist AND `object_type`='$type'";
- $db_results = Dba::read($sql);
+ $sql = "SELECT `rating`,`object_id` FROM `rating` WHERE `object_id` IN $idlist AND `object_type`='$type'";
+ $db_results = Dba::read($sql);
- while ($row = Dba::fetch_assoc($db_results)) {
- $rating[$row['object_id']]['rating'] += $row['rating'];
- $rating[$row['object_id']]['total']++;
- }
-
- foreach ($ids as $id) {
- parent::add_to_cache('rating_' . $type . '_user',$id,intval($user[$id]));
-
- // Do the bit of math required to store this
- if (!isset($rating[$id])) {
- $entry = array('average'=>'0','percise'=>'0');
- }
- else {
- $average = round($rating[$id]['rating']/$rating[$id]['total'],1);
- $entry = array('average'=>floor($average),'percise'=>$average);
- }
-
- parent::add_to_cache('rating_' . $type . '_all',$id,$entry);
+ while ($row = Dba::fetch_assoc($db_results)) {
+ $rating[$row['object_id']]['rating'] += $row['rating'];
+ $rating[$row['object_id']]['total']++;
+ }
+
+ foreach ($ids as $id) {
+ parent::add_to_cache('rating_' . $type . '_user',$id,intval($user[$id]));
+
+ // Do the bit of math required to store this
+ if (!isset($rating[$id])) {
+ $entry = array('average'=>'0','percise'=>'0');
+ }
+ else {
+ $average = round($rating[$id]['rating']/$rating[$id]['total'],1);
+ $entry = array('average'=>floor($average),'percise'=>$average);
}
+
+ parent::add_to_cache('rating_' . $type . '_all',$id,$entry);
+ }
- return true;
- } else {
- return false;
- }
+ return true;
} // build_cache