Exemple #1
0
 /**
  * @param Forum $parent
  * @param null $limit
  * @param int $pageNumber
  * @return mixed
  */
 public function findPosts(Forum $parent = null, $limit = null, $pageNumber = 1)
 {
     if ($limit === null) {
         $limit = $this->configManager->get('newpost.max', "forum");
     }
     $childIds = array();
     if ($parent) {
         $childIds = $this->getChildIds($parent);
     }
     $qb = $this->em->getRepository('SymbbCoreForumBundle:Post')->createQueryBuilder('p');
     $qb->select("p");
     if (!empty($childIds)) {
         $qb->join('p.topic', 't');
         $qb->where("t.forum IN ( :forums )");
     }
     $qb->orderBy("p.created", "DESC");
     $query = $qb->getQuery();
     if (!empty($childIds)) {
         $query->setParameter('forums', $childIds);
     }
     $paginator = $this->paginator;
     $pagination = $paginator->paginate($query, $pageNumber, $limit);
     return $pagination;
 }
Exemple #2
0
 public function search($page = 1, $limit = 0)
 {
     if ($limit === null || $limit === 0) {
         $limit = $this->configManager->get('newpost.max', "forum");
     }
     $configUsermanager = $this->configManager->getSymbbConfig('usermanager');
     $configGroupManager = $this->configManager->getSymbbConfig('groupmanager');
     $userlcass = $configUsermanager['user_class'];
     $groupclass = $configGroupManager['group_class'];
     $sql = "SELECT\n                    p\n                FROM\n                    SymbbCoreForumBundle:Post p\n                INNER JOIN\n                    SymbbCoreForumBundle:Topic t WITH\n                    t.id = p.topic\n                LEFT JOIN\n                    SymbbCoreSystemBundle:Flag f WITH\n                        f.objectClass = 'Symbb\\Core\\ForumBundle\\Entity\\Post' AND\n                        f.objectId = p.id AND\n                        f.user = :user AND\n                        f.flag = '" . AbstractFlagHandler::FLAG_NEW . "'\n                WHERE\n                    p.author != :user AND\n                    (\n                        ( SELECT COUNT(a.id) FROM SymbbCoreSystemBundle:Access a WHERE\n                            a.objectId = t.forum AND\n                            a.object = 'Symbb\\Core\\ForumBundle\\Entity\\Forum' AND\n                            a.identity = :userclass AND\n                            a.identityId = :user AND\n                            a.access = 'VIEW'\n                        ) > 0 OR\n                        ( SELECT COUNT(a2.id) FROM SymbbCoreSystemBundle:Access a2 WHERE\n                            a2.objectId = t.forum AND\n                            a2.object = 'Symbb\\Core\\ForumBundle\\Entity\\Forum' AND\n                            a2.identity = :groupclass AND\n                            a2.identityId IN (:groups) AND\n                            a2.access = 'VIEW'\n                        ) > 0\n                    )\n                GROUP BY\n                    p.id\n                ORDER BY\n                    f.id DESC,\n                    p.created DESC ";
     $groupIds = array();
     foreach ($this->getUser()->getGroups() as $group) {
         $groupIds[] = $group->getId();
     }
     //// count
     $query = $this->em->createQuery($sql);
     $rsm = new ResultSetMappingBuilder($this->em);
     $rsm->addScalarResult('count', 'count');
     $queryCount = $query->getSQL();
     $queryCount = "SELECT COUNT(*) count FROM (" . $queryCount . ") as temp";
     $queryCount = $this->em->createNativeQuery($queryCount, $rsm);
     $queryCount->setParameter(0, $this->getUser()->getId());
     $queryCount->setParameter(1, $this->getUser()->getId());
     $queryCount->setParameter(2, $userlcass);
     $queryCount->setParameter(3, $this->getUser()->getId());
     $queryCount->setParameter(4, $groupclass);
     $queryCount->setParameter(5, $groupIds);
     $count = $queryCount->getSingleScalarResult();
     ////
     if (!$count) {
         $count = 0;
     }
     $query->setParameter('user', $this->getUser()->getId());
     $query->setParameter('userclass', $userlcass);
     $query->setParameter('groupclass', $groupclass);
     $query->setParameter('groups', $groupIds);
     $query->setHint('knp_paginator.count', $count);
     $pagination = $this->paginator->paginate($query, $page, $limit, array('distinct' => false));
     return $pagination;
 }