예제 #1
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");
 }
예제 #2
0
 public function getPage($rubriqueId, $order, $dataType)
 {
     $this->rubriqueDao = new RubriqueDao();
     $this->sousRubriqueDao = new Sousrubriquedao();
     $this->contenuDao = new ContenuDao();
     $this->linktocontenuDao = new LinktocontenuDao();
     $sortContentList = new Contenu();
     $sortSectionList = new Sousrubrique();
     if (strcmp($dataType, "object") == 0 || strcmp($dataType, "json") == 0) {
         //Pagearrangement object
         $pagearrangement = null;
         //Page (Rubrique)
         $page = $this->rubriqueDao->getRubrique($rubriqueId);
         //List of sections (SousRubrique)
         $sectionsList = $this->sousRubriqueDao->getSousrubriquesByRubrique($rubriqueId, "object");
         $sectionsList = $sortSectionList->sortByPosition($sectionsList, "asc");
         $contents = array();
         $contentsLinked = array();
         $sortedContents = array();
         $count = 0;
         //List of contents (Contenu)
         foreach ($sectionsList as $section) {
             //Start by contents
             $contents[$count] = $this->contenuDao->getContenusBySousrubrique($section->getId(), "object");
             $isAdded = false;
             //Continue by content linked in another section
             $linktocontenuList = $this->linktocontenuDao->getAllLinktocontenusBySousrubrique($section->getId(), "object");
             foreach ($linktocontenuList as $linktocontenu) {
                 $content = $linktocontenu;
                 /*
                 //-1 is the default value that mean, you take the content position
                 if($linktocontenu->getRang() > -1){
                     $content->setRang($linktocontenu->getContenu()->getRang());
                 }
                 */
                 array_push($contentsLinked, $content);
             }
             //push new contents from linktocontenu if they exist
             if (!empty($contentsLinked)) {
                 foreach ($contentsLinked as $link) {
                     array_push($contents[$count], $link);
                 }
                 $isAdded = true;
             }
             //contents from contenu table has been already ordered by rank asc
             if (!empty($contents[$count]) && $isAdded) {
                 $sortedContents[] = $sortContentList->sortByPosition($contents[$count], $order);
             } else {
                 //$sortedContents[] = $contents[$count];
                 $sortedContents[] = $sortContentList->sortByPosition($contents[$count], $order);
             }
             $count++;
             $isAdded = false;
             $contentsLinked = array();
         }
         //index of the array matches index of sectionsList
         $pagearrangement = new Pagearrangement($page, $sectionsList, $sortedContents);
         if (strcmp($dataType, "object") == 0) {
             return $pagearrangement->getPage();
         } elseif (strcmp($dataType, "json") == 0) {
             return $pagearrangement->to_json();
         }
     }
     return null;
 }
예제 #3
0
 protected function exchangeForm($data)
 {
     //Right now, there's no difference with exchangeArray but it could change in the future
     parent::exchangeArray($data);
     if (isset($data['author'])) {
         $this->setAuthor($data['author']);
     }
     if (isset($data['themes'])) {
         $this->setThemes($data['themes']);
     }
     if (isset($data['blogdate'])) {
         $this->setDate($data['blogdate']);
     }
     if (isset($data['text1'])) {
         $this->setText1($data['text1']);
     }
     if (isset($data['text2'])) {
         $this->setText2($data['text2']);
     }
     if (isset($data['text3'])) {
         $this->setText3($data['text3']);
     }
 }