X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FWallabag%2FCoreBundle%2FRepository%2FTagRepository.php;h=afeb985b30c272c9b9f76d84540b15eaf230f172;hb=f2e5fdc3666a2a6525b4202ab48df05efeebaf5c;hp=005142fc568707a9b2e807f390dbf2cca8814fb2;hpb=b3dc0749d3a007b9dced1d96b1f4000115c14784;p=github%2Fwallabag%2Fwallabag.git diff --git a/src/Wallabag/CoreBundle/Repository/TagRepository.php b/src/Wallabag/CoreBundle/Repository/TagRepository.php index 005142fc..afeb985b 100644 --- a/src/Wallabag/CoreBundle/Repository/TagRepository.php +++ b/src/Wallabag/CoreBundle/Repository/TagRepository.php @@ -3,119 +3,68 @@ namespace Wallabag\CoreBundle\Repository; use Doctrine\ORM\EntityRepository; -use Doctrine\ORM\Tools\Pagination\Paginator; +use Pagerfanta\Adapter\DoctrineORMAdapter; +use Pagerfanta\Pagerfanta; -class EntryRepository extends EntityRepository +class TagRepository extends EntityRepository { /** - * Retrieves unread entries for a user + * Return only the QueryBuilder to retrieve all tags for a given user. * * @param int $userId - * @param int $firstResult - * @param int $maxResults * - * @return Paginator + * @return QueryBuilder */ - public function findUnreadByUser($userId, $firstResult, $maxResults = 12) + private function getQbForAllTags($userId) { - $qb = $this->createQueryBuilder('e') - ->setFirstResult($firstResult) - ->setMaxResults($maxResults) - ->leftJoin('e.user', 'u') - ->where('e.isArchived = false') - ->andWhere('u.id =:userId')->setParameter('userId', $userId) - ->orderBy('e.createdAt', 'desc') - ->getQuery(); - - $paginator = new Paginator($qb); - - return $paginator; + return $this->createQueryBuilder('t') + ->leftJoin('t.entries', 'e') + ->where('e.user = :userId')->setParameter('userId', $userId); } /** - * Retrieves read entries for a user + * Find Tags and return a Pager. * * @param int $userId - * @param int $firstResult - * @param int $maxResults * - * @return Paginator + * @return Pagerfanta */ - public function findArchiveByUser($userId, $firstResult, $maxResults = 12) + public function findTags($userId) { - $qb = $this->createQueryBuilder('e') - ->select('e') - ->setFirstResult($firstResult) - ->setMaxResults($maxResults) - ->leftJoin('e.user', 'u') - ->where('e.isArchived = true') - ->andWhere('u.id =:userId')->setParameter('userId', $userId) - ->orderBy('e.createdAt', 'desc') - ->getQuery(); + $qb = $this->getQbForAllTags($userId); - $paginator = new Paginator($qb); + $pagerAdapter = new DoctrineORMAdapter($qb); - return $paginator; + return new Pagerfanta($pagerAdapter); } /** - * Retrieves starred entries for a user + * Find Tags. * * @param int $userId - * @param int $firstResult - * @param int $maxResults * - * @return Paginator + * @return array */ - public function findStarredByUser($userId, $firstResult, $maxResults = 12) + public function findAllTags($userId) { - $qb = $this->createQueryBuilder('e') - ->select('e') - ->setFirstResult($firstResult) - ->setMaxResults($maxResults) - ->leftJoin('e.user', 'u') - ->where('e.isStarred = true') - ->andWhere('u.id =:userId')->setParameter('userId', $userId) - ->orderBy('e.createdAt', 'desc') - ->getQuery(); - - $paginator = new Paginator($qb); - - return $paginator; + return $this->getQbForAllTags($userId) + ->getQuery() + ->getResult(); } /** - * Find Entries + * Used only in test case to get a tag for our entry. * - * @param int $userId - * @param bool $isArchived - * @param bool $isStarred - * @param string $sort - * @param string $order - * - * @return array + * @return Tag */ - public function findEntries($userId, $isArchived = null, $isStarred = null, $sort = 'created', $order = 'ASC') + public function findOneByEntryAndTagLabel($entry, $label) { - $qb = $this->createQueryBuilder('e') - ->where('e.user =:userId')->setParameter('userId', $userId); - - if (null !== $isArchived) { - $qb->andWhere('e.isArchived =:isArchived')->setParameter('isArchived', (bool) $isArchived); - } - - if (null !== $isStarred) { - $qb->andWhere('e.isStarred =:isStarred')->setParameter('isStarred', (bool) $isStarred); - } - - if ('created' === $sort) { - $qb->orderBy('e.createdAt', $order); - } elseif ('updated' === $sort) { - $qb->orderBy('e.updatedAt', $order); - } - - return $qb + 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() - ->getResult(); + ->getSingleResult(); } }