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.
16 * @return QueryBuilder
18 public function findUnreadByUser($userId)
20 return $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');
28 * Retrieves read entries for a user.
32 * @return QueryBuilder
34 public function findArchiveByUser($userId)
36 return $this->createQueryBuilder('e')
37 ->leftJoin('e.user', 'u')
38 ->where('e.isArchived = true')
39 ->andWhere('u.id =:userId')->setParameter('userId', $userId)
40 ->orderBy('e.id', 'desc');
44 * Retrieves starred entries for a user.
48 * @return QueryBuilder
50 public function findStarredByUser($userId)
52 return $this->createQueryBuilder('e')
53 ->leftJoin('e.user', 'u')
54 ->where('e.isStarred = true')
55 ->andWhere('u.id =:userId')->setParameter('userId', $userId)
56 ->orderBy('e.id', 'desc');
63 * @param bool $isArchived
64 * @param bool $isStarred
66 * @param string $order
70 public function findEntries($userId, $isArchived = null, $isStarred = null, $sort = 'created', $order = 'ASC')
72 $qb = $this->createQueryBuilder('e')
73 ->where('e.user =:userId')->setParameter('userId', $userId);
75 if (null !== $isArchived) {
76 $qb->andWhere('e.isArchived =:isArchived')->setParameter('isArchived', (bool) $isArchived);
79 if (null !== $isStarred) {
80 $qb->andWhere('e.isStarred =:isStarred')->setParameter('isStarred', (bool) $isStarred);
83 if ('created' === $sort) {
84 $qb->orderBy('e.id', $order);
85 } elseif ('updated' === $sort) {
86 $qb->orderBy('e.updatedAt', $order);
89 $pagerAdapter = new DoctrineORMAdapter($qb);
91 return new Pagerfanta($pagerAdapter);
95 * Fetch an entry with a tag. Only used for tests.
99 public function findOneWithTags($userId)
101 $qb = $this->createQueryBuilder('e')
102 ->innerJoin('e.tags', 't')
103 ->innerJoin('e.user', 'u')
104 ->addSelect('t', 'u')
105 ->where('e.user=:userId')->setParameter('userId', $userId)
108 return $qb->getQuery()->getResult();