本文整理匯總了PHP中Program::audios方法的典型用法代碼示例。如果您正苦於以下問題:PHP Program::audios方法的具體用法?PHP Program::audios怎麽用?PHP Program::audios使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Program
的用法示例。
在下文中一共展示了Program::audios方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: getAudios
/**
* get audio list
*
* @param Program $program
* @return \Illuminate\Database\Eloquent\Collection
*/
private function getAudios(&$program)
{
// filter by source, and sort by time
$audios = $audiosCopy = $program->audios()->enabled()->get();
$audioList = [];
$audioGroups = $audios->groupBy('part');
foreach ($audioGroups as $group) {
foreach ($group as $i => $item) {
if ($item->download) {
unset($group[$i]);
}
}
$group = $group->groupBy('source');
if (isset($group[Audio::SOURCE_DEFAULT])) {
if (1 < $group->count()) {
unset($group[Audio::SOURCE_DEFAULT]);
} else {
$audio = $group[Audio::SOURCE_DEFAULT][0];
$audio->url = qiniu_url($audio->url);
}
}
$audioList[] = $group->first()->first();
}
$audios = collect($audioList);
// get download url
$downloadUrls = [];
foreach ($audiosCopy as $audio) {
if ($audio->download) {
$downloadUrls[$audio->part] = $audio->url;
}
}
foreach ($audios as $audio) {
$audio->download_url = $downloadUrls[$audio->part] ?? null;
}
return $audios;
}