Esempio n. 1
0
 public function deleteAction()
 {
     $id = (int) $this->getParam('id');
     $record = StationStream::getRepository()->findOneBy(array('id' => $id, 'station_id' => $this->station->id));
     if ($record instanceof StationStream) {
         $record->delete();
     }
     // Ensure at least one stream is default.
     $this->station->checkDefaultStream();
     $this->alert('<b>Record deleted.</b>', 'green');
     $this->redirectFromHere(array('action' => 'index', 'id' => NULL));
 }
Esempio n. 2
0
 public function viewAction()
 {
     $id = (int) $this->getParam('id');
     $record = Artist::find($id);
     if (!$record instanceof Artist) {
         throw new \DF\Exception\DisplayOnly('Artist Not Found');
     }
     $this->view->artist = $record;
     // Generate statistics.
     $cache_key = 'artist_' . $record->id . '_stats';
     $stats = \DF\Cache::get($cache_key);
     if (empty($stats)) {
         $stats = array('plays_per_day' => array(), 'song_lists' => array('most_played' => array('label' => 'Most Played Songs', 'songs' => array()), 'most_liked' => array('label' => 'Most Liked Songs', 'songs' => array()), 'most_recent' => array('label' => 'Most Recently Played', 'songs' => array())));
         $active_streams = \Entity\StationStream::getMainRadioStreams();
         $songs = $this->em->createQuery('SELECT s, sh
             FROM Entity\\Song s
             LEFT JOIN s.history sh
             WHERE s.artist LIKE :artist_q
             AND sh.stream_id IN (:streams)
             ORDER BY s.title, sh.timestamp DESC')->setParameter('artist_q', '%' . $record->name . '%')->setParameter('streams', $active_streams)->getArrayResult();
         $plays_per_day = array();
         foreach ($songs as &$song) {
             foreach ((array) $song['history'] as $i => $history) {
                 // Get day of song play, incremenet counter.
                 $day = strtotime(date('Y-m-d', $history['timestamp']) . ' 00:00:00') * 1000;
                 $plays_per_day[$day] += 1;
                 // Increment votes.
                 $song['score_likes'] += $history['score_likes'];
                 $song['score_dislikes'] += $history['score_dislikes'];
             }
             unset($song['history']);
             // Increment vote totals.
             $song['score_total'] = $song['score_likes'] - $song['score_dislikes'];
             $song['votes'] = $song['score_likes'] + $song['score_dislikes'];
         }
         // Remove current day, as it will always be lower.
         $current_day = strtotime(date('Y-m-d') . ' 00:00:00') * 1000;
         unset($plays_per_day[$current_day]);
         ksort($plays_per_day);
         foreach ($plays_per_day as $plays_day => $plays_total) {
             $stats['plays_per_day'][] = array($plays_day, $plays_total);
         }
         $stats['song_lists']['most_played']['songs'] = array_slice(Utilities::irsort($songs, 'play_count'), 0, 10);
         $stats['song_lists']['most_liked']['songs'] = array_slice(Utilities::irsort($songs, 'score_total'), 0, 10);
         $stats['song_lists']['most_recent']['songs'] = array_slice(Utilities::irsort($songs, 'last_played'), 0, 10);
         \DF\Cache::save($stats, $cache_key, array(), 300);
     }
     $this->view->stats = $stats;
 }
Esempio n. 3
0
 /**
  * Process a single video stream's NowPlaying info.
  *
  * @param StationStream $stream
  * @param Station $station
  * @return array Structured NowPlaying Data
  */
 public static function processVideoStream(StationStream $stream, Station $station, $force = false)
 {
     $current_np_data = (array) $stream->nowplaying_data;
     if (!$force && NOWPLAYING_SEGMENT % 2 == 0 && !empty($current_np_data)) {
         return $current_np_data;
     }
     // Process stream.
     $custom_class = Station::getStationClassName($station->name);
     $custom_adapter = '\\PVL\\VideoAdapter\\' . $custom_class;
     $np = StationStream::api($stream);
     if (class_exists($custom_adapter)) {
         $np_adapter = new $custom_adapter($stream, $station);
         $stream_np = $np_adapter->process();
     } else {
         $adapters = array(new \PVL\VideoAdapter\Livestream($stream, $station), new \PVL\VideoAdapter\TwitchTv($stream, $station), new \PVL\VideoAdapter\UStream($stream, $station), new \PVL\VideoAdapter\StreamUp($stream, $station));
         foreach ($adapters as $np_adapter) {
             if ($np_adapter->canHandle()) {
                 $stream_np = $np_adapter->process();
                 break;
             }
         }
     }
     if (!empty($stream_np)) {
         $np = array_merge($np, $stream_np);
         $np['status'] = isset($np['meta']['status']) ? $np['meta']['status'] : 'offline';
         Debug::log('Adapter Class: ' . get_class($np_adapter));
         Debug::print_r($np);
     } else {
         $np['on_air'] = array('text' => 'Stream Offline');
         $np['meta'] = array('status' => 'offline', 'listeners' => 0);
         $np['status'] = 'offline';
     }
     $stream->nowplaying_data = $np;
     return $np;
 }
Esempio n. 4
0
 public static function api($row)
 {
     if ($row instanceof self) {
         $row = $row->toArray();
     }
     $api = array('id' => (int) $row['id'], 'name' => $row['name'], 'shortcode' => self::getStationShortName($row['name']), 'genre' => $row['genre'], 'category' => $row['category'], 'affiliation' => $row['affiliation'], 'image_url' => \PVL\Url::upload($row['image_url']), 'web_url' => $row['web_url'], 'twitter_url' => $row['twitter_url'], 'irc' => $row['irc'], 'sort_order' => (int) $row['weight']);
     if (isset($row['streams'])) {
         $api['streams'] = array();
         foreach ((array) $row['streams'] as $stream) {
             $api['streams'][] = StationStream::api($stream);
             // Set first stream as default, override if a later stream is explicitly default.
             if ($stream['is_default'] || !isset($api['default_stream_id'])) {
                 $api['default_stream_id'] = (int) $stream['id'];
                 $api['stream_url'] = $stream['stream_url'];
             }
         }
     }
     $api['player_url'] = ShortUrl::stationUrl($api['shortcode']);
     if ($row['requests_enabled']) {
         $api['request_url'] = \DF\Url::route(array('module' => 'default', 'controller' => 'station', 'action' => 'request', 'id' => $row['id']));
     } else {
         $api['request_url'] = '';
     }
     return $api;
 }
Esempio n. 5
0
 /**
  * Submit a new station.
  *
  * @throws \DF\Exception
  */
 public function stationAction()
 {
     $this->em->getFilters()->disable('softdelete');
     $user = $this->auth->getLoggedInUser();
     // Check for existing submissions.
     $existing_submissions = $this->em->createQuery('SELECT s, u FROM Entity\\Station s JOIN s.managers u
         WHERE (s.deleted_at IS NULL OR s.deleted_at IS NOT NULL)
         AND u.id = :user_id')->setParameter('user_id', $user->id)->getArrayResult();
     if ($existing_submissions) {
         $message = '<b>You have already submitted the following stations to the system:</b>';
         $message .= '<ul>';
         foreach ($existing_submissions as $station) {
             if ($station['deleted_at']) {
                 $status = 'Declined';
             } elseif ($station['is_active']) {
                 $status = 'Approved';
             } else {
                 $status = 'Pending Review';
             }
             $message .= '<li><b>' . $station['name'] . ':</b> ' . $status . '</li>';
         }
         $message .= '</ul>';
         $message .= 'Please contact the PVL team for questions related to these stations, and do not resubmit them!';
         $this->flash($message, 'info');
     }
     // Initialize the form.
     $form = new \DF\Form($this->current_module_config->forms->submit_station);
     if ($_POST && $form->isValid($_POST)) {
         $data = $form->getValues();
         $stream = $data['stream'];
         unset($data['stream']);
         $files = $form->processFiles('stations');
         foreach ($files as $file_field => $file_paths) {
             $data[$file_field] = $file_paths[1];
         }
         // Check for existing station by name.
         $existing_station = Station::getRepository()->findOneBy(array('name' => $data['name']));
         if ($existing_station instanceof Station) {
             throw new \DF\Exception('A station with this name already exists! Please do not submit duplicate stations.');
         }
         // Set up initial station record.
         $record = new Station();
         $record->fromArray($data);
         $record->is_active = false;
         $record->save();
         // Set up first stream, connected to station.
         $stream_record = new StationStream();
         $stream_record->fromArray($stream);
         $stream_record->name = 'Primary Stream';
         $stream_record->station = $record;
         $stream_record->is_default = 1;
         $stream_record->is_active = 1;
         $stream_record->save();
         // Make the current user an administrator of the new station.
         if (!$this->acl->isAllowed('administer all')) {
             $user->stations->add($record);
             $user->save();
         }
         /*
         * Now notify only PR account.
         *
                     // Notify all existing managers.
                     $station_managers_raw = StationManager::getAllActiveManagers();
                     $station_emails = Utilities::ipull($station_managers_raw, 'email');
         
                     $network_administrators = Action::getUsersWithAction('administer all');
                     $network_emails = Utilities::ipull($network_administrators, 'email');
         
                     $email_to = array_merge($station_emails, $network_emails);
         */
         $email_to = array('*****@*****.**');
         if ($email_to) {
             \DF\Messenger::send(array('to' => $email_to, 'subject' => 'New Station Submitted For Review', 'template' => 'newstation', 'vars' => array('form' => $form->populate($_POST))));
         }
         $this->alert('Your station has been submitted. Thank you! We will contact you with any questions or additional information.', 'green');
         $this->redirectHome();
         return;
     }
     $this->renderForm($form, 'edit', 'Submit Your Station');
 }