public function indexAction() { if ($this->getRequest()->isPost()) { $mainLayout = $this->initializeAdminArea(); $em = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default'); $lang = $this->params()->fromRoute('lang'); $id = $this->params()->fromPost('revisionId'); try { $helper = new AlboPretorioControllerHelper(); $articoloRecord = $helper->recoverWrapperRecordsById(new AlboPretorioArticoliGetterWrapper(new AlboPretorioArticoliGetter($em)), array('id' => $id, 'limit' => 1), $id); $helper->checkRecords($articoloRecord, 'Atto albo pretorio non trovato'); $sezioniRecords = $helper->recoverWrapperRecords(new AlboPretorioSezioniGetterWrapper(new AlboPretorioSezioniGetter($em)), array()); $articoloRecord[0]['checkRettifica'] = 1; $form = new AlboPretorioArticoliForm(); $form->addNote(); $form->addSezioni($helper->formatForDropwdown($sezioniRecords, 'id', 'nome')); $form->addTitolo(); $form->addMainFields(); $form->addScadenze(); $form->setData($articoloRecord[0]); $this->layout()->setVariables(array('form' => $form, 'formAction' => $this->url()->fromRoute('admin/albo-pretorio-update', array('lang' => $lang)), 'formTitle' => $articoloRecord[0]['titolo'], 'formDescription' => "Compila i dati relativi all'atto da inserire sull'albo pretorio", 'templatePartial' => self::formTemplate, 'formBreadCrumbCategory' => array(array('label' => 'Albo pretorio', 'href' => $this->url()->fromRoute('admin/albo-pretorio-summary', array('lang' => $lang)), 'title' => "'Torna all'elenco atti albo pretorio")), 'alboRevisionWarning' => 1, 'alboNumeroAtto' => $articoloRecord[0]['numeroAtto'], 'alboAnnoAtto' => $articoloRecord[0]['anno'])); $this->layout()->setTemplate($mainLayout); } catch (\Exception $e) { $this->layout()->setVariables(array('messageType' => 'warning', 'messageTitle' => 'Errore verificato', 'messageText' => $e->getMessage(), 'showBreadCrumb' => 1, 'formBreadCrumbCategory' => array(array('label' => 'Albo pretorio', 'href' => $this->url()->fromRoute('admin/albo-pretorio-operations', array('lang' => $this->params()->fromRoute('lang'), 'action' => 'publish')), 'title' => "Vai all'elenco atti albo pretorio")), 'dataTableActiveTitle' => 'Rettifica atto', 'templatePartial' => 'message.phtml')); } } else { return $this->redirect()->toRoute('admin/albo-pretorio-summary', array('lang' => $this->params()->fromRoute('lang'))); } }
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 AlboPretorioArticoliFormInputFilter(); $form = new AlboPretorioArticoliForm(); $form->setBindOnValidate(false); $form->setInputFilter($inputFilter->getInputFilter()); $form->setData($post); $this->initializeAdminArea(); $userDetails = $this->recoverUserDetails(); $helper = new AlboPretorioControllerHelper(); $helper->setConnection($connection); $helper->setLoggedUser($userDetails); try { if (!$form->isValid()) { throw new NullException("The form is not valid"); } $inputFilter->exchangeArray($form->getData()); $helper->getConnection()->beginTransaction(); $helper->update($inputFilter); $helper->getConnection()->commit(); $logWriter = new LogWriter($connection); $logWriter->writeLog(array('user_id' => $userDetails->id, 'module_id' => ModulesContainer::contenuti_id, 'message' => "Aggiornato atto albo pretorio " . $inputFilter->titolo, 'type' => 'info', 'description' => '', 'reference_id' => $inputFilter->id, 'backend' => 1)); $this->layout()->setVariables(array('messageType' => 'success', 'messageTitle' => 'Atto albo pretorio aggiornato correttamente', 'messageText' => 'I dati sono stati processati correttamente dal sistema', 'messageShowFormLink' => 1, 'messageShowForm' => "Torna alla modifica dati atto", 'backToSummaryLink' => $this->url()->fromRoute('admin/albo-pretorio-summary', array('lang' => $this->params()->fromRoute('lang'))), 'backToSummaryText' => "Elenco atti albo pretorio", 'attachmentsLink' => $this->url()->fromRoute('admin/attachments-summary', array('lang' => $this->params()->fromRoute('lang'), 'module' => 'albo-pretorio', 'referenceId' => $inputFilter->id)))); $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::albo_pretorio_id, 'message' => "Errore aggiornamento atto albo pretorio", 'type' => 'error', 'description' => $e->getMessage(), 'reference_id' => $inputFilter->id, 'backend' => 1)); $this->layout()->setVariables(array('messageType' => 'danger', 'messageTitle' => 'Errore aggiornamento atto albo pretorio', 'messageText' => $e->getMessage(), 'form' => $form, 'formInputFilter' => $inputFilter->getInputFilter(), 'messageShowFormLink' => 1, 'messageShowForm' => "Torna alla modifica dati atto")); $this->layout()->setTemplate($this->layout()->getVariable('templateDir') . 'message.phtml'); } }
/** * @param array $formDataSample * @return AlboPretorioArticoliForm */ protected function setupForm($formDataSample) { $form = new AlboPretorioArticoliForm(); $form->addTitolo(); $form->addSezioni(array(1 => 'Sezione 1 test', 2 => 'Sezione 2 test', 3 => 'Sezione 3 test')); $form->addNumero(); $form->addAnno(); $form->addMainFields(); $form->addScadenze(); $form->addHomePage(); $form->addFacebook(); $form->addNote(); $inputFilter = new AlboPretorioArticoliFormInputFilter(); $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'); $helper = new AlboPretorioControllerHelper(); try { $sezioniRecords = $helper->recoverWrapperRecords(new AlboPretorioSezioniGetterWrapper(new AlboPretorioSezioniGetter($em)), array('fields' => 'aps.id, aps.nome', 'orderBy' => 'aps.nome ASC')); $helper->checkRecords($sezioniRecords, 'Sezioni non presenti o non rilevate dal sistema. Verificare i dati delle sezioni o inserirne una nuova'); $articoliRecords = $helper->recoverWrapperRecordsById(new AlboPretorioArticoliGetterWrapper(new AlboPretorioArticoliGetter($em)), array('id' => $id, 'limit' => 1), $id); $helper->checkArticoloIsNotAnnulled($articoliRecords); $numeroProgressivo = $helper->recoverNumeroProgressivo(new AlboPretorioArticoliGetterWrapper(new AlboPretorioArticoliGetter($em)), date("Y")); $form = new AlboPretorioArticoliForm(); $form->addSezioni($helper->formatForDropwdown($sezioniRecords, 'id', 'nome')); $form->addTitolo(); $form->addNumero(); $form->addAnno(); $form->addMainFields(); $form->addScadenze(); $form->addHomePage(); if (!empty($articoliRecords)) { $form->setData($articoliRecords[0]); $formAction = $this->url()->fromRoute('admin/albo-pretorio-update', array('lang' => $lang)); $formTitle = $articoliRecords[0]['titolo']; $submitButtonValue = 'Modifica'; } else { $form->addFacebook(); $form->setData(array('anno' => date("Y"), 'numeroAtto' => $numeroProgressivo)); $formAction = $this->url()->fromRoute('admin/albo-pretorio-insert', array('lang' => $lang)); $formTitle = 'Nuovo atto'; $submitButtonValue = 'Inserisci'; } $this->layout()->setVariables(array('form' => $form, 'formAction' => $formAction, 'formTitle' => $formTitle, 'formDescription' => "Compila i dati relativi all'atto da inserire sull'albo pretorio", 'submitButtonValue' => $submitButtonValue, 'templatePartial' => self::formTemplate, 'formBreadCrumbCategory' => array(array('label' => 'Albo pretorio', 'href' => $this->url()->fromRoute('admin/albo-pretorio-summary', array('lang' => $lang)), 'title' => "'Torna all'elenco atti albo pretorio")))); } catch (NullException $e) { $message = $e->getParams(); $this->layout()->setVariables(array('messageType' => $message['type'] ? $message['type'] : 'warning', 'messageTitle' => $message['title'] ? $message['title'] : 'Problema verificato', 'messageText' => $message['text'] ? $message['text'] : $e->getMessage(), 'showBreadCrumb' => 1, 'formBreadCrumbCategory' => 'Albo pretorio', 'templatePartial' => 'message.phtml')); } $this->layout()->setTemplate($mainLayout); }