summaryrefslogtreecommitdiffstats
path: root/lib/class/rating.class.php
diff options
context:
space:
mode:
authorPaul 'flowerysong' Arthur <flowerysong00@yahoo.com>2010-03-14 20:14:52 +0000
committerPaul 'flowerysong' Arthur <flowerysong00@yahoo.com>2010-03-14 20:14:52 +0000
commit1cb0983ed04c65e06d502ae2ac9ed6d5e31d70dc (patch)
tree54655ff3e692a71a17f1d37cd97374b263557ca1 /lib/class/rating.class.php
parentef48bf3fbdca2a4d25f5d025f4c6ad23905e5369 (diff)
downloadampache-1cb0983ed04c65e06d502ae2ac9ed6d5e31d70dc.tar.gz
ampache-1cb0983ed04c65e06d502ae2ac9ed6d5e31d70dc.tar.bz2
ampache-1cb0983ed04c65e06d502ae2ac9ed6d5e31d70dc.zip
Cosmetics: remove trailing whitespace
Diffstat (limited to 'lib/class/rating.class.php')
-rw-r--r--lib/class/rating.class.php158
1 files changed, 79 insertions, 79 deletions
diff --git a/lib/class/rating.class.php b/lib/class/rating.class.php
index f5af5519..5c2bb3e9 100644
--- a/lib/class/rating.class.php
+++ b/lib/class/rating.class.php
@@ -23,7 +23,7 @@
/**
* Rating class
* This is an amalgamation(sp?) of code from SoundOfEmotion
- * to track ratings for songs, albums and artists.
+ * to track ratings for songs, albums and artists.
*/
class Rating extends database_object {
@@ -40,21 +40,21 @@ class Rating extends database_object {
* This is run every time a new object is created, it requires
* the id and type of object that we need to pull the raiting for
*/
- public function __construct($id,$type) {
+ public function __construct($id,$type) {
$this->id = intval($id);
$this->type = Dba::escape($type);
// Check for the users rating
- if ($rating = $this->get_user($GLOBALS['user']->id)) {
+ if ($rating = $this->get_user($GLOBALS['user']->id)) {
$this->rating = $rating;
$this->preciserating = $rating;
- }
- else {
+ }
+ else {
$this->get_average();
}
-
- return true;
+
+ return true;
} // Constructor
@@ -65,44 +65,44 @@ class Rating extends database_object {
* //FIXME: Improve logic so that misses get cached as average
*/
public static function build_cache($type, $ids) {
-
+
if (!is_array($ids) OR !count($ids)) { return false; }
- $user_id = Dba::escape($GLOBALS['user']->id);
+ $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 " .
+ $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'];
+ $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);
-
- 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]));
+
+ $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);
- }
-
- return true;
+ 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;
} // build_cache
@@ -112,22 +112,22 @@ class Rating extends database_object {
* in user. It returns the value
*/
public function get_user($user_id) {
-
- $id = intval($this->id);
-
- if (parent::is_cached('rating_' . $this->type . '_user',$id)) {
- return parent::get_from_cache('rating_' . $this->type . '_user',$id);
- }
- $user_id = Dba::escape($user_id);
+ $id = intval($this->id);
+
+ if (parent::is_cached('rating_' . $this->type . '_user',$id)) {
+ return parent::get_from_cache('rating_' . $this->type . '_user',$id);
+ }
+
+ $user_id = Dba::escape($user_id);
$sql = "SELECT `rating` FROM `rating` WHERE `user`='$user_id' AND `object_id`='$id' AND `object_type`='$this->type'";
$db_results = Dba::read($sql);
-
+
$results = Dba::fetch_assoc($db_results);
- parent::add_to_cache('rating_' . $this->type . '_user',$id,$results['rating']);
-
+ parent::add_to_cache('rating_' . $this->type . '_user',$id,$results['rating']);
+
return $results['rating'];
} // get_user
@@ -136,79 +136,79 @@ class Rating extends database_object {
* get_average
* Get the users average rating this is based off the floor'd average
* of what everyone has rated this album as. This is shown if there
- * is no personal rating, and used for random play mojo. It sets
+ * is no personal rating, and used for random play mojo. It sets
* $this->average_rating and returns the value
*/
- public function get_average() {
+ public function get_average() {
- $id = intval($this->id);
+ $id = intval($this->id);
- if (parent::is_cached('rating_' . $this->type . '_all',$id)) {
- $data = parent::get_from_cache('rating_' . $this->type . '_user',$id);
- $this->rating = $data['rating'];
- $this->perciserating = $data['percise'];
- return true;
- }
+ if (parent::is_cached('rating_' . $this->type . '_all',$id)) {
+ $data = parent::get_from_cache('rating_' . $this->type . '_user',$id);
+ $this->rating = $data['rating'];
+ $this->perciserating = $data['percise'];
+ return true;
+ }
$sql = "SELECT `rating` FROM `rating` WHERE `object_id`='$id' AND `object_type`='$this->type'";
$db_results = Dba::read($sql);
$i = 0;
- while ($r = Dba::fetch_assoc($db_results)) {
+ while ($r = Dba::fetch_assoc($db_results)) {
$i++;
$total += $r['rating'];
} // while we're pulling results
- if ($total > 0) {
+ if ($total > 0) {
$average = round($total/$i, 1);
}
- elseif ($i >= '1' AND $total == '0') {
+ elseif ($i >= '1' AND $total == '0') {
$average = -1;
}
- else {
+ else {
$average = 0;
}
-
+
$this->preciserating = $average;
$this->rating = floor($average);
-
+
return $this->rating;
} // get_average
/**
* set_rating
- * This function sets a rating for the current $this object.
+ * This function sets a rating for the current $this object.
* This uses the currently logged in user for the 'user' who is rating
* the object. Returns true on success, false on failure
*/
- public function set_rating($score) {
-
+ public function set_rating($score) {
+
$score = Dba::escape($score);
// If score is -1, then remove rating
if ($score == '-1') {
- $sql = "DELETE FROM `rating` WHERE `object_id`='$this->id' AND `object_type`='$this->type' " .
+ $sql = "DELETE FROM `rating` WHERE `object_id`='$this->id' AND `object_type`='$this->type' " .
"AND `user`='" . Dba::escape($GLOBALS['user']->id) . "'";
$db_results = Dba::read($sql);
return true;
}
/* Check if it exists */
- $sql = "SELECT `id` FROM `rating` WHERE `object_id`='$this->id' AND `object_type`='$this->type' " .
+ $sql = "SELECT `id` FROM `rating` WHERE `object_id`='$this->id' AND `object_type`='$this->type' " .
"AND `user`='" . Dba::escape($GLOBALS['user']->id) . "'";
$db_results = Dba::read($sql);
- if ($existing = Dba::fetch_assoc($db_results)) {
+ if ($existing = Dba::fetch_assoc($db_results)) {
$sql = "UPDATE `rating` SET `rating`='$score' WHERE `id`='" . $existing['id'] . "'";
$db_results = Dba::write($sql);
}
- else {
- $sql = "INSERT INTO `rating` (`object_id`,`object_type`,`rating`,`user`) VALUES " .
+ else {
+ $sql = "INSERT INTO `rating` (`object_id`,`object_type`,`rating`,`user`) VALUES " .
" ('$this->id','$this->type','$score','" . $GLOBALS['user']->id . "')";
$db_results = Dba::write($sql);
- }
+ }
return true;
@@ -216,31 +216,31 @@ class Rating extends database_object {
/**
* show
- * This takes an id and a type and displays the rating if ratings are enabled.
+ * This takes an id and a type and displays the rating if ratings are enabled.
*/
- public static function show ($object_id,$type) {
+ public static function show ($object_id,$type) {
// If there aren't ratings don't return anything
- if (!Config::get('ratings')) { return false; }
+ if (!Config::get('ratings')) { return false; }
- $rating = new Rating($object_id,$type);
+ $rating = new Rating($object_id,$type);
- require Config::get('prefix') . '/templates/show_object_rating.inc.php';
+ require Config::get('prefix') . '/templates/show_object_rating.inc.php';
- } // show
+ } // show
/**
* show_static
- * This is a static version of the ratings created by Andy90
+ * This is a static version of the ratings created by Andy90
*/
- public static function show_static ($object_id,$type) {
+ public static function show_static ($object_id,$type) {
// If there aren't ratings don't return anything
- if (!Config::get('ratings')) { return false; }
+ if (!Config::get('ratings')) { return false; }
- $rating = new Rating($object_id,$type);
+ $rating = new Rating($object_id,$type);
- require Config::get('prefix') . '/templates/show_static_object_rating.inc.php';
+ require Config::get('prefix') . '/templates/show_static_object_rating.inc.php';
} // show_static