diff options
author | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2005-12-25 10:04:27 +0000 |
---|---|---|
committer | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2005-12-25 10:04:27 +0000 |
commit | 27158141ee1a14b7d23ae8997d2c41b49fc904d9 (patch) | |
tree | 2180fff67d21ffdbab32f2105cff3c7275b6b511 /lib/class/rating.class.php | |
parent | 5415c2e847032896907946c98d68a254399e4416 (diff) | |
download | ampache-27158141ee1a14b7d23ae8997d2c41b49fc904d9.tar.gz ampache-27158141ee1a14b7d23ae8997d2c41b49fc904d9.tar.bz2 ampache-27158141ee1a14b7d23ae8997d2c41b49fc904d9.zip |
initial ratings mojo, some stylesheet fixes, changed user preferences again and a db update
Diffstat (limited to 'lib/class/rating.class.php')
-rw-r--r-- | lib/class/rating.class.php | 34 |
1 files changed, 30 insertions, 4 deletions
diff --git a/lib/class/rating.class.php b/lib/class/rating.class.php index 6d5199a4..f69e2585 100644 --- a/lib/class/rating.class.php +++ b/lib/class/rating.class.php @@ -32,8 +32,7 @@ class Rating { var $type; // The type of object we want /* Generated vars */ - var $rating; // The rating as set by this user - var $average_rating; // The average rating as set by all users + var $rating; // The average rating as set by all users /** * Constructor @@ -42,19 +41,31 @@ class Rating { */ function Rating($id,$type) { + $this->id = $id; + $this->type = $type; + if (intval($id) > 1) { + $this->get_average(); + } } // Rating /** * get_user * Get the user's rating this is based off the currently logged - * in user. It sets the $this->rating and returns the value + * in user. It returns the value */ - function get_user() { + function get_user($username) { + $username = sql_escape($username); + $sql = "SELECT rating FROM ratings WHERE user='$username' AND object_id='$this->id' AND object_type='$this->type'"; + $db_results = mysql_query($sql, dbh()); + + $results = mysql_fetch_assoc($db_results); + + return $results['rating']; } // get_user @@ -67,6 +78,21 @@ class Rating { */ function get_average() { + $sql = "SELECT rating FROM ratings WHERE object_id='$this->id' AND object_type='$this->type'"; + $db_results = mysql_fetch_assoc($db_results); + + $i = 0; + + while ($r = mysql_fetch_assoc($db_results)) { + $i++; + $total = $r['rating']; + } // while we're pulling results + + $average = floor($total/$i); + + $this->rating = $average; + + return $average; } // get_average |