Example #1
0
 public function requestAction()
 {
     $this->stationRequired();
     if (!$this->station->requests_enabled) {
         throw new \DF\Exception\DisplayOnly('This station does not support requests at this time.');
     }
     if ($this->station->requests_external_url) {
         return $this->redirect($this->station->requests_external_url);
     }
     $is_supported = CentovaCast::isStationSupported($this->station);
     if (!$is_supported) {
         throw new \DF\Exception\DisplayOnly('This station is not functioning properly and cannot accept requests at this time.');
     }
     // Search redirection.
     if ($_GET) {
         $this->redirectFromHere($_GET);
     }
     // Process a request.
     if ($this->getParam('track')) {
         try {
             $track_id = (int) $this->getParam('track');
             CentovaCast::request($this->station, $track_id);
             $track = StationMedia::find($track_id);
             $this->alert('<b>Your song, "' . $track->title . '" by ' . $track->artist . ', has been requested.</b><br>Stay tuned to the station to hear it!', 'green');
         } catch (\DF\Exception $e) {
             $this->alert('<b>Your song could not be requested. An error occurred:</b><br>' . $e->getMessage(), 'red');
         }
         $this->redirectFromHere(array('track' => NULL));
         return;
     }
     // Most requested songs.
     $top_songs = $this->em->createQuery('SELECT sm FROM Entity\\StationMedia sm WHERE sm.station_id = :station_id AND sm.requests > 0 ORDER BY sm.requests DESC')->setParameter('station_id', $this->station_id)->setMaxResults(10)->getArrayResult();
     $this->view->top_songs = $top_songs;
     // Artist names.
     $artist_names_raw = $this->em->createQuery('SELECT DISTINCT sm.artist FROM Entity\\StationMedia sm WHERE sm.station_id = :station_id ORDER BY sm.artist ASC')->setParameter('station_id', $this->station_id)->getArrayResult();
     $artist_names = array();
     foreach ($artist_names_raw as $name) {
         $artist_names[] = $name['artist'];
     }
     $this->view->artist_names = $artist_names;
     // Paginated results.
     if ($this->hasParam('q')) {
         $query = $this->getParam('q');
         $media = StationMedia::search($this->station, $query);
         $this->view->page_title = 'Search Results for "' . htmlspecialchars($query) . '"';
         $this->view->reset_button = true;
     } else {
         if ($this->hasParam('artist')) {
             $artist = $this->getParam('artist');
             $media = StationMedia::getByArtist($this->station, $artist);
             $this->view->page_title = 'All Songs by ' . htmlspecialchars($artist);
             $this->view->reset_button = true;
         } else {
             $media = StationMedia::getRequestable($this->station);
             $this->view->page_title = 'All Available Songs';
             $this->view->reset_button = false;
         }
     }
     $pager = new \DF\Paginator($media, $this->getParam('page'), 50);
     $this->view->pager = $pager;
 }