diff options
author | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2007-09-12 07:30:55 +0000 |
---|---|---|
committer | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2007-09-12 07:30:55 +0000 |
commit | bff9e37fa5fa41111b5b06ce6cdcb0eb8e5c21f9 (patch) | |
tree | f9f61787479b286e5ae5efb96447107c10dd553e /lib/class | |
parent | c99ad11ee04fa811aaf6988a2daa0567ab6ee0d8 (diff) | |
download | ampache-bff9e37fa5fa41111b5b06ce6cdcb0eb8e5c21f9.tar.gz ampache-bff9e37fa5fa41111b5b06ce6cdcb0eb8e5c21f9.tar.bz2 ampache-bff9e37fa5fa41111b5b06ce6cdcb0eb8e5c21f9.zip |
more work on the localplay stuff, most details ironed out, just needs some code to back it up, also tweaked plugins and threw in some extra goodies in the preference class, also pimped out the error class
Diffstat (limited to 'lib/class')
-rw-r--r-- | lib/class/dba.class.php | 2 | ||||
-rw-r--r-- | lib/class/error.class.php | 64 | ||||
-rw-r--r-- | lib/class/localplay.abstract.php | 9 | ||||
-rw-r--r-- | lib/class/preference.class.php | 42 | ||||
-rw-r--r-- | lib/class/rating.class.php | 12 |
5 files changed, 91 insertions, 38 deletions
diff --git a/lib/class/dba.class.php b/lib/class/dba.class.php index 62d18e00..c2c60fce 100644 --- a/lib/class/dba.class.php +++ b/lib/class/dba.class.php @@ -85,9 +85,9 @@ class Dba { public static function fetch_assoc($resource) { $result = mysql_fetch_assoc($resource); + debug_event('Assoc',self::$_sql,'6'); if (!$result) { -// debug_event('fetch_assoc',self::$_sql,'1'); return array(); } diff --git a/lib/class/error.class.php b/lib/class/error.class.php index 29c1c885..61202532 100644 --- a/lib/class/error.class.php +++ b/lib/class/error.class.php @@ -1,27 +1,5 @@ <?php /* - - Copyright (c) 2001 - 2007 Ampache.org - All Rights Reserved - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License - as published by the Free Software Foundation; version 2 - of the License. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ - - -/** Copyright (c) 2001 - 2007 Ampache.org All Rights Reserved @@ -38,8 +16,9 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ - +/** * Error class * This is the baic error class, its better now that we can use php5 * hello static functions and variables @@ -60,6 +39,19 @@ class Error { } // __construct /** + * __destruct + * This saves all of the errors that are left into the session + */ + public function __destruct() { + + + foreach (self::$errors as $key=>$error) { + $_SESSION['errors'][$key] = $error; + } + + } // __destruct + + /** * add * This is a public static function it adds a new error message to the array * It can optionally clobber rather then adding to the error message @@ -70,24 +62,21 @@ class Error { if (!isset(Error::$errors[$name])) { Error::$errors[$name] = $message; Error::$state = 1; - return true; + $_SESSION['errors'][$key] = $message; } - // They want us to clobber it - if ($clobber) { + elseif ($clobber) { Error::$state = 1; Error::$errors[$name] = $message; - return true; + $_SESSION['errors'][$key] = $message; } - // They want us to append the error, add a BR\n and then the message else { Error::$state = 1; Error::$errors[$name] .= "<br />\n" . $message; - return true; + $_SESSION['errors'][$key] .= "<br />\n" . $message; } - } // add /** @@ -116,5 +105,20 @@ class Error { } // display + /** + * auto_init + * This loads the errors from the session back into Ampache + */ + public static function auto_init() { + + if (!is_array($_SESSION['errors'])) { return false; } + + // Re-insert them + foreach ($_SESSION['errors'] as $key=>$error) { + self::add($key,$error); + } + + } // auto_init + } // Error diff --git a/lib/class/localplay.abstract.php b/lib/class/localplay.abstract.php index 1874e390..d8e21387 100644 --- a/lib/class/localplay.abstract.php +++ b/lib/class/localplay.abstract.php @@ -34,11 +34,18 @@ abstract class localplay_controller { abstract public function status(); abstract public function get_version(); // Returns the version of this plugin abstract public function get_description(); // Returns the description - abstract public function actions(); // Return an array of name=>link actions for the sidebar abstract public function is_installed(); // Returns an boolean t/f abstract public function install(); abstract public function uninstall(); + // For display we need the following 'instance' functions + abstract public function add_instance($data); + abstract public function delete_instance($id); + abstract public function get_instances(); + abstract public function instance_fields(); + abstract public function set_active_instance($uid); + abstract public function get_active_instance(); + /** * get_url * This returns the URL for the passed object diff --git a/lib/class/preference.class.php b/lib/class/preference.class.php index 6fb707fe..ef8a0a05 100644 --- a/lib/class/preference.class.php +++ b/lib/class/preference.class.php @@ -175,4 +175,46 @@ class Preference { } // insert + /** + * delete + * This deletes the specified preference, a name or a ID can be passed + */ + public static function delete($preference) { + + // First prepare + if (!is_numeric($preference)) { + $id = self::id_from_name($preference); + $name = $preference; + } + else { + $name = self::name_from_id($preference); + $id = $preference; + } + + $id = Dba::escape($id); + + // Remove the preference, then the user records of it + $sql = "DELETE FROM `preference` WHERE `id`='$id'"; + $db_results = Dba::query($sql); + + self::rebuild_preferences(); + + } // delete + + /** + * rebuild_preferences + * This removes any garbage and then adds back in anything missing preferences wise + */ + public static function rebuild_preferences() { + + // First remove garbage + $sql = "DELETE FROM `user_preference` USING `user_preference` LEFT JOIN `preference` ON `preference`.`id`=`user_preference`.`preference` " . + "WHERE `preference`.`id` IS NULL"; + $db_results = Dba::query($sql); + + // Now add anything that we are missing back in, except System + $sql = "SELECT * FROM `preference` WHERE `type`!='system'"; + + } // rebuild_preferences + } // end Preference class 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); } |