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 | |
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')
-rw-r--r-- | lib/class/rating.class.php | 34 | ||||
-rw-r--r-- | lib/class/update.class.php | 65 | ||||
-rw-r--r-- | lib/class/user.class.php | 34 |
3 files changed, 118 insertions, 15 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 diff --git a/lib/class/update.class.php b/lib/class/update.class.php index 8ef40403..10532321 100644 --- a/lib/class/update.class.php +++ b/lib/class/update.class.php @@ -242,6 +242,12 @@ class Update { $version[] = array('version' => '332003', 'description' => $update_string); + $update_string = "- Added ID to playlist_data so that duplicate songs on the same playlist can actually work.<br />" . + "- Re-worked Preferences, again :'(, hopefully making them better.<br />" . + "- Added rating table for SoundOfEmotions Rating system.<br />"; + + $version[] = array('version' => '332004', 'description' => $update_string); + return $version; } // populate_version @@ -1221,13 +1227,70 @@ class Update { @function update_332004 @discussion adds a id to the playlist_data field because of a problem with updating the same song on the same playlist being basicly - impossible...Also re-works the indexing on the tables + impossible...Adds rating table and general clean up */ function update_332004() { $sql = "ALTER TABLE `playlist_data` ADD `id` INT( 11 ) UNSIGNED NOT NULL AUTO_INCREMENT FIRST"; $db_results = mysql_query($sql, dbh()); + /* Create the ratings table */ + $sql = " CREATE TABLE `ratings` (`id` int(11) unsigned NOT NULL auto_increment," . + " `user` varchar(128) NOT NULL default ''," . + " `object_type` enum('artist','album','song') NOT NULL default 'artist'," . + " `object_id` int(11) unsigned NOT NULL default '0'," . + " `rating` enum('00','0','1','2','3','4','5') NOT NULL default '0'," . + " PRIMARY KEY (`id`))"; + $db_results = mysql_query($sql, dbh()); + + /* Add an index for the object ID */ + $sql = "ALTER TABLE `ratings` ADD INDEX ( `object_id` ) "; + $db_results = mysql_query($sql, dbh()); + + /** + * Update the Type designation on the preference table + * possible types are + * system, theme, interface, options, streaming + * users get everything but site, admins get the whole kit and kabodle + */ + + /* Set the Theme preferences */ + $sql = "UPDATE preferences SET type='theme' WHERE name='font' OR name='bg_color1' OR name='bg_color2' " . + " OR name='base_color1' OR name='base_color2' OR name='font_color1' OR name='font_color2' " . + " OR name='font_color3' OR name='row_color1' OR name='row_color2' OR name='row_color3' " . + " OR name='error_color' OR name='theme_name' OR name='font' OR name='font_size'"; + $db_results = mysql_query($sql, dbh()); + + /* Set the Interface preferences */ + $sql = "UPDATE preferences SET type='interface' WHERE name='refresh_limit' OR name='lang' OR name='condPL' " . + " OR name='popular_threshold' OR name='ellipse_threshold_album' OR name='ellipse_threshold_artist' " . + " OR name='ellipse_threshold_title'"; + $db_results = mysql_query($sql, dbh()); + + /* Set the Options Preferences */ + $sql = "UPDATE preferences SET type='options' WHERE name='download' OR name='upload' OR name='quarantine' " . + " OR name='direct_link' OR name='upload_dir'"; + $db_results = mysql_query($sql, dbh()); + + /* Set the Streaming Preferences */ + $sql = "UPDATE preferences SET type='streaming' WHERE name='sample_rate' OR name='play_type' " . + " OR name='playlist_type'"; + $db_results = mysql_query($sql, dbh()); + + /* Get the ID */ + $sql = "SELECT id FROM preferences WHERE name='display_menu'"; + $db_results = mysql_query($sql, dbh()); + + $result = mysql_fetch_assoc($db_results); + + /* Kill the bottom menu preference as its no longer needed */ + $sql = "DELETE FROM preferences WHERE name='display_menu'"; + $db_results = mysql_query($sql, dbh()); + + /* Kill the user pref references */ + $sql = "DELETE FROM user_preference WHERE preference='" . $result['id'] . "'"; + $db_results = mysql_query($sql, dbh()); + $this->set_version('db_version','332004'); } // update_332004 diff --git a/lib/class/user.class.php b/lib/class/user.class.php index 83a778ce..0b0459a7 100644 --- a/lib/class/user.class.php +++ b/lib/class/user.class.php @@ -74,11 +74,14 @@ class User { } // get_info - /*! - @function get_preferences - @discussion gets the prefs for this specific - user and returns them as an array - */ + /** + * get_preferences + * This is a little more complicate now that we've got many types of preferences + * This funtions pulls all of them an arranges them into a spiffy little array + * []['title'] = ucased type name + * []['prefs'] = array(array('name','display','value')); + * []['admin'] = t/f value if this is an admin only section + */ function get_preferences($user_id=0) { if (!$user_id) { @@ -86,14 +89,25 @@ class User { } if (!conf('use_auth')) { $user_id = '-1'; } - + + if ($user_id != '-1') { + $user_limit = "AND preferences.type != 'system'"; + } + + $sql = "SELECT preferences.name, preferences.description, preferences.type, user_preference.value FROM preferences,user_preference " . - "WHERE user_preference.user='$user_id' AND user_preference.preference=preferences.id AND preferences.type='user'"; + "WHERE user_preference.user='$user_id' AND user_preference.preference=preferences.id $user_limit"; $db_results = mysql_query($sql, dbh()); - while ($r = mysql_fetch_object($db_results)) { - $results[] = $r; - } + /* Ok this is crapy, need to clean this up or improve the code FIXME */ + while ($r = mysql_fetch_assoc($db_results)) { + $type = $r['type']; + $admin = false; + if ($type == 'system') { $admin = true; } + $type_array[$type][] = array('name'=>$r['name'],'description'=>$r['description'],'value'=>$r['value']); + $results[$type] = array ('title'=>ucwords($type),'admin'=>$admin,'prefs'=>$type_array[$type]); + } // end while + return $results; |