Esempio n. 1
0
 public function newAction()
 {
     $new_threshold = strtotime('-2 weeks');
     $song_adapters = Song::getExternalAdapters();
     $new_songs_raw = $this->em->createQuery('SELECT s, ex_eqbeats, ex_btunes, ex_pfm
         FROM Entity\\Song s
         LEFT JOIN s.external_eqbeats AS ex_eqbeats
         LEFT JOIN s.external_bronytunes AS ex_btunes
         LEFT JOIN s.external_ponyfm AS ex_pfm
         WHERE (ex_eqbeats.created >= :threshold OR ex_btunes.created >= :threshold OR ex_pfm.created >= :threshold)')->setParameter('threshold', $new_threshold)->getArrayResult();
     $new_songs = array();
     foreach ($new_songs_raw as $song) {
         $timestamps = array();
         foreach ($song_adapters as $adapter_key => $adapter_class) {
             $local_key = 'external_' . $adapter_key;
             if (!empty($song[$local_key])) {
                 $timestamps[] = $song[$local_key]['created'];
             }
         }
         $song['created'] = max($timestamps);
         $song['filename'] = $song['artist'] . ' - ' . $song['title'];
         $new_songs[] = $song;
     }
     $new_songs = Utilities::irsort($new_songs, 'created');
     $this->view->new_songs = $new_songs;
 }
Esempio n. 2
0
 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;
 }