本文整理汇总了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;
}