/**
  * 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 csvAction()
 {
     $id = $this->params()->fromRoute('id');
     $em = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
     $helper = new AlboPretorioControllerHelper();
     $records = $helper->recoverWrapperRecordsById(new AlboPretorioArticoliGetterWrapper(new AlboPretorioArticoliGetter($em)), array('id' => $id, 'limit' => 1), $id);
     if (!empty($records)) {
         $arrayContent = array();
         $arrayContent[] = array('Titolo', 'Numero \\ Anno', 'Sezione', 'Scadenza');
         foreach ($records as $record) {
             $arrayContent[] = array($record['titolo'], $record['numeroAtto'] . ' / ' . $record['anno'], $record['nomeSezione'], $record['dataScadenza']->format("d-m-Y"));
         }
         $csvExportHelper = new CsvExportHelper();
         $content = $csvExportHelper->makeCsvLine($arrayContent);
         $response = $this->getResponse();
         $response->getHeaders()->addHeaderLine('Content-Type', 'text/csv')->addHeaderLine('Content-Disposition', 'attachment; filename="' . Slugifier::slugify($record['titolo']) . '.csv"')->addHeaderLine('Accept-Ranges', 'bytes')->addHeaderLine('Content-Length', strlen($content));
         $response->setContent($content);
         return $response;
     }
 }
 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);
 }