/**
  * CSV export
  *
  * @return \Zend\Http\Response|\Zend\Stdlib\ResponseInterface
  * @throws \ModelModule\Model\NullException
  */
 public function csvAction()
 {
     if ($this->getRequest()->isPost()) {
         $request = $this->getRequest();
         $post = array_merge_recursive($request->getPost()->toArray(), $request->getFiles()->toArray());
         $form = new StatoCivileFormSearch();
         $form->setBindOnValidate(false);
         $form->setData($post);
         if ($form->isValid()) {
             $sessionContainer = new SessionContainer();
             $sessionContainer->offsetSet('statoCivileFormSearch', $post);
             $em = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
             $wrapper = new StatoCivileGetterWrapper(new StatoCivileGetter($em));
             $wrapper->setInput(array('numero' => isset($post['numero']) ? $post['numero'] : null, 'anno' => isset($post['anno']) ? $post['anno'] : null, 'sezioneId' => isset($post['sezione']) ? $post['sezione'] : null, 'noScaduti' => isset($post['expired']) ? $post['expired'] : null, 'textSearch' => isset($post['testo']) ? $post['testo'] : null, 'orderBy' => 'sca.id DESC', 'limit' => 1500));
             $wrapper->setupQueryBuilder();
             $records = $wrapper->getRecords();
             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="stato_civile_' . date("dmYHis") . '.csv"')->addHeaderLine('Accept-Ranges', 'bytes')->addHeaderLine('Content-Length', strlen($content));
                 $response->setContent($content);
                 return $response;
             }
         }
     }
     return $this->redirectForUnvalidAccess();
 }
 public function csvAction()
 {
     if ($this->getRequest()->isPost()) {
         $request = $this->getRequest();
         $post = array_merge_recursive($request->getPost()->toArray(), $request->getFiles()->toArray());
         $form = new ContenutiFormSearch();
         $form->addSubmitButton();
         $form->setBindOnValidate(false);
         $form->setData($post);
         if ($form->isValid()) {
             $sessionContainer = new SessionContainer();
             $sessionContainer->offsetSet('contenutiFormSearch', $post);
             $em = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
             $wrapper = new ContenutiGetterWrapper(new ContenutiGetter($em));
             $wrapper->setInput(array('limit' => 1500));
             $wrapper->setupQueryBuilder();
             $records = $wrapper->getRecords();
             $csvExportHelper = new CsvExportHelper();
             if (!empty($records)) {
                 $arrayContent = array();
                 $arrayContent[] = array('Titolo', 'Sottotitolo', 'Testo');
                 foreach ($records as $record) {
                     $arrayContent[] = array($record['titolo'], $record['sommario'], $record['testo']);
                 }
                 $content = $csvExportHelper->makeCsvLine($arrayContent);
                 $response = $this->getResponse();
                 $response->getHeaders()->addHeaderLine('Content-Type', 'text/csv')->addHeaderLine('Content-Disposition', 'attachment; filename="contenuti_' . date("dmYHis") . '.csv"')->addHeaderLine('Accept-Ranges', 'bytes')->addHeaderLine('Content-Length', strlen($content));
                 $response->setContent($content);
                 return $response;
             }
         }
     }
     return $this->redirectForUnvalidAccess();
 }
 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;
     }
 }