/** * get_artist * * This returns an array of ids of artists that have songs in the catalogs parameter */ public static function get_artists($catalogs = null) { $sql_where = ""; if (is_array($catalogs) && count($catalogs)) { $catlist = '(' . implode(',', $catalogs) . ')'; $sql_where = "WHERE `song`.`catalog` IN {$catlist}"; } $sql = "SELECT `artist`.id, `artist`.`name`, `artist`.`summary` FROM `song` LEFT JOIN `artist` ON `artist`.`id` = `song`.`artist` {$sql_where} GROUP BY `song`.artist ORDER BY `artist`.`name`"; $results = array(); $db_results = Dba::read($sql); while ($r = Dba::fetch_assoc($db_results)) { $results[] = Artist::construct_from_array($r); } return $results; }
/** * get_artists * * This returns an array of artists that have songs in the catalogs parameter * @param array|null $catalogs * @return \Artist[] */ public static function get_artists($catalogs = null, $size = 0, $offset = 0) { $sql_where = ""; if (is_array($catalogs) && count($catalogs)) { $catlist = '(' . implode(',', $catalogs) . ')'; $sql_where = "WHERE `song`.`catalog` IN {$catlist} "; } $sql_limit = ""; if ($offset > 0 && $size > 0) { $sql_limit = "LIMIT " . $offset . ", " . $size; } elseif ($size > 0) { $sql_limit = "LIMIT " . $size; } elseif ($offset > 0) { // MySQL doesn't have notation for last row, so we have to use the largest possible BIGINT value // https://dev.mysql.com/doc/refman/5.0/en/select.html $sql_limit = "LIMIT " . $offset . ", 18446744073709551615"; } $sql = "SELECT `artist`.`id`, `artist`.`name`, `artist`.`summary`, (SELECT COUNT(DISTINCT album) from `song` as `inner_song` WHERE `inner_song`.`artist` = `song`.`artist`) AS `albums`" . "FROM `song` LEFT JOIN `artist` ON `artist`.`id` = `song`.`artist` " . $sql_where . "GROUP BY `artist`.`id`, `artist`.`name`, `artist`.`summary`, `song`.`artist` ORDER BY `artist`.`name` " . $sql_limit; $results = array(); $db_results = Dba::read($sql); while ($r = Dba::fetch_assoc($db_results)) { $results[] = Artist::construct_from_array($r); } return $results; }