/**
  * @param $formDataSample
  * @return ContenutiForm
  */
 protected function setupForm($formDataSample)
 {
     $form = new ContenutiForm();
     $form->addSottoSezioni(array(1 => 'Sottosezione 1', 2 => 'Sottosezione 2'));
     $form->addMainFormElements();
     $form->addUsers(array(1 => 'John Doe', 2 => 'Jack Black'));
     $form->addHomeBox();
     $form->addSocial();
     $inputFilter = new ContenutiFormInputFilter();
     $form->setInputFilter($inputFilter->getInputFilter());
     $form->setData($formDataSample);
     return $form;
 }
Exemplo n.º 2
0
 public function indexAction()
 {
     $mainLayout = $this->initializeAdminArea();
     $id = $this->params()->fromRoute('id');
     $em = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
     $userDetails = $this->layout()->getVariable('userDetails');
     $languageSelection = $this->params()->fromRoute('languageSelection');
     $modulename = $this->params()->fromRoute('modulename');
     try {
         $helper = new ContenutiControllerHelper();
         $sottoSezioniRecords = $helper->recoverWrapperRecords(new SottoSezioniGetterWrapper(new SottoSezioniGetter($em)), array('showToAll' => $userDetails->role == 'WebMaster' ? null : 1, 'languageAbbreviation' => $languageSelection, 'isAmmTrasparente' => $modulename != 'contenuti' ? 1 : 0));
         $helper->checkRecords($sottoSezioniRecords, 'Nessuna sottosezione presente');
         $sottoSezioniRecordsForDropDown = $helper->formatSottoSezioniGetterWrapperRecordsForDropdown($sottoSezioniRecords);
         $contenutiRecords = $helper->recoverWrapperRecordsById(new ContenutiGetterWrapper(new ContenutiGetter($em)), array('id' => $id, 'isAmmTrasparente' => $modulename != 'contenuti' ? 1 : 0, 'utente' => $userDetails->role == 'WebMaster' ? null : $userDetails->id, 'limit' => 1), $id);
         $form = new ContenutiForm();
         $form->addSottoSezioni($sottoSezioniRecordsForDropDown);
         $form->addMainFormElements();
         if ($userDetails->role == 'WebMaster') {
             $usersRecords = $helper->recoverWrapperRecords(new UsersGetterWrapper(new UsersGetter($em)), array('orderBy' => 'u.name'));
             $arrayToReturn = array();
             if (!empty($usersRecords)) {
                 foreach ($usersRecords as $record) {
                     $arrayToReturn[$record['id']] = $record['name'] . ' ' . $record['surname'];
                 }
             }
             $form->addUsers($arrayToReturn);
         }
         $form->addHomeBox();
         if (!empty($contenutiRecords)) {
             $form->setData($contenutiRecords[0]);
             $submitButtonValue = 'Modifica';
             $formTitle = 'Modifica articolo';
             $formDescription = "Modifica i dati relativi all'articolo. Massimo 255 caratteri per i campi testo. Utilizzare testi brevi e concisi. Evitare copia \\ incolla da file word o pagine web che potrebbero pregiudicare l’accessibilità del sito web.";
             $formAction = $this->url()->fromRoute('admin/contenuti-update', array('lang' => $this->params()->fromRoute('lang'), 'languageSelection' => $languageSelection, 'modulename' => $modulename));
             $formBreadCrumbTitle = '';
         } else {
             $form->setData(array('dataInserimento' => date('Y-m-d H:i:s'), 'dataScadenza' => date('Y-m-d H:i:s', strtotime('+5 years')), 'attivo' => 1, 'utente' => $userDetails->id));
             $form->addSocial();
             $formTitle = 'Nuovo articolo';
             $formDescription = "Inserisci i dati relativi all'articolo. Massimo 255 caratteri per i campi testo. Utilizzare testi brevi e concisi. Evitare copia \\ incolla da file word o pagine web che potrebbero pregiudicare l’accessibilità del sito web.";
             $submitButtonValue = 'Inserisci';
             $formAction = $this->url()->fromRoute('admin/contenuti-insert', array('lang' => $this->params()->fromRoute('lang'), 'languageSelection' => $languageSelection, 'modulename' => $modulename));
             $formBreadCrumbTitle = 'Nuovo artciolo';
         }
         $this->layout()->setVariables(array('form' => $form, 'formAction' => $formAction, 'formTitle' => $formTitle, 'formDescription' => $formDescription, 'submitButtonValue' => $submitButtonValue, 'CKEditorField' => array('testo'), 'formBreadCrumbCategory' => ucfirst(str_replace('-', ' ', $modulename)), 'formBreadCrumbCategoryLink' => $this->url()->fromRoute('admin/contenuti-summary', array('lang' => $this->params()->fromRoute('lang'), 'page' => $this->params()->fromRoute('previouspage'), 'languageSelection' => $languageSelection, 'modulename' => $modulename)), 'formBreadCrumbTitle' => $formBreadCrumbTitle, 'templatePartial' => self::formTemplate));
     } catch (\Exception $e) {
         $this->layout()->setVariables(array('messageType' => 'warning', 'messageTitle' => 'Errore verificato', 'messageText' => 'Messaggio generato ' . $e->getMessage(), 'templatePartial' => 'message.phtml'));
     }
     $this->layout()->setTemplate($mainLayout);
 }
 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');
     }
     $modulename = $this->params()->fromRoute('modulename');
     /* $modulenameLabel = str_replace("-", " ", $modulename); */
     $inputFilter = new ContenutiFormInputFilter();
     $form = new ContenutiForm();
     $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->setLoggedUser($userDetails);
         $helper->getConnection()->beginTransaction();
         $lastInsertId = $helper->insert($inputFilter);
         // TODO: insert in home, update home field if home is selected
         $helper->setLogWriter(new LogWriter($connection));
         $helper->writeLog(array('user_id' => $userDetails->id, 'module_id' => ModulesContainer::contenuti_id, 'message' => "Inserito nuovo contenuto \\ articolo " . $inputFilter->titolo, 'type' => 'info', 'reference_id' => $lastInsertId, 'backend' => 1));
         $this->layout()->setVariables(array('messageType' => 'success', 'messageTitle' => 'Articolo inserito correttamente', 'messageText' => 'I dati sono stati processati correttamente dal sistema', 'showLinkResetFormAndShowIt' => 1, 'backToSummaryLink' => $this->url()->fromRoute('admin/contenuti-summary', array('lang' => $this->params()->fromRoute('lang'), 'languageSelection' => $this->params()->fromRoute('languageSelection'), 'modulename' => $modulename)), 'backToSummaryText' => "Elenco contenuti", 'insertAgainLabel' => "Inserisci un altro articolo \\ contenuto", 'attachmentsLink' => $this->url()->fromRoute('admin/attachments-summary', array('lang' => $this->params()->fromRoute('languageSelection'), 'module' => 'contenuti', 'referenceId' => $lastInsertId))));
         $helper->getConnection()->commit();
         $this->layout()->setTemplate($this->layout()->getVariable('templateDir') . 'message.phtml');
     } catch (\Exception $e) {
         $logWriter = new LogWriter($connection);
         $logWriter->writeLog(array('user_id' => $userDetails->id, 'module_id' => ModulesContainer::contenuti_id, 'message' => "Errore inserimento nuovo contenuto \\ articolo: " . $inputFilter->titolo, 'description' => $e->getMessage() . "; Titolo: " . $inputFilter->titolo . " Testo: " . $inputFilter->testo . ' Sottosezione: ' . $inputFilter->sottosezione, 'type' => 'error', 'backend' => 1));
         $this->layout()->setVariables(array('messageType' => 'danger', 'messageTitle' => 'Errore inserimento contenuto \\ articolo', 'messageText' => $e->getMessage(), 'form' => $form, 'formInputFilter' => $inputFilter->getInputFilter(), 'messageShowFormLink' => 1, 'messageShowForm' => 'Torna al form di inserimento dati'));
         $this->layout()->setTemplate($this->layout()->getVariable('templateDir') . 'message.phtml');
     }
 }
 /**
  * Update contenuti and render a message view
  *
  * @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 ContenutiFormInputFilter();
     $form = new ContenutiForm();
     $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->update($inputFilter);
         $helper->getConnection()->commit();
         // TODO: insert or delete in home, update home field
         $helper->setLogWriter(new LogWriter($connection));
         $helper->writeLog(array('user_id' => $userDetails->id, 'module_id' => ModulesContainer::contenuti_id, 'message' => "Aggiornato il contenuto " . $inputFilter->titolo, 'type' => 'info', 'reference_id' => $inputFilter->id, 'backend' => 1));
         $this->layout()->setVariables(array('messageType' => 'success', 'messageTitle' => 'Contenuto aggiornato correttamente', 'messageText' => 'I dati sono stati processati correttamente dal sistema', 'messageShowFormLink' => 1, 'messageShowForm' => 'Torna al contenuto', 'backToSummaryLink' => $this->url()->fromRoute('admin/contenuti-summary', array('lang' => $this->params()->fromRoute('lang'), 'languageSelection' => $this->params()->fromRoute('languageSelection'), 'modulename' => $this->params()->fromRoute('modulename'))), 'backToSummaryText' => "Elenco contenuti", 'attachmentsLink' => $this->url()->fromRoute('admin/attachments-summary', array('lang' => $this->params()->fromRoute('lang'), 'module' => 'contenuti', 'referenceId' => $inputFilter->id))));
         $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::contenuti_id, 'message' => "Errore aggiornamento contenuto ID: " . $inputFilter->id, 'type' => 'error', 'description' => $e->getMessage(), 'reference_id' => $inputFilter->id, 'backend' => 1));
         $this->layout()->setVariables(array('messageType' => 'danger', 'messageTitle' => 'Errore aggiornamento contenuto', 'messageText' => 'Messaggio generato: ' . $e->getMessage(), 'form' => $form, 'formInputFilter' => $inputFilter->getInputFilter(), 'messageShowFormLink' => 1, 'messageShowForm' => 'Torna al contenuto'));
         $this->layout()->setTemplate($this->layout()->getVariable('templateDir') . 'message.phtml');
     }
 }