/** * @param array $formDataSample * @return ContenutiTabellaForm */ protected function setupForm($formDataSample) { $form = new ContenutiTabellaForm(); $inputFilter = new ContenutiTabellaFormInputFilter(); $form->setInputFilter($inputFilter->getInputFilter()); $form->setData($formDataSample); return $form; }
public function indexAction() { $mainLayout = $this->initializeAdminArea(); $em = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default'); $id = $this->params()->fromRoute('id'); $helper = new ContenutiControllerHelper(); $contenutiRecords = $helper->recoverWrapperRecordsById(new ContenutiGetterWrapper(new ContenutiGetter($em)), array('id' => $id, 'limit' => 1, 'fields' => 'contenuti.id, contenuti.titolo, contenuti.tabella'), $id); $form = new ContenutiTabellaForm(); $formAction = $this->url()->fromRoute('admin/amministrazione-trasparente-tabella-update', array('lang' => $this->params()->fromRoute('lang'), 'languageSelection' => $this->params()->fromRoute('languageSelection'), 'modulename' => 'amministrazione-trasparente')); $formTitle = $contenutiRecords[0]['titolo']; $formDescription = "Compila i dati della tabella (dati aggiuntivi all'articolo)"; if (!empty($contenutiRecords[0])) { $form->setData($contenutiRecords[0]); } $this->layout()->setVariables(array('form' => $form, 'formAction' => $formAction, 'formTitle' => $formTitle, 'formDescription' => $formDescription, 'submitButtonValue' => 'Aggiorna', 'CKEditorField' => array('tabella'), 'formBreadCrumbCategory' => array(array('href' => $this->url()->fromRoute('admin/contenuti-summary', array('lang' => $this->params()->fromRoute('lang'), 'languageSelection' => $this->params()->fromRoute('languageSelection'), 'modulename' => 'amministrazione-trasparente')), 'label' => 'Amministrazione Trasparente', 'title' => 'Vai alla gestione amministrazione Trasparente'), array('href' => '#', 'label' => 'Articolo', 'title' => "Vai alla gestione dell'articolo")), 'formBreadCrumbTitle' => 'Gestione tabella aggiuntiv', 'templatePartial' => self::formTemplate)); $this->layout()->setTemplate($mainLayout); }
/** * @return \Zend\Http\Response */ public function indexAction() { $em = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default'); /** * @var \Doctrine\DBAL\Connection $connection */ $connection = $em->getConnection(); $request = $this->getRequest(); $post = array_merge_recursive($request->getPost()->toArray(), $request->getFiles()->toArray()); if (!($request->isXmlHttpRequest() or $request->isPost())) { return $this->redirect()->toRoute('main'); } $inputFilter = new ContenutiTabellaFormInputFilter(); $form = new ContenutiTabellaForm(); $form->setBindOnValidate(false); $form->setInputFilter($inputFilter->getInputFilter()); $form->setData($post); $this->initializeAdminArea(); $userDetails = $this->recoverUserDetails(); try { if (!$form->isValid()) { throw new NullException("The form is not valid"); } $inputFilter->exchangeArray($form->getData()); $helper = new ContenutiControllerHelper(); $helper->setConnection($connection); $helper->getConnection()->beginTransaction(); $helper->updateTabella($inputFilter); $helper->getConnection()->commit(); $logWriter = new LogWriter($connection); $logWriter->writeLog(array('user_id' => $userDetails->id, 'module_id' => ModulesContainer::amministrazione_trasparente_id, 'message' => "Aggiornata tabella articolo " . $inputFilter->titolo, 'type' => 'info', 'reference_id' => $inputFilter->id, 'backend' => 1)); $this->layout()->setVariables(array('messageType' => 'success', 'messageTitle' => 'Articolo aggiornato correttamente', 'messageText' => 'I dati sono stati processati correttamente dal sistema', 'messageShowFormLink' => 1, 'messageShowForm' => "Torna alla tabella artcolo")); $this->layout()->setTemplate($this->layout()->getVariable('templateDir') . 'message.phtml'); } catch (\Exception $e) { $logWriter = new LogWriter($connection); $logWriter->writeLog(array('user_id' => isset($userDetails->id) ? $userDetails->id : null, 'module_id' => ModulesContainer::amministrazione_trasparente_id, 'message' => "Errore aggiornamento tabella articolo amm. trasparente ", 'type' => 'error', 'description' => $e->getMessage(), 'reference_id' => $inputFilter->id, 'backend' => 1)); $this->layout()->setVariables(array('messageType' => 'danger', 'messageTitle' => 'Errore aggiornamento tabella articolo amm. trasparente', 'messageText' => 'Messaggio generato: ' . $e->getMessage(), 'form' => $form, 'formInputFilter' => $inputFilter->getInputFilter(), 'messageShowFormLink' => 1, 'messageShowForm' => "Torna alla tabella dell'articolo amm. trasparente")); $this->layout()->setTemplate($this->layout()->getVariable('templateDir') . 'message.phtml'); } }