wallabag/src/Wallabag/CoreBundle/Repository/TagRepository.php

71 lines
1.6 KiB
PHP
Raw Normal View History

2015-02-20 16:18:48 +00:00
<?php
namespace Wallabag\CoreBundle\Repository;
use Doctrine\ORM\EntityRepository;
2015-08-07 16:17:23 +00:00
use Pagerfanta\Adapter\DoctrineORMAdapter;
use Pagerfanta\Pagerfanta;
2015-02-20 16:18:48 +00:00
2015-02-20 16:20:12 +00:00
class TagRepository extends EntityRepository
2015-02-20 16:18:48 +00:00
{
2015-08-07 16:17:23 +00:00
/**
2015-12-29 13:50:52 +00:00
* Return only the QueryBuilder to retrieve all tags for a given user.
2015-08-07 16:17:23 +00:00
*
* @param int $userId
2015-08-07 16:17:23 +00:00
*
2015-12-29 13:50:52 +00:00
* @return QueryBuilder
*/
private function getQbForAllTags($userId)
{
return $this->createQueryBuilder('t')
->leftJoin('t.entries', 'e')
->where('e.user = :userId')->setParameter('userId', $userId);
}
/**
* Find Tags and return a Pager.
*
* @param int $userId
*
* @return Pagerfanta
2015-08-07 16:17:23 +00:00
*/
public function findTags($userId)
{
2015-12-29 13:50:52 +00:00
$qb = $this->getQbForAllTags($userId);
2015-08-07 16:17:23 +00:00
$pagerAdapter = new DoctrineORMAdapter($qb);
return new Pagerfanta($pagerAdapter);
}
2015-08-19 09:46:21 +00:00
/**
2015-12-29 13:50:52 +00:00
* Find Tags.
2015-08-19 09:46:21 +00:00
*
2015-12-29 13:50:52 +00:00
* @param int $userId
2015-08-19 09:46:21 +00:00
*
2015-12-29 13:50:52 +00:00
* @return array
2015-08-19 09:46:21 +00:00
*/
2015-12-29 13:50:52 +00:00
public function findAllTags($userId)
2015-08-19 09:46:21 +00:00
{
2015-12-29 13:50:52 +00:00
return $this->getQbForAllTags($userId)
2015-08-19 09:46:21 +00:00
->getQuery()
2015-12-29 13:50:52 +00:00
->getResult();
2015-08-19 09:46:21 +00:00
}
2016-02-10 16:41:28 +00:00
/**
* Used only in test case to get a tag for our entry.
*
* @return Tag
*/
public function findOnebyEntryAndLabel($entry, $label)
{
return $this->createQueryBuilder('t')
->leftJoin('t.entries', 'e')
->where('e.id = :entryId')->setParameter('entryId', $entry->getId())
->andWhere('t.label = :label')->setParameter('label', $label)
->setMaxResults(1)
->getQuery()
->getSingleResult();
}
2015-02-20 16:18:48 +00:00
}