namespace Wallabag\CoreBundle\Repository;
use Doctrine\ORM\EntityRepository;
-use Pagerfanta\Adapter\DoctrineORMAdapter;
-use Pagerfanta\Pagerfanta;
class TagRepository extends EntityRepository
{
*
* @return array
*/
- public function findTags($userId)
+ public function findAllTags($userId)
{
- $qb = $this->createQueryBuilder('t')
- ->where('t.user =:userId')->setParameter('userId', $userId);
-
- $pagerAdapter = new DoctrineORMAdapter($qb);
-
- return new Pagerfanta($pagerAdapter);
+ return $this->createQueryBuilder('t')
+ ->leftJoin('t.entries', 'e')
+ ->where('e.user = :userId')->setParameter('userId', $userId);
}
/**
- * Find a tag by its label and its owner.
- *
- * @param string $label
- * @param int $userId
+ * Used only in test case to get a tag for our entry.
*
- * @return Tag|null
+ * @return Tag
*/
- public function findOneByLabelAndUserId($label, $userId)
+ public function findOneByEntryAndTagLabel($entry, $label)
{
return $this->createQueryBuilder('t')
- ->where('t.label = :label')->setParameter('label', $label)
- ->andWhere('t.user = :user_id')->setParameter('user_id', $userId)
+ ->leftJoin('t.entries', 'e')
+ ->where('e.id = :entryId')->setParameter('entryId', $entry->getId())
+ ->andWhere('t.label = :label')->setParameter('label', $label)
+ ->setMaxResults(1)
->getQuery()
- ->getOneOrNullResult();
+ ->getSingleResult();
}
}