public function indexAction() { $id = $this->getParam('id'); if (empty($id)) { $this->redirectHome(); } $record = Song::find($id); if (!$record instanceof Song) { throw new \DF\Exception\DisplayOnly('Song not found!'); } $song_info = array(); $song_info['record'] = $record; // Get external provider information. $song_info['external'] = $record->getExternal(); // Get album art and lyrics from all providers. $adapters = Song::getExternalAdapters(); $external_fields = array('lyrics', 'purchase_url', 'description'); foreach ($external_fields as $field_name) { $song_info[$field_name] = NULL; foreach ($adapters as $adapter_name => $adapter_class) { if (!empty($song_info['external'][$adapter_name][$field_name])) { $song_info[$field_name] = $song_info['external'][$adapter_name][$field_name]; break; } } } $song_info['image_url'] = $record->image_url; if (!$song_info['image_url']) { $song_info['image_url'] = \DF\Url::content('images/song_generic.png'); } $song_info['description'] = $this->_cleanUpText($song_info['description']); $song_info['lyrics'] = $this->_cleanUpText($song_info['lyrics']); // Get most recent playback information. $history_raw = $this->em->createQuery(' SELECT sh, st FROM Entity\\SongHistory sh JOIN sh.station st WHERE sh.song_id = :song_id AND st.category IN (:categories) AND sh.timestamp >= :threshold ORDER BY sh.timestamp DESC')->setParameter('song_id', $record->id)->setParameter('categories', array('audio', 'video'))->setParameter('threshold', strtotime('-1 week'))->getArrayResult(); $history = array(); $last_row = NULL; foreach ($history_raw as $i => $row) { if ($last_row && $row['station_id'] == $last_row['station_id']) { $timestamp_diff = abs($row['timestamp'] - $last_row['timestamp']); if ($timestamp_diff < 60) { continue; } } $history[] = $row; $last_row = $row; } $song_info['recent_history'] = $history; // Get requestable locations. $song_info['request_on'] = $this->em->createQuery(' SELECT sm, st FROM Entity\\StationMedia sm JOIN sm.station st WHERE sm.song_id = :song_id GROUP BY sm.station_id')->setParameter('song_id', $record->id)->getArrayResult(); $this->view->song = $song_info; }
public function indexAction() { if (!$this->hasParam('id')) { return $this->listAction(); } $id = $this->getParam('id'); $record = Song::find($id); if (!$record instanceof Song) { return $this->returnError('Song not found.'); } $return = Song::api($record); $return['external'] = $record->getExternal(); return $this->returnSuccess($return); }
public function votesAction() { $threshold = strtotime('-2 weeks'); $votes_raw = $this->em->createQuery('SELECT sv.song_id, SUM(sv.vote) AS vote_total FROM Entity\\SongVote sv WHERE sv.station_id = :station_id AND sv.timestamp >= :threshold GROUP BY sv.song_id')->setParameter('station_id', $this->station->id)->setParameter('threshold', $threshold)->getArrayResult(); $ignored_songs = $this->_getIgnoredSongs(); $votes_raw = array_filter($votes_raw, function ($value) use($ignored_songs) { return !isset($ignored_songs[$value['song_id']]); }); \PVL\Utilities::orderBy($votes_raw, 'vote_total DESC'); $votes = array(); foreach ($votes_raw as $row) { $row['song'] = Song::find($row['song_id']); $votes[] = $row; } $this->view->votes = $votes; }
public function votesAction() { $threshold = strtotime('-1 week'); $votes_raw = $this->em->createQuery('SELECT sv.song_id, SUM(sv.vote) AS vote_total FROM Entity\\SongVote sv WHERE sv.timestamp >= :threshold GROUP BY sv.song_id')->setParameter('threshold', $threshold)->getArrayResult(); Utilities::orderBy($votes_raw, 'vote_total DESC'); $votes = array(); foreach ($votes_raw as $row) { $row['song'] = Song::find($row['song_id']); $votes[] = $row; } $this->view->votes = $votes; }