/** * @param $formDataSample * @return AlboPretorioSezioniForm */ protected function setupForm($formDataSample) { $form = new AlboPretorioSezioniForm(); $inputFilter = new AlboPretorioSezioniFormInputFilter(); $form->setInputFilter($inputFilter->getInputFilter()); $form->setData($formDataSample); return $form; }
public function indexAction() { $mainLayout = $this->initializeAdminArea(); $id = $this->params()->fromRoute('id'); $lang = $this->params()->fromRoute('lang'); $em = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default'); if (is_numeric($id)) { $wrapper = new AlboPretorioSezioniGetterWrapper(new AlboPretorioSezioniGetter($em)); $wrapper->setInput(array("id" => $id, 'limit' => 1)); $wrapper->setupQueryBuilder(); $sezioneRecord = $wrapper->getRecords(); } $form = new AlboPretorioSezioniForm(); if (!empty($sezioneRecord)) { $form->setData($sezioneRecord[0]); $formTitle = $sezioneRecord[0]['nome']; $formAction = $this->url()->fromRoute('admin/albo-pretorio-sezioni-update', array('lang' => $lang)); } else { $formTitle = 'Nuova sezione'; $formAction = $this->url()->fromRoute('admin/albo-pretorio-sezioni-insert', array('lang' => $lang)); } $this->layout()->setVariables(array('formTitle' => $formTitle, 'formDescription' => 'Inserisci dati nuova sezione albo pretorio', 'form' => $form, 'formAction' => $formAction, 'formBreadCrumbTitle' => 'Modifica', 'formBreadCrumbCategory' => array(array('label' => 'Albo pretorio', 'href' => $this->url()->fromRoute('admin/albo-pretorio-summary', array('lang' => $lang)), 'title' => 'Albo pretorio'), array('label' => 'Sezioni', 'href' => $this->url()->fromRoute('admin/albo-pretorio-sezioni-summary', array('lang' => $lang)), 'title' => 'Elenco sezioni albo pretorio')), '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 AlboPretorioSezioniFormInputFilter(); $form = new AlboPretorioSezioniForm(); $form->setBindOnValidate(false); $form->setInputFilter($inputFilter->getInputFilter()); $form->setData($post); $this->initializeAdminArea(); $userDetails = $this->recoverUserDetails(); $helper = new AlboPretorioSezioniControllerHelper(); $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); $lastInsertId = $helper->insert($inputFilter); $helper->getConnection()->commit(); $logWriter = new LogWriter($connection); $logWriter->writeLog(array('user_id' => $userDetails->id, 'module_id' => ModulesContainer::albo_pretorio_id, 'message' => "Inserita nuova sezione albo pretorio " . $inputFilter->nome, 'type' => 'info', 'reference_id' => $lastInsertId, 'backend' => 1)); $this->layout()->setVariables(array('messageType' => 'success', 'messageTitle' => 'Sezione albo pretorio inserita correttamente', 'messageText' => 'I dati sono stati processati correttamente dal sistema', 'showLinkResetFormAndShowIt' => 1, 'backToSummaryLink' => $this->url()->fromRoute('admin/albo-pretorio-sezioni-summary', array('lang' => $this->params()->fromRoute('lang'))), 'backToSummaryText' => "Elenco sezioni", 'insertAgainLabel' => "Inserisci un'altra sezione")); } catch (\Exception $e) { try { $helper->getConnection()->rollBack(); } catch (\Doctrine\DBAL\ConnectionException $e) { } $logWriter = new LogWriter($connection); $logWriter->writeLog(array('user_id' => $userDetails->id, 'module_id' => ModulesContainer::albo_pretorio_id, 'message' => "Errore inserimento nuova sezione: " . $inputFilter->nome, 'description' => $e->getMessage(), 'type' => 'error', 'backend' => 1)); $this->layout()->setVariables(array('messageType' => 'danger', 'messageTitle' => 'Errore inserimento nuova sezione albo pretorio ' . $inputFilter->nome . ' - ' . $e->getMessage(), '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'); }