Exemplo n.º 1
0
 public function addAction()
 {
     //$this->getServiceLocator()->get('CacheListener')->getCacheService()->flush();
     $form = new SousrubriqueForm();
     $this->sousrubriqueDao = new Sousrubriquedao();
     $this->rubriqueDao = new RubriqueDao();
     $this->translator = $this->getServiceLocator()->get('translator');
     $form->get('submit')->setAttribute('value', $this->translator->translate('Ajouter'));
     $request = $this->getRequest();
     if ($request->isPost()) {
         $sousrubrique = new Sousrubrique();
         $form->setInputFilter(new InputFilter());
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $utils = new Utils();
             $sousrubrique = new Sousrubrique();
             $sousrubrique->setRubrique($this->rubriqueDao->getRubrique($request->getPost('rubriquesList')));
             $sousrubrique->setId($request->getPost('id'));
             $sousrubrique->setRang($utils->stripTags_replaceHtmlChar_trim($request->getPost('rang'), true, true, true));
             $sousrubrique->setLibelle($utils->stripTags_replaceHtmlChar_trim($request->getPost('libelle'), true, true, true));
             $this->sousrubriqueDao->saveSousrubrique($sousrubrique);
             //flush cache
             $this->getServiceLocator()->get('CacheDataListener')->getCacheService()->flush();
             return $this->redirect()->toRoute('Sousrubrique');
         } else {
             return array('form' => $form, 'error' => $form->getMessages());
         }
     }
     return array('form' => $form, 'error' => '');
 }
Exemplo n.º 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;
 }