diff options
author | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2005-12-27 01:31:18 +0000 |
---|---|---|
committer | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2005-12-27 01:31:18 +0000 |
commit | 534f9da3d2b2644c2700050c76657d003878ed58 (patch) | |
tree | 87d0a6aa736ed0d6b2d398d0d9d3534ca7fecc9f /lib/class/rating.class.php | |
parent | 6b0b77f12b6873204bfd73a250621115b1f539a0 (diff) | |
download | ampache-534f9da3d2b2644c2700050c76657d003878ed58.tar.gz ampache-534f9da3d2b2644c2700050c76657d003878ed58.tar.bz2 ampache-534f9da3d2b2644c2700050c76657d003878ed58.zip |
fixed rating system if using non-flash
Diffstat (limited to 'lib/class/rating.class.php')
-rw-r--r-- | lib/class/rating.class.php | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/lib/class/rating.class.php b/lib/class/rating.class.php index 4a513421..06344e1c 100644 --- a/lib/class/rating.class.php +++ b/lib/class/rating.class.php @@ -90,10 +90,15 @@ class Rating { if ($total > 0) { $average = floor($total/$i); + $this->rating = $average; } - - $this->rating = $average; - + elseif ($i >= '1' AND $total == '0') { + $this->rating = '-1'; + } + else { + $this->rating = '0'; + } + return $average; } // get_average @@ -104,9 +109,25 @@ class Rating { * This uses the currently logged in user for the 'user' who is rating * the object. Returns true on success, false on failure */ - function set_rating() { + function set_rating($score) { + + $score = sql_escape($score); + + /* Check if it exists */ + $sql = "SELECT id FROM ratings WHERE object_id='$this->id' AND object_type='$this->type' AND `user`='" . sql_escape($GLOBALS['user']->username) . "'"; + $db_results = mysql_query($sql, dbh()); + if ($existing = mysql_fetch_assoc($db_results)) { + $sql = "UPDATE ratings SET user_rating='$score' WHERE id='" . $existing['id'] . "'"; + $db_results = mysql_query($sql, dbh()); + } + else { + $sql = "INSERT INTO ratings (`object_id`,`object_type`,`user_rating`,`user`) VALUES " . + " ('$this->id','$this->type','$score','" . sql_escape($GLOBALS['user']->username) . "')"; + $db_results = mysql_query($sql, dbh()); + } + return true; } // set_rating |