3 namespace Wallabag\CoreBundle\Repository
;
5 use Doctrine\ORM\EntityRepository
;
6 use Doctrine\ORM\Tools\Pagination\Paginator
;
8 class EntryRepository
extends EntityRepository
11 * Retrieves unread entries for a user
14 * @param int $firstResult
15 * @param int $maxResults
19 public function findUnreadByUser($userId, $firstResult, $maxResults = 12)
21 $qb = $this->createQueryBuilder('e')
22 ->setFirstResult($firstResult)
23 ->setMaxResults($maxResults)
24 ->leftJoin('e.user', 'u')
25 ->where('e.isArchived = false')
26 ->andWhere('u.id =:userId')->setParameter('userId', $userId)
27 ->orderBy('e.createdAt', 'desc')
30 $paginator = new Paginator($qb);
36 * Retrieves read entries for a user
39 * @param int $firstResult
40 * @param int $maxResults
44 public function findArchiveByUser($userId, $firstResult, $maxResults = 12)
46 $qb = $this->createQueryBuilder('e')
48 ->setFirstResult($firstResult)
49 ->setMaxResults($maxResults)
50 ->leftJoin('e.user', 'u')
51 ->where('e.isArchived = true')
52 ->andWhere('u.id =:userId')->setParameter('userId', $userId)
53 ->orderBy('e.createdAt', 'desc')
56 $paginator = new Paginator($qb);
62 * Retrieves starred entries for a user
65 * @param int $firstResult
66 * @param int $maxResults
70 public function findStarredByUser($userId, $firstResult, $maxResults = 12)
72 $qb = $this->createQueryBuilder('e')
74 ->setFirstResult($firstResult)
75 ->setMaxResults($maxResults)
76 ->leftJoin('e.user', 'u')
77 ->where('e.isStarred = true')
78 ->andWhere('u.id =:userId')->setParameter('userId', $userId)
79 ->orderBy('e.createdAt', 'desc')
82 $paginator = new Paginator($qb);
91 * @param bool $isArchived
92 * @param bool $isStarred
94 * @param string $order
98 public function findEntries($userId, $isArchived = null, $isStarred = null, $sort = 'created', $order = 'ASC')
100 $qb = $this->createQueryBuilder('e')
101 ->where('e.user =:userId')->setParameter('userId', $userId);
103 if (null !== $isArchived) {
104 $qb->andWhere('e.isArchived =:isArchived')->setParameter('isArchived', (bool) $isArchived);
107 if (null !== $isStarred) {
108 $qb->andWhere('e.isStarred =:isStarred')->setParameter('isStarred', (bool) $isStarred);
111 if ('created' === $sort) {
112 $qb->orderBy('e.createdAt', $order);
113 } elseif ('updated' === $sort) {
114 $qb->orderBy('e.updatedAt', $order);