Example #1
0
 public function getChildrenDirectByCategorie(Categorie $categorie = null)
 {
     $query = $this->createQueryBuilder('c');
     if ($categorie != null) {
         $query->where('c.lvl = ' . ($categorie->getLvl() + 1))->andWhere('c.rgt < ' . $categorie->getRgt())->andWhere('c.lft > ' . $categorie->getLft())->andWhere('c.root = ' . $categorie->getRoot());
     } else {
         $query->where('c.lvl = 0');
     }
     $query->orderBy('c.lft')->leftJoin('c.children', 'children')->addSelect('children')->leftJoin('children.lastPost', 'p')->addSelect('p');
     return $query->getQuery()->getResult();
 }
Example #2
0
 public function getThreadAction($pole, Categorie $categorie, $slug, Post $post, Thread $thread, $nonVu = null, $moderer = false, User $user = null, $perm = null, $page = 1, $answer = 0)
 {
     if ($perm == null) {
         $permService = $this->container->get('ter_aelis_forum.permission');
         $perm = $permService->getPerm($user);
     }
     $voirCategorie = $perm['voirCategorie'][$categorie->getId()];
     $voirSujet = $perm['voirSujet'][$categorie->getId()];
     $repondreSujet = $perm['repondreSujet'][$categorie->getId()];
     if ($voirCategorie == 0 || $voirSujet == 0) {
         throw new AccessDeniedException("Interdiction de voir ce sujet (idCategorie = " . $categorie->getId() . ")");
     }
     list($pole_aff, $pole) = $this->getPoleAffichage($pole, $categorie->getRoot());
     $nbCommentPerPage = $this->container->getParameter('comment.nb_comment');
     $returnArray = array('user' => $user, 'answer' => $answer, 'slug' => $slug, 'thread' => $thread, 'repondreSujet' => $repondreSujet, 'pole' => $pole, 'pole_aff' => $pole_aff, 'nbCommentPerPage' => $nbCommentPerPage, 'moderer' => $moderer, 'sujet' => $post, 'page' => $page, 'nonVu' => $nonVu);
     $em = $this->getDoctrine()->getManager();
     $comments = null;
     if ($thread->getNumberComment() > 0) {
         $editerMessage = $perm['editerMessage'][$categorie->getId()];
         $supprimerMessage = $perm['supprimerMessage'][$categorie->getId()];
         $moderer = $perm['moderer'][$categorie->getId()];
         $repositoryComments = $em->getRepository('TerAelisCommentBundle:Comment');
         $comments = $repositoryComments->findByThread($thread, $nbCommentPerPage, $page, $answer);
         // Variables transmises au twig
         $returnArray['comments'] = $comments;
         $returnArray['editerMessage'] = $editerMessage;
         $returnArray['supprimerMessage'] = $supprimerMessage;
         $returnArray['postLastComment'] = $post->getLastComment();
         $returnArray['moderer'] = $moderer;
     }
     // Update des non lus
     if ($user != null) {
         $lastCommentShown = null;
         if ($comments != null) {
             foreach ($comments as $c) {
                 $lastCommentShown = $c;
             }
         }
         $nonVuService = $this->container->get('ter_aelis_forum.non_vu');
         $nonVuService->deleteNonVu($user, $post, $lastCommentShown);
     }
     return $this->render('TerAelisCommentBundle:Thread:view.html.twig', $returnArray);
 }
Example #3
0
 public function getLastPost(Categorie $c)
 {
     $lastDates = $this->createQueryBuilder('p')->join('p.mainCategorie', 'c')->addSelect('c')->addSelect('MAX(p.lastComment) as max_lastComment')->where('c.lft <= ' . $c->getLft() . ' and c.rgt >= ' . $c->getRgt() . ' and c.root = ' . $c->getRoot())->andWhere('p.publie = 1')->andWhere('p.datePublication < :today')->groupBy('p.mainCategorie')->setParameter('today', new \DateTime())->getQuery()->getArrayResult();
     $where = "";
     $i = 0;
     $parameters = array();
     foreach ($lastDates as $p) {
         $i++;
         $where .= " or p.lastComment = :p" . $i;
         $parameters['p' . $i] = $p['max_lastComment'];
     }
     if (strlen($where) <= 0) {
         return array();
     } else {
         $where = substr($where, 4);
         $query = $this->createQueryBuilder('p')->join('p.mainCategorie', 'c')->addSelect('c')->where($where)->getQuery();
         return $query->setParameters($parameters)->getResult();
     }
 }