protected function setupForm($formDataSample)
 {
     $form = new AttiConcessioneForm();
     $form->addUfficioResponsabile(array(1 => 'Ufficio 1', 2 => 'Ufficio 2'));
     $form->addResponsabileProcedimento(array(1 => 'Responsabile 1', 2 => 'Responsabile 2'));
     $form->addModalitaAssegnazione(array(1 => 'Modalita 1', 2 => 'Modalita 2'));
     $form->addTitoloDataInserimentoEAnno();
     $inputFilter = new AttiConcessioneFormInputFilter();
     $form->setInputFilter($inputFilter->getInputFilter());
     $form->setData($formDataSample);
     return $form;
 }
 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 AttiConcessioneFormInputFilter();
     $form = new AttiConcessioneForm();
     $form->setBindOnValidate(false);
     $form->setInputFilter($inputFilter->getInputFilter());
     $form->setData($post);
     $this->initializeAdminArea();
     $userDetails = $this->recoverUserDetails();
     $helper = new AttiConcessioneControllerHelper();
     $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);
         $inputFilter->progressivo = $helper->recoverNumeroProgressivo(new AttiConcessioneGetterWrapper(new AttiConcessioneGetter($em)), $inputFilter->anno);
         $lastInsertId = $helper->insert($inputFilter);
         $logWriter = new LogWriter($connection);
         $logWriter->writeLog(array('user_id' => $userDetails->id, 'module_id' => ModulesContainer::atti_concessione, 'message' => "Inserito nuovo atto concessione " . $inputFilter->titolo, 'type' => 'info', 'reference_id' => $lastInsertId, 'backend' => 1));
         $this->layout()->setVariables(array('messageType' => 'success', 'messageTitle' => 'Atto concessione inserito correttamente', 'messageText' => 'I dati sono stati processati correttamente dal sistema', 'showLinkResetFormAndShowIt' => 1, 'backToSummaryLink' => $this->url()->fromRoute('admin/atti-concessione-summary', array('lang' => 'it', 'languageSelection' => 'it', 'modulename' => 'atti-concessione')), 'backToSummaryText' => "Elenco atti", 'insertAgainLabel' => "Inserisci un altro atto"));
         $helper->getConnection()->commit();
     } 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::atti_concessione, 'message' => "Errore inserimento nuovo atto concessione: " . $inputFilter->titolo, 'type' => 'error', 'description' => $e->getMessage(), 'backend' => 1));
         $this->layout()->setVariables(array('messageType' => 'danger', 'messageTitle' => 'Errore inserimento nuovo atto di concessione', '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');
 }
 public function indexAction()
 {
     $mainLayout = $this->initializeAdminArea();
     $em = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
     $id = $this->params()->fromRoute('id');
     $lang = $this->params()->fromRoute('lang');
     try {
         $helper = new AttiConcessioneControllerHelper();
         $respProcRecords = $helper->recoverWrapperRecords(new UsersRespProcGetterWrapper(new UsersRespProcGetter($em)), array());
         $helper->checkRecords($respProcRecords, 'Nessun responsabile procedimento');
         $respProcForDropdown = $helper->formatResponsabiliForDropdown($respProcRecords);
         $sezioniRecords = $helper->recoverWrapperRecords(new UsersSettoriGetterWrapper(new UsersSettoriGetter($em)), array('orderBy' => 'settore.nome'));
         $helper->checkRecords($sezioniRecords, 'Nessuna sezione presente');
         $sezioniRecordsForDropDown = $helper->formatForDropwdown($sezioniRecords, 'id', 'nome');
         $modalitaAssegnazioneRecords = $helper->recoverWrapperRecords(new AttiConcessioneModalitaAssegnazioneGetterWrapper(new AttiConcessioneModalitaAssegnazioneGetter($em)), array());
         $helper->checkRecords($modalitaAssegnazioneRecords, 'Nessuna modalità di assegnazione presente');
         $modAssegnForDropdown = $helper->formatForDropwdown($modalitaAssegnazioneRecords, 'id', 'nome');
         $attiRecords = $helper->recoverWrapperRecordsById(new AttiConcessioneGetterWrapper(new AttiConcessioneGetter($em)), array('aa.id' => $id, 'limit' => 1), $id);
         $form = new AttiConcessioneForm();
         $form->addUfficioResponsabile($sezioniRecordsForDropDown);
         $form->addResponsabileProcedimento($respProcForDropdown);
         $form->addModalitaAssegnazione($modAssegnForDropdown);
         $form->addTitoloDataInserimentoEAnno();
         if (!empty($attiRecords)) {
             $formAction = $this->url()->fromRoute('admin/atti-concessione-update', array('lang' => $lang));
             $formTitle = 'Modifica atto di concessione';
             $formDescription = 'Modifica nuovo atto di concessione';
             $form->setData($attiRecords[0]);
         } else {
             $form->setData(array('anno' => date('Y')));
             $formAction = $this->url()->fromRoute('admin/atti-concessione-insert', array('lang' => $lang));
             $formTitle = 'Nuovo atto di concessione';
             $formDescription = 'Inserisci nuovo atto di concessione';
         }
         $this->layout()->setVariables(array('form' => $form, 'formAction' => $formAction, 'formTitle' => $formTitle, 'formDescription' => $formDescription, 'formBreadCrumbCategory' => 'Atti di concessione', 'formBreadCrumbCategoryLink' => $this->url()->fromRoute('admin/atti-concessione-summary', array('lang' => $lang)), 'templatePartial' => self::formTemplate));
         $this->layout()->setTemplate($mainLayout);
     } catch (\Exception $e) {
         $this->layout()->setVariables(array('messageType' => 'danger', 'messageTitle' => 'Problema verificato', 'messageText' => $e->getMessage(), 'templatePartial' => 'message.phtml'));
         $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 AttiConcessioneFormInputFilter();
     $form = new AttiConcessioneForm();
     $form->setBindOnValidate(false);
     $form->setInputFilter($inputFilter->getInputFilter());
     $form->setData($post);
     $this->initializeAdminArea();
     $userDetails = $this->recoverUserDetails();
     try {
         if (!$form->isValid()) {
             throw new NullException("The form is not valid");
         }
         $inputFilter->exchangeArray($form->getData());
         $helper = new AttiConcessioneControllerHelper();
         $helper->setConnection($connection);
         $helper->getConnection()->beginTransaction();
         $helper->update($inputFilter);
         $helper->getConnection()->commit();
         $logWriter = new LogWriter($connection);
         $logWriter->writeLog(array('user_id' => $userDetails->id, 'module_id' => ModulesContainer::atti_concessione, 'message' => "Aggiornato atto di concessione " . $inputFilter->titolo, 'type' => 'info', 'reference_id' => $inputFilter->id, 'backend' => 1));
         $this->layout()->setVariables(array('messageType' => 'success', 'messageTitle' => 'Atto di concessione aggiornato correttamente', 'messageText' => 'I dati sono stati processati correttamente dal sistema', 'messageShowFormLink' => 1, 'messageShowForm' => 'Torna alla modifica atto', 'backToSummaryLink' => $this->url()->fromRoute('admin/atti-concessione-summary', array('lang' => $this->params()->fromRoute('lang'), 'languageSelection' => $this->params()->fromRoute('languageSelection'), 'modulename' => $this->params()->fromRoute('modulename'))), 'backToSummaryText' => "Elenco atti", 'attachmentsLink' => $this->url()->fromRoute('admin/attachments-summary', array('lang' => $this->params()->fromRoute('lang'), 'module' => 'atti-concessione', 'referenceId' => $inputFilter->id))));
         $this->layout()->setTemplate($this->layout()->getVariable('templateDir') . 'message.phtml');
     } catch (\Exception $e) {
         $logWriter = new LogWriter($connection);
         $logWriter->writeLog(array('user_id' => $userDetails->id, 'module_id' => ModulesContainer::atti_concessione, 'message' => "Errore aggiornamento atto concessione", 'type' => 'error', 'description' => $e->getMessage(), 'reference_id' => $inputFilter->id, 'backend' => 1));
         $this->layout()->setVariables(array('messageType' => 'danger', 'messageTitle' => 'Errore aggiornamento atto di concessione', 'messageText' => $e->getMessage(), 'form' => $form, 'formInputFilter' => $inputFilter->getInputFilter(), 'messageShowFormLink' => 1, 'messageShowForm' => "Torna all'atto di concessione"));
         $this->layout()->setTemplate($this->layout()->getVariable('templateDir') . 'message.phtml');
     }
 }