X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FWallabag%2FAnnotationBundle%2FRepository%2FAnnotationRepository.php;h=8d3f07eef350f2eb8ebf12a05b80deb5f6d026fb;hb=5a619812ca3eb05a82a023ccdaee13501eb8d45f;hp=c1c6e638984885e2e19608890cc24a64caefa865;hpb=4dc872238a61f33c886c423c5812cc578b3b1cdc;p=github%2Fwallabag%2Fwallabag.git diff --git a/src/Wallabag/AnnotationBundle/Repository/AnnotationRepository.php b/src/Wallabag/AnnotationBundle/Repository/AnnotationRepository.php index c1c6e638..8d3f07ee 100644 --- a/src/Wallabag/AnnotationBundle/Repository/AnnotationRepository.php +++ b/src/Wallabag/AnnotationBundle/Repository/AnnotationRepository.php @@ -50,7 +50,8 @@ class AnnotationRepository extends EntityRepository { return $this->createQueryBuilder('a') ->andWhere('a.id = :annotationId')->setParameter('annotationId', $annotationId) - ->getQuery()->getSingleResult() + ->getQuery() + ->getSingleResult() ; } @@ -67,7 +68,8 @@ class AnnotationRepository extends EntityRepository return $this->createQueryBuilder('a') ->where('a.entry = :entryId')->setParameter('entryId', $entryId) ->andwhere('a.user = :userId')->setParameter('userId', $userId) - ->getQuery()->getResult() + ->getQuery() + ->getResult() ; } @@ -88,4 +90,36 @@ class AnnotationRepository extends EntityRepository ->getQuery() ->getOneOrNullResult(); } + + /** + * Used only in test case to get the right annotation associated to the right user. + * + * @param string $username + * + * @return Annotation + */ + public function findOneByUsername($username) + { + return $this->createQueryBuilder('a') + ->leftJoin('a.user', 'u') + ->where('u.username = :username')->setParameter('username', $username) + ->orderBy('a.id', 'DESC') + ->setMaxResults(1) + ->getQuery() + ->getSingleResult(); + } + + /** + * Remove all annotations for a user id. + * Used when a user want to reset all informations. + * + * @param int $userId + */ + public function removeAllByUserId($userId) + { + $this->getEntityManager() + ->createQuery('DELETE FROM Wallabag\AnnotationBundle\Entity\Annotation a WHERE a.user = :userId') + ->setParameter('userId', $userId) + ->execute(); + } }