Esempio n. 1
0
 public function editAction()
 {
     $form = new \DF\Form($this->current_module_config->forms->podcast);
     if ($this->hasParam('id')) {
         $id = (int) $this->getParam('id');
         $record = Record::find($id);
         $form->setDefaults($record->toArray(TRUE, TRUE));
     }
     if ($_POST && $form->isValid($_POST)) {
         $data = $form->getValues();
         if (!$record instanceof Record) {
             $record = new Record();
         }
         $files = $form->processFiles('podcasts');
         foreach ($files as $file_field => $file_paths) {
             $data[$file_field] = $file_paths[1];
         }
         $record->fromArray($data);
         $record->save();
         $this->alert('Changes saved.', 'green');
         return $this->redirectFromHere(array('action' => 'index', 'id' => NULL));
     }
     $this->renderForm($form, 'edit', 'Edit Record');
 }
Esempio n. 2
0
 /**
  * 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');
 }