/**
  * Annull atto and redirect to summary
  */
 public function annullAction()
 {
     if ($this->getServiceLocator()->get('request')->isPost()) {
         $em = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
         $userDetails = $this->recoverUserDetails();
         $id = $this->params()->fromPost('annullId');
         $helper = new AlboPretorioControllerHelper();
         $helper->setConnection($em->getConnection());
         $helper->getConnection()->beginTransaction();
         try {
             $record = $helper->recoverWrapperRecordsById(new AlboPretorioArticoliGetterWrapper(new AlboPretorioArticoliGetter($em)), array('id' => $id, 'limit' => 1), $id);
             $helper->annullArticle($id);
             $helper->getConnection()->commit();
             $this->log(array('user_id' => $userDetails->id, 'message' => "Pubblicato atto albo pretorio " . $record[0]['titolo'], 'type' => 'info', 'backend' => 1, 'module_id' => ModulesContainer::albo_pretorio_id, 'reference_id' => $record[0]['id']));
         } catch (\Exception $e) {
             try {
                 $helper->getConnection()->rollBack();
             } catch (\Doctrine\DBAL\ConnectionException $exDb) {
             }
             $this->log(array('user_id' => $userDetails->id, 'message' => "Errore pubblicazione atto albo pretorio " . $record[0]['titolo'] . ' Messaggio generato: ' . $e->getMessage(), 'type' => 'error', 'backend' => 1, 'module_id' => ModulesContainer::albo_pretorio_id, 'reference_id' => $record[0]['id']));
             // TODO: redirect to a message page and show an error message
         }
     }
     return $this->redirectToSummary();
 }
 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')));
     }
 }
 /**
  * @return PdfModel
  */
 public function indexAction()
 {
     $em = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
     $id = $this->params()->fromRoute('id');
     $helper = new AlboPretorioControllerHelper();
     $records = $helper->recoverWrapperRecordsById(new AlboPretorioArticoliGetterWrapper(new AlboPretorioArticoliGetter($em)), array('id' => $id, 'limit' => 1), $id);
     $pdf = new PdfModel();
     $pdf->setOption('filename', 'albo-pretorio-relata-atto-' . $records[0]['id']);
     $pdf->setOption('paperSize', 'a4');
     $pdf->setOption('paperOrientation', 'landscape');
     $pdf->setVariables(array('record' => $records[0]));
     return $pdf;
 }
 public function indexAction()
 {
     $mainLayout = $this->initializeAdminArea();
     $page = $this->params()->fromRoute('page');
     $em = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
     $userDetails = $this->recoverUserDetails();
     $acl = $userDetails->acl;
     $translator = $this->getServiceLocator()->get('translator');
     $helper = new AlboPretorioControllerHelper();
     $wrapper = $helper->recoverWrapperRecordsPaginator(new EntiTerziGetterWrapper(new EntiTerziGetter($em)), array('orderBy' => 'ret.id DESC'), $page);
     $paginatorRecords = $wrapper->setupRecords();
     $this->layout()->setVariables(array('tableTitle' => $translator->translate('Rubrica enti terzi'), 'tableDescription' => $wrapper->getPaginator()->getTotalItemCount() . $translator->translate(' enti in archivio'), 'columns' => array("Nome", "Email", " ", $acl->hasResource('enti_terzi_delete') ? " " : null), 'paginator' => $wrapper->getPaginator(), 'records' => $this->formatRecordsToShowOnTable($paginatorRecords), 'templatePartial' => self::summaryTemplate));
     $this->layout()->setTemplate($mainLayout);
 }
 /**
  * Albo atto details page
  */
 public function detailsAction()
 {
     $mainLayout = $this->initializeFrontendWebsite();
     $em = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
     $id = $this->params()->fromRoute('id');
     try {
         $helper = new AlboPretorioControllerHelper();
         $wrapper = $helper->recoverWrapperById(new AlboPretorioArticoliGetterWrapper(new AlboPretorioArticoliGetter($em)), array('id' => $id, 'limit' => 1), $id);
         $attoRecord = $wrapper->getRecords();
         $helper->checkRecords($attoRecord, 'Nessun atto albo pretorio trovato');
         $wrapper->setEntityManager($em);
         $records = $wrapper->addAttachmentsFromRecords($attoRecord, array('moduleId' => ModulesContainer::albo_pretorio_id, 'noScaduti' => 1, 'orderBy' => 'a.position'));
         $this->layout()->setVariables(array('records' => $records, 'templatePartial' => 'albo-pretorio/albo-pretorio-details.phtml'));
     } catch (\Exception $e) {
         $this->layout()->setVariables(array('messageType' => 'secondary', 'moduleLabel' => "Albo pretorio", 'messageTitle' => "Nessun albo pretorio trovato", 'messageText' => "Impossibile visualizzare i dati richiesti sul sito pubblico", '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 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');
     }
 }
 public function indexAction()
 {
     $mainLayout = $this->initializeAdminArea();
     $page = $this->params()->fromRoute('page');
     $perPage = $this->params()->fromRoute('perpage');
     $em = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
     $helper = new AlboPretorioControllerHelper();
     $sessionContainer = new SessionContainer();
     $sessionSearch = $sessionContainer->offsetGet(AlboPretorioSearchController::sessionIdentifier);
     try {
         $arraySearch = $helper->recoverArrayQuerySearch($sessionSearch);
         $sezioniRecords = $helper->recoverWrapperRecords(new AlboPretorioSezioniGetterWrapper(new AlboPretorioSezioniGetter($em)), array('orderBy' => 'aps.nome ASC'));
         $helper->checkRecords($sezioniRecords, 'Nessuna sezione presente');
         $alboArticoliWrapper = $helper->recoverWrapperRecordsPaginator(new AlboPretorioArticoliGetterWrapper(new AlboPretorioArticoliGetter($em)), $arraySearch, $page, $perPage);
         $formSearch = new AlboPretorioFormSearch();
         $formSearch->addYears();
         $formSearch->addSezioni($helper->formatForDropwdown($sezioniRecords, 'id', 'nome'));
         $formSearch->addCheckExpired();
         $formSearch->addSubmitButton();
         $formSearch->addResetButton();
         $formSearch->addHomePage();
         if (!empty($sessionSearch)) {
             $formSearch->setData(array('numero_progressivo' => $sessionSearch['numero_progressivo'], 'numero_atto' => $sessionSearch['numero_atto'], 'mese' => $sessionSearch['mese'], 'anno' => $sessionSearch['anno'], 'sezione' => $sessionSearch['sezione'], 'testo' => $sessionSearch['testo'], 'home' => $sessionSearch['home'], 'expired' => $sessionSearch['expired']));
         }
         $alboArticoliRecords = $alboArticoliWrapper->setupRecords();
         $alboArticoliWrapper->setEntityManager($em);
         $alboArticoliWrapper->addAttachmentsFromRecords($alboArticoliRecords, array('moduleId' => ModulesContainer::albo_pretorio_id));
         $paginator = $alboArticoliWrapper->getPaginator();
         $paginatorCount = $paginator->getTotalItemCount();
         $tableDescription = $paginatorCount . " atti in archivio. ";
         if ($paginatorCount > 0) {
             $alboStatisticsRecords = $helper->recoverWrapperRecords(new AlboPretorioArticoliGetterWrapper(new AlboPretorioArticoliGetter($em)), array_merge($arraySearch, array('fields' => '
                         (SELECT COUNT(alboArt.id) FROM Application\\Entity\\ZfcmsComuniAlboArticoli alboArt WHERE alboArt.attivo = 0) AS disattivati,
                         (SELECT COUNT(aArt.id) FROM Application\\Entity\\ZfcmsComuniAlboArticoli aArt WHERE aArt.annullato = 1) AS annullati,
                         (SELECT COUNT(aa.id) FROM Application\\Entity\\ZfcmsComuniAlboArticoli aa WHERE aa.pubblicare = 0) AS nonPubblicati,
                         (SELECT COUNT(aHome.id) FROM Application\\Entity\\ZfcmsComuniAlboArticoli aHome WHERE aHome.pubblicare = 0) AS inHome
                     ', 'limit' => 1)));
             $tableDescription .= $alboStatisticsRecords[0]['disattivati'] . ' disattivati';
             $tableDescription .= ', ' . $alboStatisticsRecords[0]['annullati'] . ' annullati';
             $tableDescription .= ', ' . $alboStatisticsRecords[0]['nonPubblicati'] . ' non pubblicati';
             $tableDescription .= ', ' . $alboStatisticsRecords[0]['inHome'] . ' presenti in home page';
         }
         $this->layout()->setVariables(array('formSearch' => $formSearch, 'tableTitle' => 'Albo pretorio', 'tableDescription' => $tableDescription, 'columns' => array(array('label' => 'Num \\ Anno', 'width' => '10%'), array('label' => 'Titolo', 'width' => '20%'), 'Sezione', 'Date', 'Inserito da', ' ', ' ', ' ', ' ', ' ', ' '), 'sessionSearch' => $sessionSearch, 'paginator' => $paginator, 'records' => $this->formatArticoliRecords($alboArticoliRecords), 'templatePartial' => 'datatable/datatable_albo_pretorio.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 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);
 }
 /**
  * @return \Zend\Http\Response|JsonModel
  */
 public function jsonAction()
 {
     $this->initializeFrontendWebsite();
     $em = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
     $id = $this->params()->fromRoute('id');
     $helper = new AlboPretorioControllerHelper();
     $wrapper = $helper->recoverWrapperById(new AlboPretorioArticoliGetterWrapper(new AlboPretorioArticoliGetter($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('Titolo' => $record['titolo'], 'Numero' => $record['numeroAtto'], 'Anno' => $record['anno'], 'Scadenza' => $record['dataScadenza']->format("d-m-Y"), 'Sezione' => $record['nomeSezione']));
 }
 public function testPublishArticle()
 {
     $this->helper->setConnection($this->getConnectionMock());
     $this->assertEquals($this->helper->publishArticle(1, 1), 1);
 }