diff options
author | Nicolas LÅ“uillet <nicolas@loeuillet.org> | 2016-02-26 13:59:08 +0100 |
---|---|---|
committer | Jeremy Benoist <jeremy.benoist@gmail.com> | 2016-02-26 18:14:42 +0100 |
commit | 4dc872238a61f33c886c423c5812cc578b3b1cdc (patch) | |
tree | 4a9413cca2b24e9290057159eeb3833c20aefddb /src/Wallabag/AnnotationBundle/Repository | |
parent | 9eab365e28de969036e58245a57a8a6418541b3c (diff) | |
download | wallabag-4dc872238a61f33c886c423c5812cc578b3b1cdc.tar.gz wallabag-4dc872238a61f33c886c423c5812cc578b3b1cdc.tar.zst wallabag-4dc872238a61f33c886c423c5812cc578b3b1cdc.zip |
Rename CommentBundle with AnnotationBundle
Diffstat (limited to 'src/Wallabag/AnnotationBundle/Repository')
-rw-r--r-- | src/Wallabag/AnnotationBundle/Repository/AnnotationRepository.php | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/src/Wallabag/AnnotationBundle/Repository/AnnotationRepository.php b/src/Wallabag/AnnotationBundle/Repository/AnnotationRepository.php new file mode 100644 index 00000000..c1c6e638 --- /dev/null +++ b/src/Wallabag/AnnotationBundle/Repository/AnnotationRepository.php | |||
@@ -0,0 +1,91 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Wallabag\AnnotationBundle\Repository; | ||
4 | |||
5 | use Doctrine\ORM\EntityRepository; | ||
6 | |||
7 | /** | ||
8 | * AnnotationRepository. | ||
9 | */ | ||
10 | class AnnotationRepository extends EntityRepository | ||
11 | { | ||
12 | /** | ||
13 | * Return a query builder to used by other getBuilderFor* method. | ||
14 | * | ||
15 | * @param int $userId | ||
16 | * | ||
17 | * @return QueryBuilder | ||
18 | */ | ||
19 | private function getBuilderByUser($userId) | ||
20 | { | ||
21 | return $this->createQueryBuilder('a') | ||
22 | ->leftJoin('a.user', 'u') | ||
23 | ->andWhere('u.id = :userId')->setParameter('userId', $userId) | ||
24 | ->orderBy('a.id', 'desc') | ||
25 | ; | ||
26 | } | ||
27 | |||
28 | /** | ||
29 | * Retrieves all annotations for a user. | ||
30 | * | ||
31 | * @param int $userId | ||
32 | * | ||
33 | * @return QueryBuilder | ||
34 | */ | ||
35 | public function getBuilderForAllByUser($userId) | ||
36 | { | ||
37 | return $this | ||
38 | ->getBuilderByUser($userId) | ||
39 | ; | ||
40 | } | ||
41 | |||
42 | /** | ||
43 | * Get annotation for this id. | ||
44 | * | ||
45 | * @param int $annotationId | ||
46 | * | ||
47 | * @return array | ||
48 | */ | ||
49 | public function findAnnotationById($annotationId) | ||
50 | { | ||
51 | return $this->createQueryBuilder('a') | ||
52 | ->andWhere('a.id = :annotationId')->setParameter('annotationId', $annotationId) | ||
53 | ->getQuery()->getSingleResult() | ||
54 | ; | ||
55 | } | ||
56 | |||
57 | /** | ||
58 | * Find annotations for entry id. | ||
59 | * | ||
60 | * @param int $entryId | ||
61 | * @param int $userId | ||
62 | * | ||
63 | * @return array | ||
64 | */ | ||
65 | public function findAnnotationsByPageId($entryId, $userId) | ||
66 | { | ||
67 | return $this->createQueryBuilder('a') | ||
68 | ->where('a.entry = :entryId')->setParameter('entryId', $entryId) | ||
69 | ->andwhere('a.user = :userId')->setParameter('userId', $userId) | ||
70 | ->getQuery()->getResult() | ||
71 | ; | ||
72 | } | ||
73 | |||
74 | /** | ||
75 | * Find last annotation for a given entry id. Used only for tests. | ||
76 | * | ||
77 | * @param int $entryId | ||
78 | * | ||
79 | * @return array | ||
80 | */ | ||
81 | public function findLastAnnotationByPageId($entryId, $userId) | ||
82 | { | ||
83 | return $this->createQueryBuilder('a') | ||
84 | ->where('a.entry = :entryId')->setParameter('entryId', $entryId) | ||
85 | ->andwhere('a.user = :userId')->setParameter('userId', $userId) | ||
86 | ->orderBy('a.id', 'DESC') | ||
87 | ->setMaxResults(1) | ||
88 | ->getQuery() | ||
89 | ->getOneOrNullResult(); | ||
90 | } | ||
91 | } | ||