3 namespace Wallabag\CoreBundle\Repository
;
5 use Doctrine\ORM\EntityRepository
;
6 use Pagerfanta\Adapter\DoctrineORMAdapter
;
7 use Pagerfanta\Pagerfanta
;
9 class EntryRepository
extends EntityRepository
12 * Retrieves unread entries for a user.
18 public function findUnreadByUser($userId)
20 $qb = $this->createQueryBuilder('e')
21 ->leftJoin('e.user', 'u')
22 ->where('e.isArchived = false')
23 ->andWhere('u.id =:userId')->setParameter('userId', $userId)
24 ->orderBy('e.id', 'desc')
27 $pagerAdapter = new DoctrineORMAdapter($qb);
29 return new Pagerfanta($pagerAdapter);
33 * Retrieves read entries for a user.
39 public function findArchiveByUser($userId)
41 $qb = $this->createQueryBuilder('e')
43 ->leftJoin('e.user', 'u')
44 ->where('e.isArchived = true')
45 ->andWhere('u.id =:userId')->setParameter('userId', $userId)
46 ->orderBy('e.id', 'desc')
49 $pagerAdapter = new DoctrineORMAdapter($qb);
51 return new Pagerfanta($pagerAdapter);
55 * Retrieves starred entries for a user.
61 public function findStarredByUser($userId)
64 $qb = $this->createQueryBuilder('e')
66 ->leftJoin('e.user', 'u')
67 ->where('e.isStarred = true')
68 ->andWhere('u.id =:userId')->setParameter('userId', $userId)
69 ->orderBy('e.id', 'desc')
72 $pagerAdapter = new DoctrineORMAdapter($qb);
74 return new Pagerfanta($pagerAdapter);
81 * @param bool $isArchived
82 * @param bool $isStarred
84 * @param string $order
88 public function findEntries($userId, $isArchived = null, $isStarred = null, $sort = 'created', $order = 'ASC')
90 $qb = $this->createQueryBuilder('e')
91 ->where('e.user =:userId')->setParameter('userId', $userId);
93 if (null !== $isArchived) {
94 $qb->andWhere('e.isArchived =:isArchived')->setParameter('isArchived', (bool) $isArchived);
97 if (null !== $isStarred) {
98 $qb->andWhere('e.isStarred =:isStarred')->setParameter('isStarred', (bool) $isStarred);
101 if ('created' === $sort) {
102 $qb->orderBy('e.id', $order);
103 } elseif ('updated' === $sort) {
104 $qb->orderBy('e.updatedAt', $order);
107 $pagerAdapter = new DoctrineORMAdapter($qb);
109 return new Pagerfanta($pagerAdapter);
113 * Fetch an entry with a tag. Only used for tests.
117 public function findOneWithTags($userId)
119 $qb = $this->createQueryBuilder('e')
120 ->innerJoin('e.tags', 't')
121 ->innerJoin('e.user', 'u')
122 ->addSelect('t', 'u')
123 ->where('e.user=:userId')->setParameter('userId', $userId)
126 return $qb->getQuery()->getResult();