public function indexAction()
 {
     $mainLayout = $this->initializeFrontendWebsite();
     $page = $this->params()->fromRoute('page');
     $em = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
     $templateDir = $this->layout()->getVariable('templateDir');
     $basicLayout = $this->layout()->getVariable('atti_concessione_basiclayout');
     $sessionContainer = new SessionContainer();
     $sessionSearch = $sessionContainer->offsetGet(AttiConcessioneSearchController::sessionIdentifier);
     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('anno' => isset($sessionSearch['anno']) ? $sessionSearch['anno'] : null, 'codice' => isset($sessionSearch['codice']) ? $sessionSearch['codice'] : null, 'beneficiarioSearch' => isset($sessionSearch['beneficiario']) ? $sessionSearch['beneficiario'] : null, 'importo' => isset($sessionSearch['importo']) ? $sessionSearch['importo'] : null, 'settore' => isset($sessionSearch['settore']) ? $sessionSearch['settore'] : null, 'attivo' => 1, 'orderBy' => 'atti.id DESC'), $page, null);
         $settoriRecords = $helper->recoverWrapperRecords(new UsersSettoriGetterWrapper(new UsersSettoriGetter($em)), array('orderBy' => 'settore.nome'));
         $wrapperArticoli->setEntityManager($em);
         $articoliRecords = $wrapperArticoli->addAttachmentsToPaginatorRecords($wrapperArticoli->setupRecords(), array('moduleId' => ModulesContainer::atti_concessione, 'noScaduti' => 1, 'orderBy' => 'a.position'));
         $form = new AttiConcessioneFormSearch();
         $form->addAnno($helper->formatYears($yearsRecords));
         $form->addMainElements();
         $form->addUfficio($helper->formatForDropwdown($settoriRecords, 'id', 'nome'));
         $form->addSubmitSearchButton();
         if (!empty($sessionSearch)) {
             $form->setData(array('anno' => $sessionSearch['anno'], 'codice' => $sessionSearch['codice'], 'beneficiario' => $sessionSearch['beneficiario'], 'importo' => $sessionSearch['importo'], 'settore' => $sessionSearch['settore']));
         }
         $articoliPaginator = $wrapperArticoli->getPaginator();
         $this->layout()->setVariables(array('records' => $articoliRecords, 'form' => $form, 'sessionSearch' => $sessionSearch, 'paginator' => $articoliPaginator, 'paginator_total_item_count' => $articoliPaginator->getTotalItemCount(), 'templatePartial' => 'atti-concessione/atti-concessione.phtml'));
     } catch (NullException $e) {
         $this->layout()->setVariables(array('messageType' => 'secondary', 'messageText' => "Si è verificato un problema o una mancanza di dati necessari per visualizzare la pagina richiesta", 'templatePartial' => 'atti-concessione/atti-concessione.phtml'));
     }
     $this->layout()->setTemplate(isset($basicLayout) ? $templateDir . $basicLayout : $mainLayout);
 }
 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);
 }
 /**
  * Set search session
  *
  * @return \Zend\Http\Response
  */
 public function indexAction()
 {
     if ($this->getRequest()->isPost()) {
         $request = $this->getRequest();
         $post = array_merge_recursive($request->getPost()->toArray(), $request->getFiles()->toArray());
         $inputFilter = new AttiConcessioneFormSearchInputFilter();
         $formSearch = new AttiConcessioneFormSearch();
         $formSearch->addMainElements();
         // $formSearch->addAnno(array());
         // $formSearch->addUfficio(array());
         $formSearch->setInputFilter($inputFilter->getInputFilter());
         $formSearch->setData($post);
         if ($formSearch->isValid()) {
             $inputFilter->exchangeArray($formSearch->getData());
             $formSearch->setData($post);
             $sessioContainer = new SessionContainer();
             $sessioContainer->offsetSet(self::sessionIdentifier, array('anno' => $inputFilter->anno != 0 ? $inputFilter->anno : null, 'codice' => $inputFilter->codice ? $inputFilter->codice : null, 'beneficiario' => $inputFilter->beneficiario ? $inputFilter->beneficiario : null, 'importo' => $inputFilter->importo != 0 ? $inputFilter->importo : null, 'settore' => $inputFilter->settore ? $inputFilter->settore : null));
             $referer = $this->getRequest()->getHeader('Referer');
             if (is_object($referer)) {
                 return $this->redirect()->toUrl($referer->getUri());
             }
         }
         $mainLayout = $this->initializeFrontendWebsite();
         $referer = $this->getRequest()->getHeader('Referer');
         $moduleUrl = $this->url()->fromRoute('atti-concessione');
         $refererUrl = is_object($referer) ? $referer->getUri() : $moduleUrl;
         $this->layout()->setVariables(array('formMessages' => $formSearch->getMessages(), 'refererUrl' => $refererUrl, 'moduleUrl' => $moduleUrl, 'moduleLabel' => "Atti di concessione", 'templatePartial' => 'form-message.phtml'));
         $this->layout()->setTemplate($mainLayout);
     } else {
         $referer = $this->getRequest()->getHeader('Referer');
         if (is_object($referer)) {
             return $this->redirect()->toUrl($referer->getUri());
         }
         return $this->redirect()->toRoute('main');
     }
 }