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'); }
/** * 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'); }