3 namespace Wallabag\CoreBundle\Repository
;
5 use Doctrine\ORM\EntityRepository
;
6 use Doctrine\ORM\Tools\Pagination\Paginator
;
7 use Pagerfanta\Adapter\DoctrineORMAdapter
;
8 use Pagerfanta\Pagerfanta
;
10 class EntryRepository
extends EntityRepository
13 * Retrieves unread entries for a user.
16 * @param int $firstResult
17 * @param int $maxResults
21 public function findUnreadByUser($userId, $firstResult, $maxResults = 12)
23 $qb = $this->createQueryBuilder('e')
24 ->setFirstResult($firstResult)
25 ->setMaxResults($maxResults)
26 ->leftJoin('e.user', 'u')
27 ->where('e.isArchived = false')
28 ->andWhere('u.id =:userId')->setParameter('userId', $userId)
29 ->orderBy('e.id', 'desc')
32 $paginator = new Paginator($qb);
38 * Retrieves read entries for a user.
41 * @param int $firstResult
42 * @param int $maxResults
46 public function findArchiveByUser($userId, $firstResult, $maxResults = 12)
48 $qb = $this->createQueryBuilder('e')
50 ->setFirstResult($firstResult)
51 ->setMaxResults($maxResults)
52 ->leftJoin('e.user', 'u')
53 ->where('e.isArchived = true')
54 ->andWhere('u.id =:userId')->setParameter('userId', $userId)
55 ->orderBy('e.id', 'desc')
58 $paginator = new Paginator($qb);
64 * Retrieves starred entries for a user.
67 * @param int $firstResult
68 * @param int $maxResults
72 public function findStarredByUser($userId, $firstResult, $maxResults = 12)
74 $qb = $this->createQueryBuilder('e')
76 ->setFirstResult($firstResult)
77 ->setMaxResults($maxResults)
78 ->leftJoin('e.user', 'u')
79 ->where('e.isStarred = true')
80 ->andWhere('u.id =:userId')->setParameter('userId', $userId)
81 ->orderBy('e.id', 'desc')
84 $paginator = new Paginator($qb);
93 * @param bool $isArchived
94 * @param bool $isStarred
96 * @param string $order
100 public function findEntries($userId, $isArchived = null, $isStarred = null, $sort = 'created', $order = 'ASC')
102 $qb = $this->createQueryBuilder('e')
103 ->where('e.user =:userId')->setParameter('userId', $userId);
105 if (null !== $isArchived) {
106 $qb->andWhere('e.isArchived =:isArchived')->setParameter('isArchived', (bool) $isArchived);
109 if (null !== $isStarred) {
110 $qb->andWhere('e.isStarred =:isStarred')->setParameter('isStarred', (bool) $isStarred);
113 if ('created' === $sort) {
114 $qb->orderBy('e.id', $order);
115 } elseif ('updated' === $sort) {
116 $qb->orderBy('e.updatedAt', $order);
119 $pagerAdapter = new DoctrineORMAdapter($qb);
121 return new Pagerfanta($pagerAdapter);
125 * Fetch an entry with a tag. Only used for tests.
129 public function findOneWithTags($userId)
131 $qb = $this->createQueryBuilder('e')
132 ->innerJoin('e.tags', 't')
133 ->innerJoin('e.user', 'u')
134 ->addSelect('t', 'u')
135 ->where('e.user=:userId')->setParameter('userId', $userId)
138 return $qb->getQuery()->getResult();