/**
  * @return JsonModel|\Zend\Http\Response
  */
 public function jsonAction()
 {
     $this->initializeFrontendWebsite();
     $em = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
     $id = $this->params()->fromRoute('id');
     $helper = new AttiConcessioneControllerHelper();
     $wrapper = $helper->recoverWrapperById(new AttiConcessioneGetterWrapper(new AttiConcessioneGetter($em)), array('id' => $id, 'limit' => 1), $id);
     $wrapper->setEntityManager($em);
     $records = $wrapper->addAttachmentsFromRecords($wrapper->getRecords(), array());
     if (empty($records)) {
         return $this->redirectForUnvalidAccess();
     }
     $record = $records[0];
     return new JsonModel(array('Numero \\ Anno' => $record['progressivo'] . ' \\ ' . $record['anno'], 'Beneficiario CF / PIVA' => $record['beneficiario'], 'Importo' => $record['importo'], 'Modalità Assegnazione' => $record['nomemodAssegnazione'], 'Ufficio e responsabile del servizio' => $record['nomeSezione'] . ' ' . $record['nomeResponsabileProc'], "Norma o titolo a base dell'attribuzione" => $record['titolo']));
 }
 /**
  * Atto concessione details
  */
 public function detailsAction()
 {
     $mainLayout = $this->initializeFrontendWebsite();
     $em = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
     $id = $this->params()->fromRoute('id');
     try {
         $helper = new AttiConcessioneControllerHelper();
         $wrapper = $helper->recoverWrapperById(new AttiConcessioneGetterWrapper(new AttiConcessioneGetter($em)), array('id' => $id, 'limit' => 1), $id);
         $attoRecord = $wrapper->getRecords();
         $helper->checkRecords($attoRecord, 'Nessun atto di concessione trovato');
         $wrapper->setEntityManager($em);
         $records = $wrapper->addAttachmentsFromRecords($attoRecord, array('moduleId' => ModulesContainer::atti_concessione, 'noScaduti' => 1, 'orderBy' => 'ao.position'));
         $this->layout()->setVariables(array('records' => $records, 'templatePartial' => 'atti-concessione/atti-concessione-details.phtml'));
     } catch (\Exception $e) {
         $this->layout()->setVariables(array('messageType' => 'secondary', 'moduleLabel' => "Atti di concessione", 'messageTitle' => "Nessun atto di concessione trovato", 'messageText' => "Impossibile visualizzare i dati richiesti", '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');
     }
 }
 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();
     $page = $this->params()->fromRoute('page');
     $em = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
     try {
         $helper = new AttiConcessioneControllerHelper();
         $yearsRecords = $helper->recoverWrapperRecords(new AttiConcessioneGetterWrapper(new AttiConcessioneGetter($em)), array('fields' => 'DISTINCT(atti.anno) AS year', 'orderBy' => 'atti.id DESC'), $page, null);
         $wrapperArticoli = $helper->recoverWrapperRecordsPaginator(new AttiConcessioneGetterWrapper(new AttiConcessioneGetter($em)), array('orderBy' => 'atti.id DESC'), $page, null);
         $settoriRecords = $helper->recoverWrapperRecords(new UsersSettoriGetterWrapper(new UsersSettoriGetter($em)), array('orderBy' => 'settore.nome'));
         $yearsForDropdown = $helper->formatYears($yearsRecords);
         $settoriForDropDown = $helper->formatForDropwdown($settoriRecords, 'id', 'nome');
         $form = new AttiConcessioneFormSearch();
         $form->addAnno($yearsForDropdown);
         $form->addMainElements();
         $form->addUfficio($settoriForDropDown);
         $form->addSubmitSearchButton();
         $form->addResetButton();
         $paginator = $wrapperArticoli->getPaginator();
         $paginatorItemCount = $paginator->getTotalItemCount();
         $wrapperArticoli->setEntityManager($em);
         $paginatorRecords = $this->formatArticoliRecords($wrapperArticoli->addAttachmentsFromRecords($wrapperArticoli->setupRecords(), array('moduleId' => ModulesContainer::atti_concessione)));
         $formSearch = new AttiConcessioneFormSearch();
         $formSearch->addMainElements();
         $formSearch->addAnno($yearsForDropdown);
         $formSearch->addUfficio($settoriForDropDown);
         $formSearch->addSubmitSearchButton();
         if (empty($paginatorRecords)) {
             $this->layout()->setVariables(array('messageType' => 'warning', 'messageTitle' => 'Nessun atto di concessione presente', 'messageText' => 'Nessun atto di concessione presente in archivio', 'showBreadCrumb' => 1, 'dataTableActiveTitle' => 'Atti di concessione', 'templatePartial' => 'message.phtml'));
             $this->layout()->setTemplate($mainLayout);
             return true;
         }
         $this->layout()->setVariables(array('tableTitle' => 'Atti di concessione', 'tableDescription' => $paginatorItemCount . " atti in archivio", 'tablesetter' => 'atti-concessione', 'formSearch' => $formSearch, 'columns' => array("Ufficio-Responsabile del Servizio - Responsabile del Procedimento", "Num / Anno", "CF / P. IVA Beneficiario", "Modalità Assegnazione", "Importo", "Norma o Titolo a base dell'attribuzione", "Date", " ", " ", " "), 'paginator' => $paginator, 'records' => $paginatorRecords, 'templatePartial' => 'datatable/datatable_atti_concessione.phtml'));
     } catch (\Exception $e) {
         $this->layout()->setVariables(array('messageType' => 'warning', 'messageTitle' => 'Problema verificato', 'messageText' => $e->getMessage(), 'templatePartial' => 'message.phtml'));
     }
     $this->layout()->setTemplate($mainLayout);
 }
 public function testFormatResponsabiliForDropdown()
 {
     $this->helper->formatResponsabiliForDropdown(array(1 => 'Responsabile 1', 2 => 'Responsabile 2'));
 }
 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);
     }
 }