+
+ /**
+ * Count all entries for a tag and a user.
+ *
+ * @param int $userId
+ * @param int $tagId
+ *
+ * @return int
+ */
+ public function countAllEntriesByUserIdAndTagId($userId, $tagId)
+ {
+ $qb = $this->createQueryBuilder('e')
+ ->select('count(e.id)')
+ ->leftJoin('e.tags', 't')
+ ->where('e.user=:userId')->setParameter('userId', $userId)
+ ->andWhere('t.id=:tagId')->setParameter('tagId', $tagId)
+ ;
+
+ return $qb->getQuery()->getSingleScalarResult();
+ }
+
+ /**
+ * Remove all entries 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\CoreBundle\Entity\Entry e WHERE e.user = :userId')
+ ->setParameter('userId', $userId)
+ ->execute();
+ }
+
+ public function removeArchivedByUserId($userId)
+ {
+ $this->getEntityManager()
+ ->createQuery('DELETE FROM Wallabag\CoreBundle\Entity\Entry e WHERE e.user = :userId AND e.isArchived = TRUE')
+ ->setParameter('userId', $userId)
+ ->execute();
+ }
+
+ /**
+ * Get id and url from all entries
+ * Used for the clean-duplicates command.
+ */
+ public function getAllEntriesIdAndUrl($userId)
+ {
+ $qb = $this->createQueryBuilder('e')
+ ->select('e.id, e.url')
+ ->where('e.user = :userid')->setParameter(':userid', $userId);
+
+ return $qb->getQuery()->getArrayResult();
+ }
+
+ /**
+ * Find all entries by url and owner.
+ *
+ * @param $url
+ * @param $userId
+ *
+ * @return array
+ */
+ public function findAllByUrlAndUserId($url, $userId)
+ {
+ return $this->createQueryBuilder('e')
+ ->where('e.url = :url')->setParameter('url', urldecode($url))
+ ->andWhere('e.user = :user_id')->setParameter('user_id', $userId)
+ ->getQuery()
+ ->getResult();
+ }