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