public function indexAction()
 {
     $mainLayout = $this->initializeAdminArea();
     $id = $this->params()->fromRoute('id');
     $em = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
     try {
         $helper = new StatoCivileControllerHelper();
         $sezioniRecords = $helper->recoverWrapperRecords(new StatoCivileSezioniGetterWrapper(new StatoCivileSezioniGetter($em)), array('orderBy' => ''));
         $helper->checkRecords($sezioniRecords, 'Nessuna sezione presente');
         $sezioniForDropDown = $helper->formatForDropwdown($sezioniRecords, 'id', 'nome');
         $records = $helper->recoverWrapperRecordsById(new StatoCivileGetterWrapper(new StatoCivileGetter($em)), array('id' => $id, 'limit' => 1), $id);
         $form = new StatoCivileForm();
         $form->addSezioni($sezioniForDropDown);
         $form->addDates();
         if (empty($records)) {
             $form->setData(array('data' => date('Y-m-d H:i:s', strtotime(date("Y-m-d H:i:s") . ' + 8 days')), 'scadenza' => date('Y-m-d H:i:s', strtotime(date("Y-m-d H:i:s") . ' + 8 days')), 'numero_progressivo' => ''));
             $formAction = $this->url()->fromRoute('admin/stato-civile-insert', array('lang' => $this->params()->fromRoute('lang')));
             $formTitle = 'Nuovo atto stato civile';
         } else {
             $form->setData($records[0]);
             $formAction = $this->url()->fromRoute('admin/stato-civile-update', array('lang' => $this->params()->fromRoute('lang')));
             $formTitle = 'Modifica atto';
         }
         $this->layout()->setVariables(array('form' => $form, 'formTitle' => $formTitle, 'formDescription' => '&Egrave; consigliabile inserire <strong>testi brevi sul tema trattato</strong>, possibilmente in minuscolo e con solo la prima iniziale maiuscola', 'formAction' => $formAction, 'formBreadCrumbCategory' => 'Stato civile', 'formBreadCrumbCategoryLink' => $this->url()->fromRoute('admin/stato-civile-summary', array('lang' => $this->params()->fromRoute('lang'))), 'templatePartial' => self::formTemplate));
     } catch (\Exception $e) {
         $this->layout()->setVariables(array('messageType' => 'danger', 'messageTitle' => 'Errore verificato', 'messageText' => $e->getMessage(), 'templatePartial' => 'message.phtml'));
     }
     $this->layout()->setTemplate($mainLayout);
 }
 /**
  * Export single atto in CSV format
  *
  * @return \Zend\Http\Response|\Zend\Stdlib\ResponseInterface
  */
 public function csvAction()
 {
     $id = $this->params()->fromRoute('id');
     $em = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
     $helper = new StatoCivileControllerHelper();
     $records = $helper->recoverWrapperRecordsById(new StatoCivileGetterWrapper(new StatoCivileGetter($em)), array('id' => $id, 'limit' => 1), $id);
     if (!empty($records)) {
         $arrayContent = array();
         $arrayContent[] = array('Titolo', 'Numero \\ Anno', 'Inserito il', 'Scadenza');
         foreach ($records as $record) {
             $arrayContent[] = array($record['titolo'], $record['progressivo'] . ' / ' . $record['anno'], $record['data']->format("d-m-Y"), $record['scadenza']->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();
     $em = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
     $id = $this->params()->fromRoute('id');
     $lang = $this->params()->fromRoute('lang');
     $helper = new StatoCivileControllerHelper();
     $records = $helper->recoverWrapperRecordsById(new StatoCivileSezioniGetterWrapper(new StatoCivileSezioniGetter($em)), array('id' => $id, 'limit' => 1), $id);
     $form = new StatoCivileSezioniForm();
     if (!empty($records)) {
         $form->setData($records[0]);
         $formAction = $this->url()->fromRoute('admin/stato-civile-sezioni-update', array('lang' => $lang));
         $formTitle = 'Modifica sezione';
         $formBreadCrumbTitle = 'Modifica';
     } else {
         $formAction = $this->url()->fromRoute('admin/stato-civile-sezioni-insert', array('lang' => $lang));
         $formTitle = 'Nuova';
         $formBreadCrumbTitle = 'Nuova sezione';
     }
     $this->layout()->setVariables(array('form' => $form, 'formAction' => $formAction, 'formTitle' => $formTitle, 'formDescription' => 'Compila il form e premi il pulsante per confermare', 'formBreadCrumbCategory' => array(array('label' => 'Stato civile', 'href' => $this->url()->fromRoute('admin/stato-civile-summary', array('lang' => $lang)), 'title' => "Elenco atti stato civile"), array('label' => 'Sezioni', 'href' => $this->url()->fromRoute('admin/stato-civile-sezioni-summary', array('lang' => $lang)), 'title' => "Elenco sezioni stato civile")), 'formBreadCrumbTitle' => $formBreadCrumbTitle, 'templatePartial' => self::formTemplate));
     $this->layout()->setTemplate($mainLayout);
 }