namespace Wallabag\CoreBundle\Repository;
use Doctrine\ORM\EntityRepository;
+use Doctrine\ORM\Query;
use Pagerfanta\Adapter\DoctrineORMAdapter;
use Pagerfanta\Pagerfanta;
use Wallabag\CoreBundle\Entity\Tag;
$qb->andWhere('e.isStarred =:isStarred')->setParameter('isStarred', (bool) $isStarred);
}
- if ($since >= 0) {
+ if ($since > 0) {
$qb->andWhere('e.updatedAt > :since')->setParameter('since', new \DateTime(date('Y-m-d H:i:s', $since)));
}
public function findByUrlAndUserId($url, $userId)
{
$res = $this->createQueryBuilder('e')
- ->where('e.url = :url')->setParameter('url', $url)
+ ->where('e.url = :url')->setParameter('url', urldecode($url))
->andWhere('e.user = :user_id')->setParameter('user_id', $userId)
->getQuery()
->getResult();
return $qb->getQuery()->getSingleScalarResult();
}
+
+ /**
+ * 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();
+ }
}