3 namespace Wallabag\CoreBundle\Repository
;
5 use Doctrine\ORM\Query
;
6 use Doctrine\ORM\EntityRepository
;
7 use Doctrine\ORM\Tools\Pagination\Paginator
;
9 class EntryRepository
extends EntityRepository
12 * Retrieves unread entries for a user
16 * @param int $maxResults
19 public function findUnreadByUser($userId, $firstResult, $maxResults = 12)
21 $qb = $this->createQueryBuilder('e')
23 ->setFirstResult($firstResult)
24 ->setMaxResults($maxResults)
25 ->where('e.isArchived = false')
26 ->andWhere('e.userId =:userId')->setParameter('userId', $userId)
27 ->andWhere('e.isDeleted=false')
28 ->orderBy('e.createdAt', 'desc')
31 $paginator = new Paginator($qb);
37 * Retrieves read entries for a user
41 * @param int $maxResults
44 public function findArchiveByUser($userId, $firstResult, $maxResults = 12)
46 $qb = $this->createQueryBuilder('e')
48 ->setFirstResult($firstResult)
49 ->setMaxResults($maxResults)
50 ->where('e.isArchived = true')
51 ->andWhere('e.userId =:userId')->setParameter('userId', $userId)
52 ->andWhere('e.isDeleted=false')
53 ->orderBy('e.createdAt', 'desc')
56 $paginator = new Paginator($qb);
62 * Retrieves starred entries for a user
66 * @param int $maxResults
69 public function findStarredByUser($userId, $firstResult, $maxResults = 12)
71 $qb = $this->createQueryBuilder('e')
73 ->setFirstResult($firstResult)
74 ->setMaxResults($maxResults)
75 ->where('e.isStarred = true')
76 ->andWhere('e.userId =:userId')->setParameter('userId', $userId)
77 ->andWhere('e.isDeleted=false')
78 ->orderBy('e.createdAt', 'desc')
81 $paginator = new Paginator($qb);
86 public function findEntries($userId, $isArchived, $isStarred, $isDeleted, $sort, $order)
88 $qb = $this->createQueryBuilder('e')
90 ->where('e.userId =:userId')->setParameter('userId', $userId);
92 if (!is_null($isArchived)) {
93 $qb->andWhere('e.isArchived =:isArchived')->setParameter('isArchived', $isArchived);
96 if (!is_null($isStarred)) {
97 $qb->andWhere('e.isStarred =:isStarred')->setParameter('isStarred', $isStarred);
100 if (!is_null($isDeleted)) {
101 $qb->andWhere('e.isDeleted =:isDeleted')->setParameter('isDeleted', $isDeleted);
104 if ('created' === $sort) {
105 $qb->orderBy('e.createdAt', $order);
106 } elseif ('updated' === $sort) {
107 $qb->orderBy('e.updatedAt', $order);
112 ->getResult(Query
::HYDRATE_ARRAY
);