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)
59 * Find annotations for entry id.
66 public function findAnnotationsByPageId($entryId, $userId)
68 return $this->createQueryBuilder('a')
69 ->where('a.entry = :entryId')->setParameter('entryId', $entryId)
70 ->andwhere('a.user = :userId')->setParameter('userId', $userId)
77 * Find last annotation for a given entry id. Used only for tests.
83 public function findLastAnnotationByPageId($entryId, $userId)
85 return $this->createQueryBuilder('a')
86 ->where('a.entry = :entryId')->setParameter('entryId', $entryId)
87 ->andwhere('a.user = :userId')->setParameter('userId', $userId)
88 ->orderBy('a.id', 'DESC')
91 ->getOneOrNullResult();
95 * Used only in test case to get the right annotation associated to the right user.
97 * @param string $username
101 public function findOneByUsername($username)
103 return $this->createQueryBuilder('a')
104 ->leftJoin('a.user', 'u')
105 ->where('u.username = :username')->setParameter('username', $username)
106 ->orderBy('a.id', 'DESC')
113 * Remove all annotations for a user id.
114 * Used when a user want to reset all informations.
118 public function removeAllByUserId($userId)
120 $this->getEntityManager()
121 ->createQuery('DELETE FROM Wallabag\AnnotationBundle\Entity\Annotation a WHERE a.user = :userId')
122 ->setParameter('userId', $userId)