Exemplo n.º 1
0
 public static function withPlaylists()
 {
     $query = "\n\t\t\t\tSELECT\n\t\t\t\t\tChannels.*\n\t\t\t\tFROM\n\t\t\t\t\tz_youtube_channels Channels\n\t\t\t\tWHERE\n\t\t\t\t\tChannels.status = " . static::STATUS_ACTIVE;
     $channels = array();
     $result = static::execute($query)->group();
     if ($result) {
         foreach ($result as $channelId => $channel) {
             $channels[$channelId] = array_merge($channel[0], array('id' => $channelId));
         }
     }
     $playlists = PlaylistsModel::all(array('conditions' => array('channel_id' => array_keys($channels), 'status' => PlaylistsModel::STATUS_ACTIVE), 'order' => array('title' => 'ASC')))->toArray();
     if ($playlists) {
         foreach ($playlists as $playlist) {
             if (isset($channels[$playlist['channel_id']])) {
                 $channels[$playlist['channel_id']]['playlists'][] = $playlist;
             }
         }
     }
     return $channels;
 }