]> git.immae.eu Git - github/wallabag/wallabag.git/blob - src/Wallabag/CommentBundle/Repository/CommentRepository.php
Comment work with annotator v2
[github/wallabag/wallabag.git] / src / Wallabag / CommentBundle / Repository / CommentRepository.php
1 <?php
2
3 namespace Wallabag\CommentBundle\Repository;
4
5 use Doctrine\ORM\EntityRepository;
6
7 /**
8 * CommentRepository.
9 *
10 * This class was generated by the Doctrine ORM. Add your own custom
11 * repository methods below.
12 */
13 class CommentRepository extends EntityRepository
14 {
15 /**
16 * Return a query builder to used by other getBuilderFor* method.
17 *
18 * @param int $userId
19 *
20 * @return QueryBuilder
21 */
22 private function getBuilderByUser($userId)
23 {
24 return $this->createQueryBuilder('c')
25 ->leftJoin('c.user', 'u')
26 ->andWhere('u.id = :userId')->setParameter('userId', $userId)
27 ->orderBy('c.id', 'desc')
28 ;
29 }
30
31 /**
32 * Retrieves all comments for a user.
33 *
34 * @param int $userId
35 *
36 * @return QueryBuilder
37 */
38 public function getBuilderForAllByUser($userId)
39 {
40 return $this
41 ->getBuilderByUser($userId)
42 ;
43 }
44
45 /**
46 * Get comment for this id.
47 *
48 * @param int $commentId
49 *
50 * @return array
51 */
52 public function findCommentById($commentId)
53 {
54 return $this->createQueryBuilder('c')
55 ->andWhere('c.id = :commentId')->setParameter('commentId', $commentId)
56 ->getQuery()->getSingleResult()
57 ;
58 }
59
60 /**
61 * Find comments for entry id.
62 *
63 * @param int $entryId
64 * @param int $userId
65 *
66 * @return array
67 */
68 public function findCommentsByPageId($entryId, $userId)
69 {
70 return $this->createQueryBuilder('c')
71 ->where('c.entry = :entryId')->setParameter('entryId', $entryId)
72 ->andwhere('c.user = :userId')->setParameter('userId', $userId)
73 ->getQuery()->getResult()
74 ;
75 }
76
77 /**
78 * Find last comment for a given entry id. Used only for tests.
79 *
80 * @param int $entryId
81 *
82 * @return array
83 */
84 public function findLastCommentByPageId($entryId, $userId)
85 {
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')
90 ->setMaxResults(1)
91 ->getQuery()
92 ->getOneOrNullResult();
93 }
94 }