public function editAction() { $form = new \DF\Form($this->current_module_config->forms->station); if ($this->hasParam('id')) { $id = (int) $this->getParam('id'); $record = Record::find($id); $form->setDefaults($record->toArray(FALSE, TRUE)); } if ($_POST && $form->isValid($_POST)) { $data = $form->getValues(); if (!$record instanceof Record) { $record = new Record(); } $files = $form->processFiles('stations'); foreach ($files as $file_field => $file_paths) { $data[$file_field] = $file_paths[1]; } $record->fromArray($data); $record->save(); // Clear station cache. \DF\Cache::remove('stations'); $this->alert('Changes saved.', 'green'); return $this->redirectFromHere(array('action' => 'index', 'id' => NULL)); } $this->renderForm($form, 'edit', 'Edit Record'); }
public function editAction() { $form_config = $this->current_module_config->forms->source; $form = new \DF\Form($form_config); if ($this->hasParam('id')) { $record = PodcastSource::getRepository()->findOneBy(array('id' => $this->getParam('id'), 'podcast_id' => $this->podcast->id)); $form->setDefaults($record->toArray()); } if (!empty($_POST) && $form->isValid($_POST)) { $data = $form->getValues(); if (!$record instanceof PodcastSource) { $record = new PodcastSource(); $record->podcast = $this->podcast; } $record->fromArray($data); $record->save(); // Clear cache. \DF\Cache::remove('podcasts'); // Immediately re-process this podcast. \PVL\PodcastManager::processPodcast($this->podcast); $this->alert('<b>Podcast source updated.</b>', 'green'); $this->redirectFromHere(array('action' => 'index', 'id' => NULL)); return; } $title = ($this->hasParam('id') ? 'Edit' : 'Add') . ' Podcast Source'; $this->renderForm($form, 'edit', $title); }
public function editAction() { if ($this->station->category == 'video') { $form_config = $this->current_module_config->forms->video_stream; } else { $form_config = $this->current_module_config->forms->radio_stream; } $form = new \DF\Form($form_config); if ($this->hasParam('id')) { $record = StationStream::getRepository()->findOneBy(array('id' => $this->getParam('id'), 'station_id' => $this->station->id)); $form->setDefaults($record->toArray()); } if (!empty($_POST) && $form->isValid($_POST)) { $data = $form->getValues(); if (!$record instanceof StationStream) { $record = new StationStream(); $record->station = $this->station; } $record->fromArray($data); $record->save(); // Ensure at least one stream is default. $this->station->checkDefaultStream(); // Clear station cache. \DF\Cache::remove('stations'); // Immediately load "Now Playing" data for the added/updated stream. if ($data['is_active'] == 0) { $record->save(); $this->alert('<b>Stream updated, but is currently inactive.</b><br>The system will not retrieve Now Playing data about this stream until it is activated.', 'red'); } elseif ($this->station->category == 'video') { $np = \PVL\NowPlaying::processVideoStream($record, $this->station, true); $record->save(); if ($np['meta']['status'] == 'online') { $this->alert('<b>Stream updated, and currently showing as online.</b>', 'green'); } else { $this->alert('<b>Stream updated, but is currently offline.</b>', 'red'); } } else { $np = \PVL\NowPlaying::processAudioStream($record, $this->station, true); $record->save(); if ($np['status'] != 'offline') { $song = $np['current_song']; $this->alert('<b>Stream updated and successfully connected.</b><br>The currently playing song is reporting as "' . $song['title'] . '" by "' . $song['artist'] . '" with ' . $np['listeners']['current'] . ' tuned in.', 'green'); } else { $this->alert('<b>Stream updated, but is currently offline.</b><br>The system could not retrieve now-playing information about this stream. Verify that the station is online and the URLs are correct.', 'red'); } } $this->redirectFromHere(array('action' => 'index', 'id' => NULL)); return; } $title = ($this->hasParam('id') ? 'Edit' : 'Add') . ' Station Stream'; $this->renderForm($form, 'edit', $title); }
public function editAction() { $form = $this->_getForm(); $form->setDefaults($this->station->toArray()); if (!empty($_POST) && $form->isValid($_POST)) { $data = $form->getValues(); $files = $form->processFiles('stations'); foreach ($files as $file_field => $file_paths) { $data[$file_field] = $file_paths[1]; } $this->station->fromArray($data); $this->station->save(); // Clear station cache. \DF\Cache::remove('stations'); $this->redirectFromHere(array('action' => 'index', 'id' => NULL)); return; } $this->renderForm($form, 'edit', 'Edit Station Profile'); }
public static function run() { $di = \Phalcon\Di::getDefault(); $em = $di->get('em'); // Assemble news items from other sources. $news_items_raw = array(self::_runTumblrNews($di), self::_runConventionPromotions($di), self::_runPodcastEpisodes($di), self::_runScheduleItems($di)); $news_items = array(); foreach ($news_items_raw as $item_group) { $news_items = array_merge($news_items, (array) $item_group); } // Replace/insert into database. $news_stats = array('inserted' => 0, 'updated' => 0, 'deleted' => 0); if (!empty($news_items)) { $old_news_raw = NetworkNews::fetchAll(); $old_news = array(); foreach ($old_news_raw as $old_row) { $old_news[$old_row->id] = $old_row; } // Update or insert items. foreach ($news_items as $item) { if (isset($old_news[$item['id']])) { $news_stats['updated']++; $record = $old_news[$item['id']]; } else { $news_stats['inserted']++; $record = new NetworkNews(); } $record->fromArray($item); $em->persist($record); unset($old_news[$item['id']]); } // Delete unreferenced items. foreach ($old_news as $item_id => $item_to_remove) { $news_stats['deleted']++; $em->remove($item_to_remove); } $em->flush(); // Flush cache of homepage news. \DF\Cache::remove('homepage_featured_news'); } \PVL\Debug::print_r($news_stats); }
protected function _flushConventionCache() { \DF\Cache::remove('homepage_conventions'); }