X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FWallabag%2FCoreBundle%2FRepository%2FEntryRepository.php;h=a8085ac9cbeb01bdc4c7bb6331ef1b72f6380765;hb=092ca70725b0263390e45c46f93828c613eca3f0;hp=f4c803f991c2e38fb41d510aa5f44ff3e197e1ae;hpb=be463487cc195026b11e92f1d6d6276f5851b97e;p=github%2Fwallabag%2Fwallabag.git diff --git a/src/Wallabag/CoreBundle/Repository/EntryRepository.php b/src/Wallabag/CoreBundle/Repository/EntryRepository.php index f4c803f9..a8085ac9 100644 --- a/src/Wallabag/CoreBundle/Repository/EntryRepository.php +++ b/src/Wallabag/CoreBundle/Repository/EntryRepository.php @@ -2,7 +2,6 @@ namespace Wallabag\CoreBundle\Repository; -use Doctrine\ORM\Query; use Doctrine\ORM\EntityRepository; use Doctrine\ORM\Tools\Pagination\Paginator; @@ -11,20 +10,20 @@ class EntryRepository extends EntityRepository /** * Retrieves unread entries for a user * - * @param $userId - * @param $firstResult - * @param int $maxResults + * @param int $userId + * @param int $firstResult + * @param int $maxResults + * * @return Paginator */ public function findUnreadByUser($userId, $firstResult, $maxResults = 12) { $qb = $this->createQueryBuilder('e') - ->select('e') ->setFirstResult($firstResult) ->setMaxResults($maxResults) + ->leftJoin('e.user', 'u') ->where('e.isArchived = false') - ->andWhere('e.userId =:userId')->setParameter('userId', $userId) - ->andWhere('e.isDeleted=false') + ->andWhere('u.id =:userId')->setParameter('userId', $userId) ->orderBy('e.createdAt', 'desc') ->getQuery(); @@ -36,9 +35,10 @@ class EntryRepository extends EntityRepository /** * Retrieves read entries for a user * - * @param $userId - * @param $firstResult - * @param int $maxResults + * @param int $userId + * @param int $firstResult + * @param int $maxResults + * * @return Paginator */ public function findArchiveByUser($userId, $firstResult, $maxResults = 12) @@ -47,9 +47,9 @@ class EntryRepository extends EntityRepository ->select('e') ->setFirstResult($firstResult) ->setMaxResults($maxResults) + ->leftJoin('e.user', 'u') ->where('e.isArchived = true') - ->andWhere('e.userId =:userId')->setParameter('userId', $userId) - ->andWhere('e.isDeleted=false') + ->andWhere('u.id =:userId')->setParameter('userId', $userId) ->orderBy('e.createdAt', 'desc') ->getQuery(); @@ -61,9 +61,10 @@ class EntryRepository extends EntityRepository /** * Retrieves starred entries for a user * - * @param $userId - * @param $firstResult - * @param int $maxResults + * @param int $userId + * @param int $firstResult + * @param int $maxResults + * * @return Paginator */ public function findStarredByUser($userId, $firstResult, $maxResults = 12) @@ -72,9 +73,9 @@ class EntryRepository extends EntityRepository ->select('e') ->setFirstResult($firstResult) ->setMaxResults($maxResults) + ->leftJoin('e.user', 'u') ->where('e.isStarred = true') - ->andWhere('e.userId =:userId')->setParameter('userId', $userId) - ->andWhere('e.isDeleted=false') + ->andWhere('u.id =:userId')->setParameter('userId', $userId) ->orderBy('e.createdAt', 'desc') ->getQuery(); @@ -83,22 +84,28 @@ class EntryRepository extends EntityRepository return $paginator; } - public function findEntries($userId, $isArchived, $isStarred, $isDeleted, $sort, $order) + /** + * Find Entries + * + * @param int $userId + * @param bool $isArchived + * @param bool $isStarred + * @param string $sort + * @param string $order + * + * @return array + */ + public function findEntries($userId, $isArchived = null, $isStarred = null, $sort = 'created', $order = 'ASC') { $qb = $this->createQueryBuilder('e') - ->select('e') - ->where('e.userId =:userId')->setParameter('userId', $userId); - - if (!is_null($isArchived)) { - $qb->andWhere('e.isArchived =:isArchived')->setParameter('isArchived', $isArchived); - } + ->where('e.user =:userId')->setParameter('userId', $userId); - if (!is_null($isStarred)) { - $qb->andWhere('e.isStarred =:isStarred')->setParameter('isStarred', $isStarred); + if (null !== $isArchived) { + $qb->andWhere('e.isArchived =:isArchived')->setParameter('isArchived', (bool) $isArchived); } - if (!is_null($isDeleted)) { - $qb->andWhere('e.isDeleted =:isDeleted')->setParameter('isDeleted', $isDeleted); + if (null !== $isStarred) { + $qb->andWhere('e.isStarred =:isStarred')->setParameter('isStarred', (bool) $isStarred); } if ('created' === $sort) { @@ -109,6 +116,25 @@ class EntryRepository extends EntityRepository return $qb ->getQuery() - ->getResult(Query::HYDRATE_ARRAY); + ->getResult(); + } + + /** + * Fetch an entry with a tag. Only used for tests. + * + * @return Entry + */ + public function findOneWithTags($userId) + { + $qb = $this->createQueryBuilder('e') + ->innerJoin('e.tags', 't') + ->addSelect('t') + ->where('t.user=:userId')->setParameter('userId', 1); + + return $qb->getQuery()->getOneOrNullResult(); + + return $qb + ->getQuery() + ->getOneOrNullResult(); } }