diff options
author | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2008-09-03 15:12:22 +0000 |
---|---|---|
committer | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2008-09-03 15:12:22 +0000 |
commit | 64cbf29ff39637f91ab938e8370b67a604c74f9a (patch) | |
tree | bd267f410722698d584bae73b857b47078ea7803 /lib/class/album.class.php | |
parent | e5fc28772b785d876d441dda663a1ec1b33d3eae (diff) | |
download | ampache-64cbf29ff39637f91ab938e8370b67a604c74f9a.tar.gz ampache-64cbf29ff39637f91ab938e8370b67a604c74f9a.tar.bz2 ampache-64cbf29ff39637f91ab938e8370b67a604c74f9a.zip |
simplify code, remove large if else statement
Diffstat (limited to 'lib/class/album.class.php')
-rw-r--r-- | lib/class/album.class.php | 56 |
1 files changed, 28 insertions, 28 deletions
diff --git a/lib/class/album.class.php b/lib/class/album.class.php index 780fa384..76857dc4 100644 --- a/lib/class/album.class.php +++ b/lib/class/album.class.php @@ -95,38 +95,38 @@ class Album extends database_object { */ public static function build_cache($ids,$extra=false) { - if ($ids) { - $idlist = '(' . implode(',', $ids) . ')'; + // Nothing to do if they pass us nothing + if (!is_array($ids) OR !count($ids)) { return false; } - $sql = "SELECT * FROM `album` WHERE `id` IN $idlist"; - $db_results = Dba::query($sql); - - while ($row = Dba::fetch_assoc($db_results)) { - parent::add_to_cache('album',$row['id'],$row); - } + $idlist = '(' . implode(',', $ids) . ')'; - // If we're extra'ing cache the extra info as well - if ($extra) { - $sql = "SELECT COUNT(DISTINCT(song.artist)) as artist_count,COUNT(song.id) AS song_count,artist.name AS artist_name" . - ",artist.prefix AS artist_prefix,album_data.art AS has_art,album_data.thumb AS has_thumb, artist.id AS artist_id,`song`.`album`". - "FROM `song` " . - "INNER JOIN `artist` ON `artist`.`id`=`song`.`artist` " . - "LEFT JOIN `album_data` ON `album_data`.`album_id` = `song`.`album` " . - "WHERE `song`.`album` IN $idlist GROUP BY `song`.`album`"; - $db_results = Dba::read($sql); - - while ($row = Dba::fetch_assoc($db_results)) { - $row['has_art'] = make_bool($row['has_art']); - $row['has_thumb'] = make_bool($row['has_thumb']); - parent::add_to_cache('album_extra',$row['album'],$row); - } // while rows - } // if extra - - return true; - } else { - return false; + $sql = "SELECT * FROM `album` WHERE `id` IN $idlist"; + $db_results = Dba::query($sql); + + while ($row = Dba::fetch_assoc($db_results)) { + parent::add_to_cache('album',$row['id'],$row); } + // If we're extra'ing cache the extra info as well + if ($extra) { + $sql = "SELECT COUNT(DISTINCT(song.artist)) as artist_count,COUNT(song.id) AS song_count,artist.name AS artist_name" . + ",artist.prefix AS artist_prefix,album_data.art AS has_art,album_data.thumb AS has_thumb, artist.id AS artist_id,`song`.`album`". + "FROM `song` " . + "INNER JOIN `artist` ON `artist`.`id`=`song`.`artist` " . + "LEFT JOIN `album_data` ON `album_data`.`album_id` = `song`.`album` " . + "WHERE `song`.`album` IN $idlist GROUP BY `song`.`album`"; + + $db_results = Dba::read($sql); + + while ($row = Dba::fetch_assoc($db_results)) { + $row['has_art'] = make_bool($row['has_art']); + $row['has_thumb'] = make_bool($row['has_thumb']); + parent::add_to_cache('album_extra',$row['album'],$row); + } // while rows + } // if extra + + return true; + } // build_cache /** |