Esempio n. 1
0
 public function indexAction()
 {
     $events_raw = $this->em->createQuery('SELECT s FROM \\Entity\\Schedule s WHERE (s.end_time >= :current AND s.start_time <= :future) AND s.station_id = :station_id ORDER BY s.start_time ASC')->setParameter('station_id', $this->station->id)->setParameter('current', time())->setParameter('future', strtotime('+2 months'))->getArrayResult();
     $events_by_day = array();
     foreach ($events_raw as $event) {
         $event['status'] = $event['start_time'] <= time() ? 'now' : 'upcoming';
         $event['range'] = Schedule::getRangeText($event['start_time'], $event['end_time'], $event['is_all_day']);
         $event_date = date('Y-m-d', $event['start_time']);
         if (!isset($events_by_day[$event_date])) {
             $events_by_day[$event_date] = array('name' => date('l, F j, Y', $event['start_time']), 'events' => array());
         }
         $events_by_day[$event_date]['events'][] = $event;
     }
     $this->view->events_by_day = $events_by_day;
 }
Esempio n. 2
0
 protected function _initEvents()
 {
     $event_info = Cache::get('pvlive_events');
     if (!$event_info) {
         $events_raw = $this->em->createQuery('SELECT s, st FROM Entity\\Schedule s JOIN s.station st WHERE (s.end_time >= :current AND s.start_time <= :future) ORDER BY s.start_time ASC')->setParameter('current', time())->setParameter('future', strtotime('+4 days'))->getArrayResult();
         $all_events = array();
         $events_by_day = array();
         for ($i = 0; $i < 6; $i++) {
             $day_timestamp = mktime(0, 0, 1, date('n'), (int) date('j') + $i);
             $day_date = date('Y-m-d', $day_timestamp);
             $is_today = $day_date == date('Y-m-d');
             $events_by_day[$day_date] = array('day_name' => $is_today ? 'Today' : date('l', $day_timestamp), 'timestamp' => $day_timestamp, 'is_today' => $is_today, 'events' => array());
         }
         foreach ($events_raw as $event) {
             $event['image_url'] = \PVL\Url::upload(Schedule::getRowImageUrl($event));
             $event['status'] = $event['start_time'] <= time() ? 'now' : 'upcoming';
             $event['range'] = Schedule::getRangeText($event['start_time'], $event['end_time'], $event['is_all_day']);
             if ($event['station_id']) {
                 $sid = $event['station_id'];
                 if (isset($this->stations[$sid])) {
                     $station = $this->stations[$sid];
                     unset($station['nowplaying_data'], $station['streams'], $station['intake_votes']);
                     $event['station'] = $station;
                 }
             }
             $all_events[] = $event;
             for ($i = $event['start_time']; $i <= $event['end_time']; $i += 86400) {
                 $event_date = date('Y-m-d', $i);
                 if (isset($events_by_day[$event_date])) {
                     $events_by_day[$event_date]['events'][] = $event;
                 }
             }
         }
         $event_info = array('all' => $all_events, 'by_day' => $events_by_day);
         Cache::save($event_info, 'pvlive_events', array(), 60);
     }
     $this->view->all_events = $event_info['all'];
     $this->view->events_by_day = $event_info['by_day'];
 }
Esempio n. 3
0
 public static function _runScheduleItems(\Phalcon\DiInterface $di)
 {
     $news_items = array();
     $em = $di->get('em');
     // Pull promoted schedule items.
     $events_raw = $em->createQuery('SELECT st, s FROM \\Entity\\Schedule s
         JOIN s.station st
         WHERE (s.end_time >= :current AND s.start_time <= :future)
         AND (st.banner_url != \'\' AND st.banner_url IS NOT NULL)
         AND s.is_promoted = 1
         ORDER BY s.start_time ASC')->setParameter('current', time())->setParameter('future', strtotime('+1 week'))->getArrayResult();
     $promoted_stations = array();
     foreach ($events_raw as $event) {
         $station_id = $event['station_id'];
         if (isset($promoted_stations[$station_id])) {
             continue;
         } else {
             $promoted_stations[$station_id] = true;
         }
         $range = Schedule::getRangeText($event['start_time'], $event['end_time'], $event['is_all_day']);
         $description = array();
         $description[] = 'Coming up on ' . $event['station']['name'];
         $description[] = $range;
         if (!empty($event['body'])) {
             $description[] = $event['body'];
         }
         // Manually adjust the sorting timestamp for the event if it is in the future.
         $sort_timestamp = $event['start_time'];
         if ($sort_timestamp >= time()) {
             $sort_timestamp = time() - ($sort_timestamp - time());
         }
         $news_items[] = array('id' => 'schedule_' . $event['guid'], 'title' => trim($event['title']), 'source' => 'station', 'body' => implode('<br>', $description), 'image_url' => \PVL\Url::upload($event['station']['banner_url']), 'web_url' => $event['station']['web_url'], 'layout' => 'vertical', 'tags' => array($event['station']['name'], 'Events'), 'sort_timestamp' => $sort_timestamp, 'display_timestamp' => $event['start_time']);
         break;
     }
     return $news_items;
 }