diff options
author | momo-i <momo-i@ampache> | 2008-09-03 22:44:01 +0000 |
---|---|---|
committer | momo-i <momo-i@ampache> | 2008-09-03 22:44:01 +0000 |
commit | 01670c6abda538b5b40893f5015bfc4913382841 (patch) | |
tree | d20886a34636087129877d3284dd1701d42daee1 /lib/class/tag.class.php | |
parent | 64cbf29ff39637f91ab938e8370b67a604c74f9a (diff) | |
download | ampache-01670c6abda538b5b40893f5015bfc4913382841.tar.gz ampache-01670c6abda538b5b40893f5015bfc4913382841.tar.bz2 ampache-01670c6abda538b5b40893f5015bfc4913382841.zip |
simplify code, remove large if else statement
Diffstat (limited to 'lib/class/tag.class.php')
-rw-r--r-- | lib/class/tag.class.php | 55 |
1 files changed, 25 insertions, 30 deletions
diff --git a/lib/class/tag.class.php b/lib/class/tag.class.php index ff02041d..a3fc2b1e 100644 --- a/lib/class/tag.class.php +++ b/lib/class/tag.class.php @@ -77,21 +77,18 @@ class Tag extends database_object { */ public static function build_cache($ids) { - if ($ids) { - $idlist = '(' . implode(',',$ids) . ')'; - - $sql = "SELECT * FROM `tag` WHERE `id` IN $idlist"; - $db_results = Dba::query($sql); + if (!is_array($ids) OR !count($ids)) { return false; } - while ($row = Dba::fetch_assoc($db_results)) { - parent::add_to_cache('tag',$row['id'],$row); - } + $idlist = '(' . implode(',',$ids) . ')'; + + $sql = "SELECT * FROM `tag` WHERE `id` IN $idlist"; + $db_results = Dba::query($sql); - return true; - } else { - return false; - } + while ($row = Dba::fetch_assoc($db_results)) { + parent::add_to_cache('tag',$row['id'],$row); + } + return true; } // build_cache /** @@ -100,29 +97,27 @@ class Tag extends database_object { */ public static function build_map_cache($type,$ids) { - if ($ids) { - $type = self::validate_type($type); - $idlist = '(' . implode(',',$ids) . ')'; + if (!is_array($ids) OR !count($ids)) { return false; } - $sql = "SELECT COUNT(`tag_map`.`id`) AS `count`,`tag`.`id`,`tag_map`.`object_id` FROM `tag_map` " . - "INNER JOIN `tag` ON `tag`.`id`=`tag_map`.`tag_id` " . - "WHERE `tag_map`.`object_type`='$type' AND `tag_map`.`object_id` IN $idlist " . - "GROUP BY `tag_map`.`object_id` ORDER BY `count` DESC"; - $db_results = Dba::query($sql); + $type = self::validate_type($type); + $idlist = '(' . implode(',',$ids) . ')'; - while ($row = Dba::fetch_assoc($db_results)) { - $tags[$row['object_id']][] = $row; - } - - foreach ($tags as $id=>$entry) { - parent::add_to_cache('tag_map_' . $type,$id,$entry); - } + $sql = "SELECT COUNT(`tag_map`.`id`) AS `count`,`tag`.`id`,`tag_map`.`object_id` FROM `tag_map` " . + "INNER JOIN `tag` ON `tag`.`id`=`tag_map`.`tag_id` " . + "WHERE `tag_map`.`object_type`='$type' AND `tag_map`.`object_id` IN $idlist " . + "GROUP BY `tag_map`.`object_id` ORDER BY `count` DESC"; + $db_results = Dba::query($sql); - return true; - } else { - return false; + while ($row = Dba::fetch_assoc($db_results)) { + $tags[$row['object_id']][] = $row; } + foreach ($tags as $id=>$entry) { + parent::add_to_cache('tag_map_' . $type,$id,$entry); + } + + return true; + } // build_map_cache /** |