| 68 | | $user_id = Dba::escape($GLOBALS['user']->id); |
| 69 | | |
| 70 | | $idlist = '(' . implode(',', $ids) . ')'; |
| 71 | | $sql = "SELECT `rating`, `object_id`,`rating`.`rating` FROM `rating` WHERE `user`='$user_id' AND `object_id` IN $idlist " . |
| 72 | | "AND `object_type`='$type'"; |
| 73 | | $db_results = Dba::read($sql); |
| 74 | | |
| 75 | | while ($row = Dba::fetch_assoc($db_results)) { |
| 76 | | $user[$row['object_id']] = $row['rating']; |
| 77 | | } |
| 78 | | |
| 79 | | $sql = "SELECT `rating`,`object_id` FROM `rating` WHERE `object_id` IN $idlist AND `object_type`='$type'"; |
| 80 | | $db_results = Dba::read($sql); |
| 81 | | |
| 82 | | while ($row = Dba::fetch_assoc($db_results)) { |
| 83 | | $rating[$row['object_id']]['rating'] += $row['rating']; |
| 84 | | $rating[$row['object_id']]['total']++; |
| 85 | | } |
| 86 | | |
| 87 | | foreach ($ids as $id) { |
| 88 | | parent::add_to_cache('rating_' . $type . '_user',$id,intval($user[$id])); |
| 89 | | |
| 90 | | // Do the bit of math required to store this |
| 91 | | if (!isset($rating[$id])) { |
| 92 | | $entry = array('average'=>'0','percise'=>'0'); |
| | 68 | if ($ids) { |
| | 69 | $user_id = Dba::escape($GLOBALS['user']->id); |
| | 70 | |
| | 71 | $idlist = '(' . implode(',', $ids) . ')'; |
| | 72 | $sql = "SELECT `rating`, `object_id`,`rating`.`rating` FROM `rating` WHERE `user`='$user_id' AND `object_id` IN $idlist " . |
| | 73 | "AND `object_type`='$type'"; |
| | 74 | $db_results = Dba::read($sql); |
| | 75 | |
| | 76 | while ($row = Dba::fetch_assoc($db_results)) { |
| | 77 | $user[$row['object_id']] = $row['rating']; |
| | 78 | } |
| | 79 | |
| | 80 | $sql = "SELECT `rating`,`object_id` FROM `rating` WHERE `object_id` IN $idlist AND `object_type`='$type'"; |
| | 81 | $db_results = Dba::read($sql); |
| | 82 | |
| | 83 | while ($row = Dba::fetch_assoc($db_results)) { |
| | 84 | $rating[$row['object_id']]['rating'] += $row['rating']; |
| | 85 | $rating[$row['object_id']]['total']++; |
| | 86 | } |
| | 87 | |
| | 88 | foreach ($ids as $id) { |
| | 89 | parent::add_to_cache('rating_' . $type . '_user',$id,intval($user[$id])); |
| | 90 | |
| | 91 | // Do the bit of math required to store this |
| | 92 | if (!isset($rating[$id])) { |
| | 93 | $entry = array('average'=>'0','percise'=>'0'); |
| | 94 | } |
| | 95 | else { |
| | 96 | $average = round($rating[$id]['rating']/$rating[$id]['total'],1); |
| | 97 | $entry = array('average'=>floor($average),'percise'=>$average); |
| | 98 | } |
| | 99 | |
| | 100 | parent::add_to_cache('rating_' . $type . '_all',$id,$entry); |