diff options
author | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2008-07-14 04:56:52 +0000 |
---|---|---|
committer | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2008-07-14 04:56:52 +0000 |
commit | 0a184d3db49a3263c1336fd679df898ca6800f4a (patch) | |
tree | 7d61e5990df4629ee8b2c3a1da722f635791896e /lib | |
parent | 5c510357a83f6a25ede6362a267c9d3569daf005 (diff) | |
download | ampache-0a184d3db49a3263c1336fd679df898ca6800f4a.tar.gz ampache-0a184d3db49a3263c1336fd679df898ca6800f4a.tar.bz2 ampache-0a184d3db49a3263c1336fd679df898ca6800f4a.zip |
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
Diffstat (limited to 'lib')
-rw-r--r-- | lib/class/album.class.php | 28 | ||||
-rw-r--r-- | lib/class/artist.class.php | 26 | ||||
-rw-r--r-- | lib/class/database_object.abstract.php | 21 | ||||
-rw-r--r-- | lib/class/flag.class.php | 48 | ||||
-rw-r--r-- | lib/class/tag.class.php | 24 |
5 files changed, 50 insertions, 97 deletions
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) { @@ -111,32 +111,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 * do it 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; @@ -93,30 +93,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 @@ <?php /* - Copyright 2001 - 2007 Ampache.org + Copyright Ampache.org All Rights Reserved This program is free software; you can redistribute it and/or @@ -24,7 +24,7 @@ * Flag Class * This handles flagging of songs, albums and artists */ -class Flag { +class Flag extends database_object { public $id; public $user; @@ -45,7 +45,7 @@ class Flag { */ public function __construct($flag_id) { - $info = $this->_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 @@ -71,30 +71,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 * in a single query, cuts down on the connections |