3 namespace Wallabag\CommentBundle\Repository
;
5 use Doctrine\ORM\EntityRepository
;
10 * This class was generated by the Doctrine ORM. Add your own custom
11 * repository methods below.
13 class CommentRepository
extends EntityRepository
16 * Return a query builder to used by other getBuilderFor* method.
20 * @return QueryBuilder
22 private function getBuilderByUser($userId)
24 return $this->createQueryBuilder('c')
25 ->leftJoin('c.user', 'u')
26 ->andWhere('u.id = :userId')->setParameter('userId', $userId)
27 ->orderBy('c.id', 'desc')
32 * Retrieves all comments for a user.
36 * @return QueryBuilder
38 public function getBuilderForAllByUser($userId)
41 ->getBuilderByUser($userId)
46 * Get comment for this id.
48 * @param int $commentId
52 public function findCommentById($commentId)
54 return $this->createQueryBuilder('c')
55 ->andWhere('c.id = :commentId')->setParameter('commentId', $commentId)
56 ->getQuery()->getSingleResult()
61 * Find comments for entry id.
68 public function findCommentsByPageId($entryId, $userId)
70 return $this->createQueryBuilder('c')
71 ->where('c.entry = :entryId')->setParameter('entryId', $entryId)
72 ->andwhere('c.user = :userId')->setParameter('userId', $userId)
73 ->getQuery()->getResult()
78 * Find last comment for a given entry id. Used only for tests.
84 public function findLastCommentByPageId($entryId, $userId)
86 return $this->createQueryBuilder('c')
87 ->where('c.entry = :entryId')->setParameter('entryId', $entryId)
88 ->andwhere('c.user = :userId')->setParameter('userId', $userId)
89 ->orderBy('c.id', 'DESC')
92 ->getOneOrNullResult();