X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FWallabag%2FCoreBundle%2FRepository%2FEntryRepository.php;h=1335e808666bc05eb63042d84b080482d7dff368;hb=4346a86068781f4acdeb574d7e2af08b77b58ea7;hp=5ae1337a8ca44faecc9891fc2c6265e0bf7e6f09;hpb=3b815d2de5a852fe2ebad5827bd4c9070aa175ea;p=github%2Fwallabag%2Fwallabag.git diff --git a/src/Wallabag/CoreBundle/Repository/EntryRepository.php b/src/Wallabag/CoreBundle/Repository/EntryRepository.php index 5ae1337a..1335e808 100644 --- a/src/Wallabag/CoreBundle/Repository/EntryRepository.php +++ b/src/Wallabag/CoreBundle/Repository/EntryRepository.php @@ -2,14 +2,15 @@ namespace Wallabag\CoreBundle\Repository; -use Doctrine\ORM\Query; use Doctrine\ORM\EntityRepository; use Doctrine\ORM\Tools\Pagination\Paginator; +use Pagerfanta\Adapter\DoctrineORMAdapter; +use Pagerfanta\Pagerfanta; class EntryRepository extends EntityRepository { /** - * Retrieves unread entries for a user + * Retrieves unread entries for a user. * * @param int $userId * @param int $firstResult @@ -25,8 +26,7 @@ class EntryRepository extends EntityRepository ->leftJoin('e.user', 'u') ->where('e.isArchived = false') ->andWhere('u.id =:userId')->setParameter('userId', $userId) - ->andWhere('e.isDeleted=false') - ->orderBy('e.createdAt', 'desc') + ->orderBy('e.id', 'desc') ->getQuery(); $paginator = new Paginator($qb); @@ -35,7 +35,7 @@ class EntryRepository extends EntityRepository } /** - * Retrieves read entries for a user + * Retrieves read entries for a user. * * @param int $userId * @param int $firstResult @@ -52,8 +52,7 @@ class EntryRepository extends EntityRepository ->leftJoin('e.user', 'u') ->where('e.isArchived = true') ->andWhere('u.id =:userId')->setParameter('userId', $userId) - ->andWhere('e.isDeleted=false') - ->orderBy('e.createdAt', 'desc') + ->orderBy('e.id', 'desc') ->getQuery(); $paginator = new Paginator($qb); @@ -62,7 +61,7 @@ class EntryRepository extends EntityRepository } /** - * Retrieves starred entries for a user + * Retrieves starred entries for a user. * * @param int $userId * @param int $firstResult @@ -79,8 +78,7 @@ class EntryRepository extends EntityRepository ->leftJoin('e.user', 'u') ->where('e.isStarred = true') ->andWhere('u.id =:userId')->setParameter('userId', $userId) - ->andWhere('e.isDeleted = false') - ->orderBy('e.createdAt', 'desc') + ->orderBy('e.id', 'desc') ->getQuery(); $paginator = new Paginator($qb); @@ -89,22 +87,20 @@ class EntryRepository extends EntityRepository } /** - * Find Entries + * Find Entries. * - * @param int $userId - * @param bool $isArchived - * @param bool $isStarred - * @param bool $isDeleted - * @param string $sort - * @param string $order + * @param int $userId + * @param bool $isArchived + * @param bool $isStarred + * @param string $sort + * @param string $order * - * @return ArrayCollection + * @return array */ - public function findEntries($userId, $isArchived = null, $isStarred = null, $isDeleted = null, $sort = 'created', $order = 'ASC') + public function findEntries($userId, $isArchived = null, $isStarred = null, $sort = 'created', $order = 'ASC') { $qb = $this->createQueryBuilder('e') - ->leftJoin('e.user', 'u') - ->where('u.id =:userId')->setParameter('userId', $userId); + ->where('e.user =:userId')->setParameter('userId', $userId); if (null !== $isArchived) { $qb->andWhere('e.isArchived =:isArchived')->setParameter('isArchived', (bool) $isArchived); @@ -114,18 +110,31 @@ class EntryRepository extends EntityRepository $qb->andWhere('e.isStarred =:isStarred')->setParameter('isStarred', (bool) $isStarred); } - if (null !== $isDeleted) { - $qb->andWhere('e.isDeleted =:isDeleted')->setParameter('isDeleted', (bool) $isDeleted); - } - if ('created' === $sort) { - $qb->orderBy('e.createdAt', $order); + $qb->orderBy('e.id', $order); } elseif ('updated' === $sort) { $qb->orderBy('e.updatedAt', $order); } - return $qb - ->getQuery() - ->getResult(Query::HYDRATE_ARRAY); + $pagerAdapter = new DoctrineORMAdapter($qb); + + return new Pagerfanta($pagerAdapter); + } + + /** + * Fetch an entry with a tag. Only used for tests. + * + * @return Entry + */ + public function findOneWithTags($userId) + { + $qb = $this->createQueryBuilder('e') + ->innerJoin('e.tags', 't') + ->innerJoin('e.user', 'u') + ->addSelect('t', 'u') + ->where('e.user=:userId')->setParameter('userId', $userId) + ; + + return $qb->getQuery()->getResult(); } }