summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorKarl 'vollmerk' Vollmer <vollmer@ampache.org>2007-08-09 06:35:24 +0000
committerKarl 'vollmerk' Vollmer <vollmer@ampache.org>2007-08-09 06:35:24 +0000
commit699a85cb82f5b8cec9439a29c2f3312ae84b77e0 (patch)
treedad8be2db019f5c1fb51e417c0e9e04853dded72 /lib
parent796c2692d0cfa4641e0c47700371c24a01412ed1 (diff)
downloadampache-699a85cb82f5b8cec9439a29c2f3312ae84b77e0.tar.gz
ampache-699a85cb82f5b8cec9439a29c2f3312ae84b77e0.tar.bz2
ampache-699a85cb82f5b8cec9439a29c2f3312ae84b77e0.zip
fixed some ratings stuff, fixed some searching stuff as well
Diffstat (limited to 'lib')
-rw-r--r--lib/class/browse.class.php6
-rw-r--r--lib/class/dba.class.php1
-rw-r--r--lib/class/rating.class.php12
-rw-r--r--lib/search.php16
4 files changed, 19 insertions, 16 deletions
diff --git a/lib/class/browse.class.php b/lib/class/browse.class.php
index 42152bd2..076b8849 100644
--- a/lib/class/browse.class.php
+++ b/lib/class/browse.class.php
@@ -181,7 +181,7 @@ class Browse {
// First we need to get the SQL statement we are going to run
// This has to run against any possible filters (dependent on type)
$sql = self::get_sql();
-debug_event('sql',$sql,'1');
+
$db_results = Dba::query($sql);
$results = array();
@@ -422,7 +422,9 @@ debug_event('sql',$sql,'1');
// Limit is based on the users preferences
$limit = $GLOBALS['user']->prefs['offset_limit'] ? $GLOBALS['user']->prefs['offset_limit'] : '25';
- $object_ids = array_slice($object_ids,self::$start,$limit);
+ if (count($object_ids) > $start) {
+ $object_ids = array_slice($object_ids,self::$start,$limit);
+ }
switch ($_SESSION['browse']['type']) {
case 'song':
diff --git a/lib/class/dba.class.php b/lib/class/dba.class.php
index 70bd47f5..f396d0f9 100644
--- a/lib/class/dba.class.php
+++ b/lib/class/dba.class.php
@@ -87,6 +87,7 @@ class Dba {
$result = mysql_fetch_assoc($resource);
if (!$result) {
+// debug_event('fetch_assoc',self::$_sql,'1');
return array();
}
diff --git a/lib/class/rating.class.php b/lib/class/rating.class.php
index 1ddd842a..ff7b940d 100644
--- a/lib/class/rating.class.php
+++ b/lib/class/rating.class.php
@@ -64,12 +64,12 @@ class Rating {
$user_id = Dba::escape($user_id);
- $sql = "SELECT `score` FROM `rating` WHERE `user`='$user_id' AND `object_id`='$this->id' AND `object_type`='$this->type'";
+ $sql = "SELECT `rating` FROM `rating` WHERE `user`='$user_id' AND `object_id`='$this->id' AND `object_type`='$this->type'";
$db_results = Dba::query($sql);
$results = Dba::fetch_assoc($db_results);
- return $results['score'];
+ return $results['rating'];
} // get_user
@@ -82,14 +82,14 @@ class Rating {
*/
public function get_average() {
- $sql = "SELECT `score` FROM `rating` WHERE `object_id`='$this->id' AND `object_type`='$this->type'";
+ $sql = "SELECT `rating` FROM `rating` WHERE `object_id`='$this->id' AND `object_type`='$this->type'";
$db_results = Dba::query($sql);
$i = 0;
while ($r = Dba::fetch_assoc($db_results)) {
$i++;
- $total += $r['score'];
+ $total += $r['rating'];
} // while we're pulling results
if ($total > 0) {
@@ -123,11 +123,11 @@ class Rating {
$db_results = Dba::query($sql);
if ($existing = Dba::fetch_assoc($db_results)) {
- $sql = "UPDATE `rating` SET `score`='$score' WHERE `id`='" . $existing['id'] . "'";
+ $sql = "UPDATE `rating` SET `rating`='$score' WHERE `id`='" . $existing['id'] . "'";
$db_results = Dba::query($sql);
}
else {
- $sql = "INSERT INTO `rating` (`object_id`,`object_type`,`score`,`user`) VALUES " .
+ $sql = "INSERT INTO `rating` (`object_id`,`object_type`,`rating`,`user`) VALUES " .
" ('$this->id','$this->type','$score','" . $GLOBALS['user']->id . "')";
$db_results = Dba::query($sql);
}
diff --git a/lib/search.php b/lib/search.php
index 65899340..22e3a2c5 100644
--- a/lib/search.php
+++ b/lib/search.php
@@ -171,9 +171,9 @@ function search_song($data,$operator,$method,$limit) {
$where_sql .= " song.file $value_string $operator";
break;
case 'comment':
- $join_sql .= 'song.id=song_ext_data.song_id AND ';
- $table_sql .= 'song_ext_data,';
- $where_sql .= " song_ext_data.comment $value_string $operator";
+ $join_sql .= 'song.id=song_data.song_id AND ';
+ $table_sql .= 'song_data,';
+ $where_sql .= " song_data.comment $value_string $operator";
break;
case 'played':
/* This is a 0/1 value so bool it */
@@ -186,11 +186,11 @@ function search_song($data,$operator,$method,$limit) {
break;
case 'rating':
$value = intval($value);
- $select_sql .= "SUM(ratings.user_rating)/(SELECT COUNT(song.id) FROM song,ratings WHERE ratings.object_id=song.id AND ratings.object_type='song' AND ratings.user_rating >= '$value') AS avgrating,";
- $group_sql .= " ratings.user_rating,";
- $where_sql .= " (ratings.user_rating >= '$value' AND ratings.object_type='song')";
- $table_sql .= "ratings,";
- $join_sql .= "ratings.object_id=song.id AND";
+ $select_sql .= "SUM(rating.rating)/(SELECT COUNT(song.id) FROM song,rating WHERE rating.object_id=song.id AND rating.object_type='song' AND rating.rating >= '$value') AS avgrating,";
+ $group_sql .= " rating.rating,";
+ $where_sql .= " (rating.rating >= '$value' AND rating.object_type='song')";
+ $table_sql .= "rating,";
+ $join_sql .= "rating.object_id=song.id AND";
$limit_sql .= " ORDER BY avgrating DESC";
default:
// Notzing!