summaryrefslogtreecommitdiffstats
path: root/lib/class/rating.class.php
diff options
context:
space:
mode:
authormomo-i <momo-i@ampache>2008-09-03 00:06:29 +0000
committermomo-i <momo-i@ampache>2008-09-03 00:06:29 +0000
commit7a6e4825d9738bd4c51deeb2eff942f2ffcbc5c5 (patch)
tree2636a9e425d21e6fe59c39ee253cb46b7742f22c /lib/class/rating.class.php
parentf1866160fd048035f9f0f729f3d20283d64aa4a7 (diff)
downloadampache-7a6e4825d9738bd4c51deeb2eff942f2ffcbc5c5.tar.gz
ampache-7a6e4825d9738bd4c51deeb2eff942f2ffcbc5c5.tar.bz2
ampache-7a6e4825d9738bd4c51deeb2eff942f2ffcbc5c5.zip
Diffstat (limited to 'lib/class/rating.class.php')
-rw-r--r--lib/class/rating.class.php62
1 files changed, 33 insertions, 29 deletions
diff --git a/lib/class/rating.class.php b/lib/class/rating.class.php
index 5d2f9bf2..d1b34822 100644
--- a/lib/class/rating.class.php
+++ b/lib/class/rating.class.php
@@ -65,41 +65,45 @@ class Rating extends database_object {
*/
public static function build_cache($type, $ids) {
- $user_id = Dba::escape($GLOBALS['user']->id);
+ if ($ids) {
+ $user_id = Dba::escape($GLOBALS['user']->id);
- $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);
+ $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'];
- }
+ 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);
- }
+ 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);
- }
+ parent::add_to_cache('rating_' . $type . '_all',$id,$entry);
+ }
- return true;
+ return true;
+ } else {
+ return false;
+ }
} // build_cache