本文整理匯總了PHP中Artist::construct_from_array方法的典型用法代碼示例。如果您正苦於以下問題:PHP Artist::construct_from_array方法的具體用法?PHP Artist::construct_from_array怎麽用?PHP Artist::construct_from_array使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Artist
的用法示例。
在下文中一共展示了Artist::construct_from_array方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: get_artists
/**
* 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;
}
示例2: get_artists
/**
* 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;
}