From 0a184d3db49a3263c1336fd679df898ca6800f4a Mon Sep 17 00:00:00 2001 From: Karl 'vollmerk' Vollmer Date: Mon, 14 Jul 2008 04:56:52 +0000 Subject: make the disabled songs link show something, need to make a custom view for that as the song one i not really valid, also played around with the caching a bit --- lib/class/album.class.php | 28 +------------------- lib/class/artist.class.php | 26 +----------------- lib/class/database_object.abstract.php | 21 +++++++++++++++ lib/class/flag.class.php | 48 +++++++++++++++++++--------------- lib/class/tag.class.php | 24 ----------------- 5 files changed, 50 insertions(+), 97 deletions(-) (limited to 'lib/class') diff --git a/lib/class/album.class.php b/lib/class/album.class.php index ad0f6ef5..184842b6 100644 --- a/lib/class/album.class.php +++ b/lib/class/album.class.php @@ -59,7 +59,7 @@ class Album extends database_object { $this->id = intval($id); /* Get the information from the db */ - $info = $this->_get_info(); + $info = $this->get_info(); // Foreach what we've got foreach ($info as $key=>$value) { @@ -110,32 +110,6 @@ class Album extends database_object { } // build_cache - /** - * _get_info - * This is a private function that pulls the album - * from the database - */ - private function _get_info() { - - $id = intval($this->id); - - if (parent::is_cached('album',$id)) { - return parent::get_from_cache('album',$id); - } - - // Just get the album information - $sql = "SELECT * FROM `album` WHERE `id`='$id'"; - $db_results = Dba::query($sql); - - $results = Dba::fetch_assoc($db_results); - - // Cache the object - parent::add_to_cache('album',$id,$results); - - return $results; - - } // _get_info - /** * _get_extra_info * This pulls the extra information from our tables, this is a 3 table join, which is why we don't normally diff --git a/lib/class/artist.class.php b/lib/class/artist.class.php index f5591018..f55fd999 100644 --- a/lib/class/artist.class.php +++ b/lib/class/artist.class.php @@ -48,7 +48,7 @@ class Artist extends database_object { $this->id = intval($id); /* Get the information from the db */ - $info = $this->_get_info(); + $info = $this->get_info(); foreach ($info as $key=>$value) { $this->$key = $value; @@ -92,30 +92,6 @@ class Artist extends database_object { } // build_cache - /** - * _get_info - * get's the vars for $this out of the database taken from the object - */ - private function _get_info() { - - $id = intval($this->id); - - if (parent::is_cached('artist',$id)) { - return parent::get_from_cache('artist',$id); - } - - /* Grab the basic information from the catalog and return it */ - $sql = "SELECT * FROM artist WHERE id='$id'"; - $db_results = Dba::query($sql); - - $results = Dba::fetch_assoc($db_results); - - parent::add_to_cache('artist',$id,$results); - - return $results; - - } // _get_info - /** * get_from_name * This gets an artist object based on the artist name diff --git a/lib/class/database_object.abstract.php b/lib/class/database_object.abstract.php index 871232ea..2005da55 100644 --- a/lib/class/database_object.abstract.php +++ b/lib/class/database_object.abstract.php @@ -31,6 +31,27 @@ abstract class database_object { // Statistics for debugging public static $cache_hit = 0; + public function get_info($id,$table_name='') { + + $table_name = $table_name ? Dba::escape($table_name) : Dba::escape(strtolower(get_class($this))); + + if (self::is_cached($table_name,$id)) { + return self::get_from_cache($table_name,$id); + } + + $sql = "SELECT * FROM `$table_name` WHERE `id`='$id'"; + $db_results = Dba::query($sql); + + if (!$db_results) { return array(); } + + $row = Dba::fetch_assoc($db_results); + + self::add_to_cache($table_name,$id,$row); + + return $row; + + } // get_info + /** * is_cached * this checks the cache to see if the specified object is there diff --git a/lib/class/flag.class.php b/lib/class/flag.class.php index 9cc7c1a8..ba2480f8 100644 --- a/lib/class/flag.class.php +++ b/lib/class/flag.class.php @@ -1,7 +1,7 @@ _get_info($flag_id); + $info = $this->get_info($flag_id,'flagged'); foreach ($info as $key=>$value) { $this->$key = $value; @@ -56,21 +56,22 @@ class Flag { } // Constructor /** - * _get_info - * Private function for getting the information for this object from the database + * build_cache + * This takes an array of ids and builds up a nice little cache + * for us */ - private function _get_info($flag_id) { + public static function build_cache($ids) { - $id = Dba::escape($flag_id); + $idlist = '(' . implode(',',$ids) . ')'; - $sql = "SELECT * FROM `flagged` WHERE `id`='$id'"; - $db_results = Dba::query($sql); + $sql = "SELECT * FROM `flagged` WHERE `id` IN $idlist"; + $db_results = Dba::query($sql); - $results = Dba::fetch_assoc($db_results); - - return $results; + while ($row = Dba::fetch_assoc($db_results)) { + parent::add_to_cache('flagged',$row['id'],$row); + } - } // _get_info + } // build_cache /** * get_recent @@ -95,19 +96,24 @@ class Flag { } // get_recent /** - * get_total - * Returns the total number of flagged objects + * get_disabled + * This returns all of the songs that have been disabled, this is + * a form of being flagged */ - function get_total() { + public static function get_disabled() { - $sql = "SELECT COUNT(id) FROM flagged"; - $db_results = mysql_query($sql, dbh()); + $sql = "SELECT `id` FROM `song` WHERE `enabled`='0'"; + $db_results = Dba::query($sql); - $results = mysql_fetch_row($db_results); + $results = array(); + + while ($row = Dba::fetch_assoc($db_results)) { + $results[] = $row['id']; + } - return $results['0']; + return $results; - } // get_total + } // get_disabled /** * get_all diff --git a/lib/class/tag.class.php b/lib/class/tag.class.php index 3499cd94..22f4ea4a 100644 --- a/lib/class/tag.class.php +++ b/lib/class/tag.class.php @@ -70,30 +70,6 @@ class Tag extends database_object { } // construct_from_name - /** - * get_info - * This takes the id and returns an array of information, checks the cache - * to see what's up - */ - private function get_info($id) { - - $id = intval($id); - - if (parent::is_cached('tag',$id)) { - return parent::get_from_cache('tag',$id); - } - - $sql = "SELECT * FROM `tag` WHERE `id`='$id'"; - $db_results = Dba::query($sql); - - $results = Dba::fetch_assoc($db_results); - - parent::add_to_cache('tag',$id,$results); - - return $results; - - } // get_info - /** * build_cache * This takes an array of object ids and caches all of their information -- cgit