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 SezioniFormInputFilter(); $form = new SezioniForm(); $form->setBindOnValidate(false); $form->setInputFilter($inputFilter->getInputFilter()); $form->setData($post); $this->initializeAdminArea(); $userDetails = $this->recoverUserDetails(); $helper = new SezioniControllerHelper(); $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(); // TODO: upload icon, delete old icon if old icon is set and its file exists $logWriter = new LogWriter($connection); $logWriter->writeLog(array('user_id' => $userDetails->id, 'module_id' => ModulesContainer::contenuti_id, 'message' => "Aggiornata sezione " . $inputFilter->nome, 'type' => 'info', 'reference_id' => $inputFilter->id, 'backend' => 1)); $this->layout()->setVariables(array('messageType' => 'success', 'messageTitle' => 'Sezione aggiornata correttamente', 'messageText' => 'I dati sono stati processati correttamente dal sistema', 'messageShowFormLink' => 1, 'messageShowForm' => 'Torna alla sezione', 'backToSummaryLink' => $this->url()->fromRoute('admin/sezioni-summary', array('lang' => $this->params()->fromRoute('lang'), 'languageSelection' => $this->params()->fromRoute('languageSelection'), 'modulename' => $this->params()->fromRoute('modulename'))), 'backToSummaryText' => "Elenco sezioni")); $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 sezione ", 'type' => 'error', 'description' => $e->getMessage(), 'reference_id' => $inputFilter->id, 'backend' => 1)); $this->layout()->setVariables(array('messageType' => 'danger', 'messageTitle' => 'Errore aggiornamento sezione', 'messageText' => $e->getMessage(), 'form' => $form, 'formInputFilter' => $inputFilter->getInputFilter(), 'messageShowFormLink' => 1, 'messageShowForm' => 'Torna alla sezione')); $this->layout()->setTemplate($this->layout()->getVariable('templateDir') . 'message.phtml'); } }
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 SezioniFormInputFilter(); $form = new SezioniForm(); $form->setBindOnValidate(false); $form->setInputFilter($inputFilter->getInputFilter()); $form->setData($post); $this->initializeAdminArea(); $userDetails = $this->recoverUserDetails(); $helper = new SezioniControllerHelper(); $helper->setConnection($connection); $helper->getConnection()->beginTransaction(); try { if (!$form->isValid()) { throw new NullException("The form is not valid"); } $inputFilter->exchangeArray($form->getData()); $helper->setLoggedUser($userDetails); $helper->insert($inputFilter); $lastInsertId = $helper->getConnection()->lastInsertId(); $helper->getConnection()->commit(); $logWriter = new LogWriter($connection); $logWriter->writeLog(array('user_id' => $userDetails->id, 'module_id' => ModulesContainer::albo_pretorio_id, 'message' => "Inserita nuova sezione " . $inputFilter->nome, 'type' => 'info', 'reference_id' => $lastInsertId, 'backend' => 1)); $this->layout()->setVariables(array('messageType' => 'success', 'messageTitle' => 'Sezione inserita correttamente', 'messageText' => 'Inserire almeno una sottosezione relativa o la stessa non sarà visibile sul sito web.', 'showLinkResetFormAndShowIt' => 1, 'backToSummaryLink' => $this->url()->fromRoute('admin/sezioni-summary', array('lang' => $this->params()->fromRoute('lang'), 'languageSelection' => $this->params()->fromRoute('languageSelection'), 'modulename' => $this->params()->fromRoute('modulename'))), 'backToSummaryText' => "Elenco sezioni", 'insertAgainLabel' => "Inserisci un'altra sezione")); } 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 inserimento nuova sezione: " . $inputFilter->nome, 'type' => 'error', 'description' => $e->getMessage(), 'backend' => 1)); $this->layout()->setVariables(array('messageType' => 'danger', 'messageTitle' => 'Errore inserimento nuova sezione', 'messageText' => 'Messaggio generato: ' . $e->getMessage(), 'form' => $form, 'formInputFilter' => $inputFilter->getInputFilter(), 'messageShowFormLink' => 1, 'messageShowForm' => 'Torna al form di inserimento dati')); } $this->layout()->setTemplate($this->layout()->getVariable('templateDir') . 'message.phtml'); }