+
+ /**
+ * 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();
+ }