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); }
/** * Submit a new station. * * @throws \DF\Exception */ public function stationAction() { $this->em->getFilters()->disable('softdelete'); $user = $this->auth->getLoggedInUser(); // Check for existing submissions. $existing_submissions = $this->em->createQuery('SELECT s, u FROM Entity\\Station s JOIN s.managers u WHERE (s.deleted_at IS NULL OR s.deleted_at IS NOT NULL) AND u.id = :user_id')->setParameter('user_id', $user->id)->getArrayResult(); if ($existing_submissions) { $message = '<b>You have already submitted the following stations to the system:</b>'; $message .= '<ul>'; foreach ($existing_submissions as $station) { if ($station['deleted_at']) { $status = 'Declined'; } elseif ($station['is_active']) { $status = 'Approved'; } else { $status = 'Pending Review'; } $message .= '<li><b>' . $station['name'] . ':</b> ' . $status . '</li>'; } $message .= '</ul>'; $message .= 'Please contact the PVL team for questions related to these stations, and do not resubmit them!'; $this->flash($message, 'info'); } // Initialize the form. $form = new \DF\Form($this->current_module_config->forms->submit_station); if ($_POST && $form->isValid($_POST)) { $data = $form->getValues(); $stream = $data['stream']; unset($data['stream']); $files = $form->processFiles('stations'); foreach ($files as $file_field => $file_paths) { $data[$file_field] = $file_paths[1]; } // Check for existing station by name. $existing_station = Station::getRepository()->findOneBy(array('name' => $data['name'])); if ($existing_station instanceof Station) { throw new \DF\Exception('A station with this name already exists! Please do not submit duplicate stations.'); } // Set up initial station record. $record = new Station(); $record->fromArray($data); $record->is_active = false; $record->save(); // Set up first stream, connected to station. $stream_record = new StationStream(); $stream_record->fromArray($stream); $stream_record->name = 'Primary Stream'; $stream_record->station = $record; $stream_record->is_default = 1; $stream_record->is_active = 1; $stream_record->save(); // Make the current user an administrator of the new station. if (!$this->acl->isAllowed('administer all')) { $user->stations->add($record); $user->save(); } /* * Now notify only PR account. * // Notify all existing managers. $station_managers_raw = StationManager::getAllActiveManagers(); $station_emails = Utilities::ipull($station_managers_raw, 'email'); $network_administrators = Action::getUsersWithAction('administer all'); $network_emails = Utilities::ipull($network_administrators, 'email'); $email_to = array_merge($station_emails, $network_emails); */ $email_to = array('*****@*****.**'); if ($email_to) { \DF\Messenger::send(array('to' => $email_to, 'subject' => 'New Station Submitted For Review', 'template' => 'newstation', 'vars' => array('form' => $form->populate($_POST)))); } $this->alert('Your station has been submitted. Thank you! We will contact you with any questions or additional information.', 'green'); $this->redirectHome(); return; } $this->renderForm($form, 'edit', 'Submit Your Station'); }