diff options
author | Thomas Citharel <tcit@tcit.fr> | 2016-02-07 16:52:59 +0100 |
---|---|---|
committer | Jeremy Benoist <jeremy.benoist@gmail.com> | 2016-02-26 18:13:17 +0100 |
commit | f38e03dc02c96344677fd2720912605b21c90b5d (patch) | |
tree | 2028cecf5d0930e1569ddb977e245ea44bedc38a /src/Wallabag/CommentBundle/Repository | |
parent | d3f1a9dc1ac181033ec54f9149d2807199fa8f17 (diff) | |
download | wallabag-f38e03dc02c96344677fd2720912605b21c90b5d.tar.gz wallabag-f38e03dc02c96344677fd2720912605b21c90b5d.tar.zst wallabag-f38e03dc02c96344677fd2720912605b21c90b5d.zip |
Comment work with annotator v2
- add missing annotator.js file and fix typo
- edit & delete routes, started tests
- basic tests
Diffstat (limited to 'src/Wallabag/CommentBundle/Repository')
-rw-r--r-- | src/Wallabag/CommentBundle/Repository/CommentRepository.php | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/src/Wallabag/CommentBundle/Repository/CommentRepository.php b/src/Wallabag/CommentBundle/Repository/CommentRepository.php new file mode 100644 index 00000000..15acffbf --- /dev/null +++ b/src/Wallabag/CommentBundle/Repository/CommentRepository.php | |||
@@ -0,0 +1,94 @@ | |||
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 | } | ||