3 namespace Wallabag\AnnotationBundle\Repository
;
5 use Doctrine\ORM\EntityRepository
;
8 * AnnotationRepository.
10 class AnnotationRepository
extends EntityRepository
13 * Retrieves all annotations for a user.
17 * @return QueryBuilder
19 public function getBuilderForAllByUser($userId)
22 ->getBuilderByUser($userId)
27 * Get annotation for this id.
29 * @param int $annotationId
33 public function findAnnotationById($annotationId)
35 return $this->createQueryBuilder('a')
36 ->andWhere('a.id = :annotationId')->setParameter('annotationId', $annotationId)
43 * Find annotations for entry id.
50 public function findAnnotationsByPageId($entryId, $userId)
52 return $this->createQueryBuilder('a')
53 ->where('a.entry = :entryId')->setParameter('entryId', $entryId)
54 ->andwhere('a.user = :userId')->setParameter('userId', $userId)
61 * Find last annotation for a given entry id. Used only for tests.
67 public function findLastAnnotationByPageId($entryId, $userId)
69 return $this->createQueryBuilder('a')
70 ->where('a.entry = :entryId')->setParameter('entryId', $entryId)
71 ->andwhere('a.user = :userId')->setParameter('userId', $userId)
72 ->orderBy('a.id', 'DESC')
75 ->getOneOrNullResult();
79 * Used only in test case to get the right annotation associated to the right user.
81 * @param string $username
85 public function findOneByUsername($username)
87 return $this->createQueryBuilder('a')
88 ->leftJoin('a.user', 'u')
89 ->where('u.username = :username')->setParameter('username', $username)
90 ->orderBy('a.id', 'DESC')
97 * Remove all annotations for a user id.
98 * Used when a user want to reset all informations.
102 public function removeAllByUserId($userId)
104 $this->getEntityManager()
105 ->createQuery('DELETE FROM Wallabag\AnnotationBundle\Entity\Annotation a WHERE a.user = :userId')
106 ->setParameter('userId', $userId)
111 * Find all annotations related to archived entries.
117 public function findAllArchivedEntriesByUser($userId)
119 return $this->createQueryBuilder('a')
120 ->leftJoin('a.entry', 'e')
121 ->where('a.user = :userid')->setParameter(':userid', $userId)
122 ->andWhere('e.isArchived = true')
128 * Return a query builder to used by other getBuilderFor* method.
132 * @return QueryBuilder
134 private function getBuilderByUser($userId)
136 return $this->createQueryBuilder('a')
137 ->leftJoin('a.user', 'u')
138 ->andWhere('u.id = :userId')->setParameter('userId', $userId)
139 ->orderBy('a.id', 'desc')