3 namespace Wallabag\AnnotationBundle\Repository
;
5 use Doctrine\ORM\EntityRepository
;
8 * AnnotationRepository.
10 class AnnotationRepository
extends EntityRepository
13 * Return a query builder to used by other getBuilderFor* method.
17 * @return QueryBuilder
19 private function getBuilderByUser($userId)
21 return $this->createQueryBuilder('a')
22 ->leftJoin('a.user', 'u')
23 ->andWhere('u.id = :userId')->setParameter('userId', $userId)
24 ->orderBy('a.id', 'desc')
29 * Retrieves all annotations for a user.
33 * @return QueryBuilder
35 public function getBuilderForAllByUser($userId)
38 ->getBuilderByUser($userId)
43 * Get annotation for this id.
45 * @param int $annotationId
49 public function findAnnotationById($annotationId)
51 return $this->createQueryBuilder('a')
52 ->andWhere('a.id = :annotationId')->setParameter('annotationId', $annotationId)
53 ->getQuery()->getSingleResult()
58 * Find annotations for entry id.
65 public function findAnnotationsByPageId($entryId, $userId)
67 return $this->createQueryBuilder('a')
68 ->where('a.entry = :entryId')->setParameter('entryId', $entryId)
69 ->andwhere('a.user = :userId')->setParameter('userId', $userId)
70 ->getQuery()->getResult()
75 * Find last annotation for a given entry id. Used only for tests.
81 public function findLastAnnotationByPageId($entryId, $userId)
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')
89 ->getOneOrNullResult();
93 * Used only in test case to get the right annotation associated to the right user.
95 * @param string $username
99 public function findOneByUsername($username)
101 return $this->createQueryBuilder('a')
102 ->leftJoin('a.user', 'u')
103 ->where('u.username = :username')->setParameter('username', $username)
104 ->orderBy('a.id', 'DESC')