protected function setupForm($formDataSample)
 {
     $form = new SceltaContraenteForm();
     $inputFilter = new SceltaContraenteFormInputFilter();
     $form->setInputFilter($inputFilter->getInputFilter());
     $form->setData($formDataSample);
     return $form;
 }
 public function indexAction()
 {
     $mainLayout = $this->initializeAdminArea();
     $em = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
     $id = $this->params()->fromRoute('id');
     $helper = new ContrattiPubbliciControllerHelper();
     $recordFromDb = $helper->recoverWrapperRecordsById(new SceltaContraenteGetterWrapper(new SceltaContraenteGetter($em)), array('csc.id' => $id, 'limit' => 1), $id);
     $form = new SceltaContraenteForm();
     if ($recordFromDb) {
         $form->setData($recordFromDb[0]);
         $formAction = $this->url()->fromRoute('admin/contratti-pubblici-scelta-contraente-update', array('lang' => $this->params()->fromRoute('lang')));
         $formTitle = 'Modifica voce scelta del contraente';
         $formDescription = 'Modifica dati e procedi';
         $formBreadCrumbTitle = 'Modifica';
     } else {
         $formAction = $this->url()->fromRoute('admin/contratti-pubblici-scelta-contraente-insert', array('lang' => $this->params()->fromRoute('lang')));
         $formTitle = 'Nuova voce scelta del contraente';
         $formDescription = 'Inserisci voce scelta contraente';
         $formBreadCrumbTitle = 'Nuova';
     }
     $this->layout()->setVariables(array('form' => $form, 'formAction' => $formAction, 'formTitle' => $formTitle, 'formDescription' => $formDescription, 'submitButtonValue' => 'Conferma', 'formBreadCrumbTitle' => $formBreadCrumbTitle, 'formBreadCrumbCategory' => array(array('href' => $this->url()->fromRoute('admin/contratti-pubblici-summary', array('lang' => $this->params()->fromRoute('lang'))), 'title' => 'Elenco contratti pubblici', 'label' => 'Contratti pubblici'), array('href' => $this->url()->fromRoute('admin/contratti-pubblici-scelta-contraente-summary', array('lang' => $this->params()->fromRoute('lang'))), 'title' => 'Elenco voci scelta contraente', 'label' => 'Scelta contraente')), '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 SceltaContraenteFormInputFilter();
     $form = new SceltaContraenteForm();
     $form->setBindOnValidate(false);
     $form->setInputFilter($inputFilter->getInputFilter());
     $form->setData($post);
     $this->initializeAdminArea();
     $userDetails = $this->recoverUserDetails();
     $helper = new SceltaContraenteControllerHelper();
     $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);
         $logWriter = new LogWriter($connection);
         $logWriter->writeLog(array('user_id' => $userDetails->id, 'module_id' => ModulesContainer::contratti_pubblici_id, 'message' => "Inserita nuova voce scelta contraente " . $inputFilter->nomeScelta, 'type' => 'info', 'reference_id' => $lastInsertId, 'backend' => 1));
         $this->layout()->setVariables(array('messageType' => 'success', 'messageTitle' => 'Voce scelta contraente inserita correttamente', 'messageText' => 'I dati sono stati processati correttamente dal sistema', 'showLinkResetFormAndShowIt' => 1, 'backToSummaryLink' => $this->url()->fromRoute('admin/contratti-pubblici-scelta-contraente-summary', array('lang' => $this->params()->fromRoute('lang'))), 'backToSummaryText' => "Elenco voci scelta contraente"));
         $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::contratti_pubblici_id, 'message' => "Errore inserimento nuova voce scelta contraente: " . $inputFilter->nomeScelta, 'type' => 'error', 'description' => $e->getMessage(), 'backend' => 1));
         $this->layout()->setVariables(array('messageType' => 'danger', 'messageTitle' => 'Errore inserimento nuova sezione', 'messageText' => $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');
 }