public function indexAction() { $mainLayout = $this->initializeAdminArea(); $em = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default'); $lang = $this->params()->fromRoute('lang'); $id = $this->params()->fromRoute('id'); try { $helper = new ContrattiPubbliciControllerHelper(); $sceltaContraenteRecords = $helper->recoverWrapperRecords(new SceltaContraenteGetterWrapper(new SceltaContraenteGetter($em)), array('orderBy' => '')); $helper->checkRecords($sceltaContraenteRecords, "Nessuna opzione di scelta contraente rilevata"); $sceltaContraenteRecordsForDropDown = $helper->formatForDropwdown($sceltaContraenteRecords, 'id', 'nomeScelta'); $responsabiliProcRecords = $helper->recoverWrapperRecords(new UsersRespProcGetterWrapper(new UsersRespProcGetter($em)), array('orderBy' => '')); $helper->checkRecords($responsabiliProcRecords, "Nessuna responsabile di procedimento rilevato"); $responsabiliProcRecordsForDropDown = $helper->formatUsersRespProcRecords($responsabiliProcRecords); $contrattoRecord = $helper->recoverWrapperRecordsById(new ContrattiPubbliciGetterWrapper(new ContrattiPubbliciGetter($em)), array('id' => $id, 'limit' => 1), $id); $usersSettoriRecords = $helper->recoverWrapperRecords(new UsersSettoriGetterWrapper(new UsersSettoriGetter($em)), array()); $helper->checkRecords($usersSettoriRecords, 'Nessun settore presente'); $usersSettoriRecordsForDropDown = $helper->formatForDropwdown($usersSettoriRecords, 'id', 'nome'); $form = new ContrattiPubbliciForm(); $form->addDetermina(); $form->addImporti(); $form->addStrutturaProponenteLabel(); $form->addResponsabili($responsabiliProcRecordsForDropDown); $form->addSceltaContraente($sceltaContraenteRecordsForDropDown); $form->addSettori($usersSettoriRecordsForDropDown); $form->addDatePubblicazione(); $form->addNumeroOfferte(); $form->addDataInizioFineLavori(); // $form->addUsersSelect(); // TODO: add user selection if (!empty($contrattoRecord)) { $formAction = $this->url()->fromRoute('admin/contratti-pubblici-update', array('lang' => $lang)); $formTitle = 'Modifica bando'; $formDescription = 'È consigliabile inserire testi brevi sul tema trattato, possibilmente in minuscolo.'; $form->setData($contrattoRecord[0]); } else { $form->setData(array("dataInserimento" => date("Y-m-d H:i:s"))); $formAction = $this->url()->fromRoute('admin/contratti-pubblici-insert', array('lang' => $lang)); $formTitle = 'Nuovo bando'; $formDescription = "Il bando verrà inserito come <strong>disattivato</strong>. Occorrerà attivare lo stesso dall'elenco."; } $this->layout()->setVariables(array('form' => $form, 'formAction' => $formAction, 'formTitle' => $formTitle, 'formDescription' => $formDescription, 'formBreadCrumbCategory' => 'Contratti pubblici', 'formBreadCrumbCategoryLink' => $this->url()->fromRoute('admin/contratti-pubblici-summary', array('lang' => $lang)), 'formLabelSpanWidth' => 3, 'formControlSpanWidth' => 9, 'templatePartial' => self::formTemplate)); } catch (NullException $e) { $this->layout()->setVariables(array('templatePartial' => 'message.phtml', 'messageType' => 'warning', 'messageTitle' => 'Errore verificato', 'messageText' => $e->getMessage())); } $this->layout()->setTemplate($mainLayout); }