public function viewAction() { $id = $this->getParam('id'); $station = Station::find($id); if ($station->is_active) { throw new \DF\Exception\DisplayOnly('This station has already been reviewed and is active.'); } $station_form = new \DF\Form($this->module_config['frontend']->forms->submit_station); $station_form->populate($station->toArray()); $form = new \DF\Form($this->current_module_config->forms->vote); if ($_POST && $form->isValid($_POST)) { $data = $form->getValues(); $data['name'] = $this->vote_name; $intake_votes = (array) $station->intake_votes; if ($data['decision'] == 'Abstain') { unset($intake_votes[$this->vote_hash]); } else { $intake_votes[$this->vote_hash] = $data; } $station->intake_votes = $intake_votes; $station->save(); $this->alert('Your vote has been submitted. Thank you for your feedback.', 'green'); $this->redirectFromHere(array('action' => 'index', 'id' => NULL)); return; } $this->view->station_form = $station_form; $this->view->form = $form; }
/** * Submit a new show/podcast. * * @throws \DF\Exception */ public function showAction() { $this->em->getFilters()->disable('softdelete'); $user = $this->auth->getLoggedInUser(); // Check for existing submissions. $existing_submissions = $this->em->createQuery('SELECT p, u FROM Entity\\Podcast p JOIN p.managers u WHERE (p.deleted_at IS NULL OR p.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 shows to the system:</b>'; $message .= '<ul>'; foreach ($existing_submissions as $podcast) { if ($podcast['deleted_at']) { $status = 'Declined'; } elseif ($podcast['is_approved']) { $status = 'Approved'; } else { $status = 'Pending Review'; } $message .= '<li><b>' . $podcast['name'] . ':</b> ' . $status . '</li>'; } $message .= '</ul>'; $message .= 'Please contact the PVL team for questions related to these shows, and do not resubmit them!'; $this->flash($message, 'info'); } // Initialize the form. $form = new \DF\Form($this->current_module_config->forms->submit_show); if ($_POST && $form->isValid($_POST)) { $data = $form->getValues(); $files = $form->processFiles('podcasts'); foreach ($files as $file_field => $file_paths) { $data[$file_field] = $file_paths[1]; } // Check for existing podcast by name. $existing_podcast = Podcast::getRepository()->findOneBy(array('name' => $data['name'])); if ($existing_podcast instanceof Podcast) { throw new \DF\Exception('A podcast with this name already exists! Please do not submit duplicate stations.'); } // Set up initial station record. $record = new Podcast(); $record->fromArray($data); $record->is_approved = false; $record->contact_email = $user->email; $record->save(); // Make the current user an administrator of the new podcast. if (!$this->acl->isAllowed('administer all')) { $user->podcasts->add($record); $user->save(); } // Notify all existing managers. $network_administrators = Action::getUsersWithAction('administer all'); $email_to = Utilities::ipull($network_administrators, 'email'); if ($email_to) { \DF\Messenger::send(array('to' => $email_to, 'subject' => 'New Podcast/Show Submitted For Review', 'template' => 'newshow', 'vars' => array('form' => $form->populate($_POST)))); } $this->alert('Your show 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 Show'); }