Exemplo n.º 1
0
 public function __construct($name = null)
 {
     // we want to ignore the name passed
     parent::__construct('galerieform');
     //$this->setHydrator(new ClassMethods);
     $this->add(array('name' => 'imagepath', 'attributes' => array('type' => 'text'), 'options' => array('label' => $this->utils->translate('Image'))));
     $this->add(array('name' => 'imagepath2', 'attributes' => array('type' => 'text'), 'options' => array('label' => $this->utils->translate('Image 2'))));
 }
Exemplo n.º 2
0
 public function editAction()
 {
     $form = new ContenuForm();
     $this->contenuDao = new ContenuDao();
     $this->rubriqueDao = new RubriqueDao();
     $this->sousrubriqueDao = new Sousrubriquedao();
     $this->fichiersdao = new Fichiersdao();
     $allFichiers = array();
     //get cache
     $cache = $this->getServiceLocator()->get('CacheDataListener');
     $result = $cache->getCacheDataItem(CacheKeys::$CacheKeyFichiersAll);
     //if there's no cache for files
     if (!$result) {
         $allFichiers = $this->fichiersdao->getAllFichiers("object");
     } else {
         $allFichiers = $result['fichiers'];
         $cache->setCacheDataItem(CacheKeys::$CacheKeyFichiersAll, array('fichiers' => $allFichiers));
     }
     $id = (int) $this->params()->fromRoute('id', 0);
     //print_r($id);
     if (!$id) {
         return $this->redirect()->toRoute('Contenu', array('action' => 'add'));
     }
     $contenu = $this->contenuDao->getContenu($id);
     $contenuId = $contenu->getId();
     if (!empty($id)) {
         if (empty($contenuId)) {
             //return $this->getResponse()->setStatusCode(404);
             return $this->notFoundAction();
         }
     }
     $rubrique = $this->rubriqueDao->getAllRubriques("array");
     $form = new ContenuForm();
     $form->get('id')->setAttribute('value', $contenu->getId());
     $form->get('titre')->setAttribute('value', $contenu->getTitre());
     $form->get('soustitre')->setAttribute('value', $contenu->getSousTitre());
     $form->get('position')->setAttribute('value', $contenu->getRang());
     $form->get('contenu')->setAttribute('value', $contenu->getContenuHtml());
     //$form->get('rubriques_id')->setAttribute('value', $contenu->getSousRubrique()->getRubrique()->getId());
     //$form->get('sousrubriques_id')->setAttribute('value', $contenu->getSousRubrique()->getId());
     $this->translator = $this->getServiceLocator()->get('translator');
     $form->get('submitbutton')->setAttribute('value', $this->translator->translate('Ajouter'));
     $request = $this->getRequest();
     if ($request->isPost()) {
         $contenu = new Contenu();
         //trigger data controls
         $form->setInputFilter(new ContenuInputFilter());
         $form->setData($request->getPost());
         $form->setUseInputFilterDefaults(false);
         if ($form->isValid()) {
             $filterData = new Utils();
             $contenu->setSousRubrique($this->sousrubriqueDao->getSousrubrique($filterData->stripTags_replaceHtmlChar_trim($request->getPost('sousrubriquesList'), true, false, true)));
             $contenu->setId($filterData->stripTags_replaceHtmlChar_trim($request->getPost('id'), true, false, true));
             $contenu->setTitre($filterData->stripTags_replaceHtmlChar_trim($request->getPost('titre'), false, false, true));
             $contenu->setRang($filterData->stripTags_replaceHtmlChar_trim($request->getPost('position'), true, false, true));
             $contenu->setSousTitre($filterData->stripTags_replaceHtmlChar_trim($request->getPost('soustitre'), false, false, true));
             $contenu->setContenuHtml($request->getPost('contenu'));
             $this->contenuDao->saveContenu($contenu);
             //flush cache
             $this->getServiceLocator()->get('CacheDataListener')->getCacheService()->flush();
             return $this->redirect()->toRoute('Contenu');
         } else {
             return array('id' => $id, 'form' => $form, 'rubrique_id' => $contenu->getSousRubrique()->getRubrique()->getId(), 'sousrubrique_id' => $contenu->getSousRubrique()->getId(), 'fichiers' => $allFichiers, 'error' => $form->getMessages());
         }
     }
     return array('id' => $id, 'form' => $form, 'rubrique_id' => $contenu->getSousRubrique()->getRubrique()->getId(), 'sousrubrique_id' => $contenu->getSousRubrique()->getId(), 'fichiers' => $allFichiers, 'error' => "no error");
 }