Ejemplo n.º 1
0
 public function indexAction()
 {
     $mainLayout = $this->initializeAdminArea();
     $id = $this->params()->fromRoute('id');
     $lang = $this->params()->fromRoute('lang');
     $em = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
     $helper = new NewsletterControllerHelper();
     $records = $helper->recoverWrapperRecordsById(new NewsletterGetterWrapper(new NewsletterGetter($em)), array('id' => $id, 'limit' => 1), $id);
     $form = new NewsletterForm();
     if (!empty($records)) {
         $form->setData($records[0]);
         $submitButtonValue = 'Modifica';
         $formTitle = 'Modifica newsletter';
         $formAction = $this->url()->fromRoute('admin/newsletter-update', array('lang' => $lang));
     } else {
         $formTitle = 'Nuova newsletter';
         $submitButtonValue = 'Inserisci';
         $formAction = $this->url()->fromRoute('admin/newsletter-insert', array('lang' => $lang));
     }
     $this->layout()->setVariables(array('formTitle' => $formTitle, 'formDescription' => "Compila i dati relativi a alla newsletter", 'form' => $form, 'formAction' => $formAction, 'submitButtonValue' => $submitButtonValue, 'formBreadCrumbCategory' => 'Newsletter', 'formBreadCrumbCategoryLink' => $this->url()->fromRoute('admin/newsletter-summary', array('lang' => $lang)), 'templatePartial' => self::formTemplate));
     $this->layout()->setTemplate($mainLayout);
 }
 public function indexAction()
 {
     /**
      * @var \Doctrine\ORM\EntityManager $em
      */
     $em = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
     /**
      * @var \Doctrine\DBAL\Connection $connection
      */
     $connection = $em->getConnection();
     $request = $this->getRequest();
     $post = array_merge_recursive($request->getPost()->toArray(), $request->getFiles()->toArray());
     if (!($request->isXmlHttpRequest() or $request->isPost())) {
         return $this->redirect()->toRoute('main');
     }
     $inputFilter = new NewsletterFormInputFilter();
     $form = new NewsletterForm();
     $form->setBindOnValidate(false);
     $form->setInputFilter($inputFilter->getInputFilter());
     $form->setData($post);
     $this->initializeAdminArea();
     $userDetails = $this->recoverUserDetails();
     $helper = new NewsletterControllerHelper();
     $helper->setConnection($connection);
     $helper->getConnection()->beginTransaction();
     $helper->setLoggedUser($userDetails);
     try {
         if (!$form->isValid()) {
             throw new NullException("The form is not valid");
         }
         $inputFilter->exchangeArray($form->getData());
         $helper->update($inputFilter);
         $helper->getConnection()->commit();
         $logWriter = new LogWriter($connection);
         $logWriter->writeLog(array('user_id' => $userDetails->id, 'module_id' => ModulesContainer::contenuti_id, 'message' => "Aggiornata newsletter " . $inputFilter->title, 'type' => 'info', 'reference_id' => $inputFilter->id, 'backend' => 1));
         $this->layout()->setVariables(array('messageType' => 'success', 'messageTitle' => 'Newsletter aggiornata correttamente', 'messageText' => 'I dati sono stati processati correttamente dal sistema', 'messageShowFormLink' => 1, 'messageShowForm' => 'Torna alla newsletter', 'backToSummaryLink' => $this->url()->fromRoute('admin/newsletter-summary', array('lang' => $this->params()->fromRoute('lang'), 'languageSelection' => $this->params()->fromRoute('languageSelection'))), 'backToSummaryText' => "Elenco newsletter"));
         $this->layout()->setTemplate($this->layout()->getVariable('templateDir') . 'message.phtml');
     } catch (\Exception $e) {
         try {
             $helper->getConnection()->rollBack();
         } catch (\Doctrine\DBAL\ConnectionException $exDb) {
         }
         $logWriter = new LogWriter($connection);
         $logWriter->writeLog(array('user_id' => $userDetails->id, 'module_id' => ModulesContainer::contenuti_id, 'message' => "Errore aggiornamento newsletter", 'type' => 'error', 'description' => $e->getMessage(), 'reference_id' => $inputFilter->id, 'backend' => 1));
         $this->layout()->setVariables(array('messageType' => 'danger', 'messageTitle' => 'Errore aggiornamento newsletter', 'messageText' => $e->getMessage(), 'form' => $form, 'formInputFilter' => $inputFilter->getInputFilter(), 'messageShowFormLink' => 1, 'messageShowForm' => 'Torna alla newsletter'));
         $this->layout()->setTemplate($this->layout()->getVariable('templateDir') . 'message.phtml');
     }
 }