Exemple #1
0
 /**
  * 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;
 }