public function fetchAction() { $this->doNotRender(); // Allow AJAX retrieval. $this->response->setHeader('Access-Control-Allow-Origin', '*'); $all_stations = Station::fetchArray(); $stations = array(); foreach ($all_stations as $station_info) { $stations[$station_info['short_name']] = $station_info; } $station_shortcode = $this->getParam('station', 'all'); // All parameters required for normal pull. if (!$this->hasParam('start') || !$this->hasParam('end')) { return $this->response->setJsonContent(array()); } $timestamps = array('start' => strtotime($this->getParam('start') . ' 00:00:00'), 'end' => strtotime($this->getParam('end') . ' 23:59:59') + 1); if ($station_shortcode != "all") { $station = $stations[$station_shortcode]; $events_raw = $this->em->createQuery('SELECT s, st FROM Entity\\Schedule s LEFT JOIN s.station st WHERE (s.station_id = :sid) AND (s.start_time <= :end AND s.end_time >= :start) ORDER BY s.start_time ASC')->setParameter('sid', $station['id'])->setParameter('start', $timestamps['start'])->setParameter('end', $timestamps['end'])->getArrayResult(); } else { $station = NULL; $events_raw = $this->em->createQuery('SELECT s, st FROM Entity\\Schedule s LEFT JOIN s.station st WHERE (s.start_time <= :end AND s.end_time >= :start) ORDER BY s.start_time ASC')->setParameter('start', $timestamps['start'])->setParameter('end', $timestamps['end'])->getArrayResult(); } $events = array(); foreach ((array) $events_raw as $event) { if (!$station) { $event['title'] = $event['station']['name'] . ":\n" . $event['title']; } $events[] = array('id' => $event['guid'], 'title' => $event['title'], 'allDay' => $event['is_all_day'] ? true : false, 'start' => date(\DateTime::ISO8601, $event['start_time']), 'end' => date(\DateTime::ISO8601, $event['end_time']), 'url' => $event['web_url']); } return $this->response->setJsonContent($events); }
public function indexAction() { $default_station = 'PVL Presents (Video)'; $stations_covering = array('PVL Presents (Video)' => 'Video Stream', 'PVL Presents (Radio)' => 'Radio Stream'); $categories = array('event' => array('name' => 'Live Event Coverage', 'icon' => 'icon-star', 'stations' => array())); $all_stations = Station::fetchArray(); $stations_by_name = array(); foreach ($all_stations as $station) { $name = $station['name']; $stations_by_name[$name] = $station; if (isset($stations_covering[$name])) { $station['category'] = 'event'; $station['nickname'] = $stations_covering[$name]; $categories['event']['stations'][] = $station; } } $this->view->categories = $categories; $this->view->station_id = $stations_by_name[$default_station]['id']; $this->view->autoplay = true; }
protected function _initStations() { $this->view->station_id = $station_id = $this->getParam('id', NULL); $this->view->volume = $this->hasParam('volume') ? (int) $this->getParam('volume') : NULL; $this->categories = Station::getCategories(); $stations_raw = Station::fetchArray(); // Limit to a single station if requested. if ($station_id && $this->getParam('showonlystation', false) == 'true') { foreach ($stations_raw as $station) { if ($station['id'] == $station_id) { $stations_raw = array($station); break; } } } $this->stations = array(); foreach ($stations_raw as $station) { // Build multi-stream directory. $streams = array(); $current_stream_id = NULL; foreach ((array) $station['streams'] as $stream) { if (!$stream['hidden_from_player'] && $stream['is_active']) { if ($stream['is_default']) { $station['default_stream_id'] = $stream['id']; $current_stream_id = $stream['id']; } $streams[$stream['id']] = $stream; } } // Pull from user preferences to potentially override defaults. $default_streams = (array) \PVL\Customization::get('stream_defaults'); if (isset($default_streams[$station['id']])) { $stream_id = (int) $default_streams[$station['id']]; if (isset($streams[$stream_id])) { $current_stream_id = $stream_id; } } $station['current_stream_id'] = $current_stream_id; $station['streams'] = $streams; // Only show stations with at least one usable stream. if (count($streams) > 0) { $this->stations[$station['id']] = $station; } } foreach ($this->stations as $station) { if (isset($this->categories[$station['category']])) { $this->categories[$station['category']]['stations'][] = $station; } } $this->view->stations = $this->stations; $this->view->categories = $this->categories; }
public function songAction() { // Generate temporary token for this session. $this->view->token = $this->_generateSongHash(); // Produce list of stations. $stations = array(); $all_stations = Station::fetchArray(); foreach ($all_stations as $station) { if ($station['category'] == 'audio') { $stations[$station['short_name']] = '<b>' . $station['name'] . '</b> - ' . $station['genre']; } } $this->view->stations = $stations; }
public function listAction() { $category = $this->getParam('category', 'all'); if ($category == 'all') { $stations_raw = Station::fetchArray(); } else { $cats = Station::getStationsInCategories(); if (!isset($cats[$category])) { return $this->returnError('Category not found.'); } $stations_raw = $cats[$category]['stations']; } $stations = array(); foreach ($stations_raw as $row) { $stations[] = Station::api($row); } return $this->returnSuccess($stations); }