]>
Commit | Line | Data |
---|---|---|
9d50517c NL |
1 | <?php |
2 | ||
ad4d1caa | 3 | namespace Wallabag\CoreBundle\Repository; |
9d50517c NL |
4 | |
5 | use Doctrine\ORM\Query; | |
6 | use Doctrine\ORM\EntityRepository; | |
163eae0b | 7 | use Doctrine\ORM\Tools\Pagination\Paginator; |
9d50517c | 8 | |
be463487 | 9 | class EntryRepository extends EntityRepository |
9d50517c | 10 | { |
b84a8055 NL |
11 | /** |
12 | * Retrieves unread entries for a user | |
13 | * | |
14 | * @param $userId | |
15 | * @param $firstResult | |
7df80cb3 | 16 | * @param int $maxResults |
b84a8055 NL |
17 | * @return Paginator |
18 | */ | |
163eae0b | 19 | public function findUnreadByUser($userId, $firstResult, $maxResults = 12) |
9d50517c NL |
20 | { |
21 | $qb = $this->createQueryBuilder('e') | |
22 | ->select('e') | |
163eae0b NL |
23 | ->setFirstResult($firstResult) |
24 | ->setMaxResults($maxResults) | |
905ae369 | 25 | ->where('e.isArchived = false') |
9d50517c | 26 | ->andWhere('e.userId =:userId')->setParameter('userId', $userId) |
905ae369 | 27 | ->andWhere('e.isDeleted=false') |
bc782eaa | 28 | ->orderBy('e.createdAt', 'desc') |
163eae0b | 29 | ->getQuery(); |
9d50517c | 30 | |
b84a8055 | 31 | $paginator = new Paginator($qb); |
163eae0b | 32 | |
b84a8055 | 33 | return $paginator; |
9d50517c | 34 | } |
bd9f0815 | 35 | |
b84a8055 NL |
36 | /** |
37 | * Retrieves read entries for a user | |
38 | * | |
39 | * @param $userId | |
40 | * @param $firstResult | |
7df80cb3 | 41 | * @param int $maxResults |
b84a8055 NL |
42 | * @return Paginator |
43 | */ | |
163eae0b | 44 | public function findArchiveByUser($userId, $firstResult, $maxResults = 12) |
bd9f0815 NL |
45 | { |
46 | $qb = $this->createQueryBuilder('e') | |
47 | ->select('e') | |
163eae0b NL |
48 | ->setFirstResult($firstResult) |
49 | ->setMaxResults($maxResults) | |
905ae369 | 50 | ->where('e.isArchived = true') |
bd9f0815 | 51 | ->andWhere('e.userId =:userId')->setParameter('userId', $userId) |
905ae369 | 52 | ->andWhere('e.isDeleted=false') |
bc782eaa | 53 | ->orderBy('e.createdAt', 'desc') |
b84a8055 NL |
54 | ->getQuery(); |
55 | ||
56 | $paginator = new Paginator($qb); | |
bd9f0815 | 57 | |
b84a8055 | 58 | return $paginator; |
bd9f0815 NL |
59 | } |
60 | ||
b84a8055 NL |
61 | /** |
62 | * Retrieves starred entries for a user | |
63 | * | |
64 | * @param $userId | |
65 | * @param $firstResult | |
7df80cb3 | 66 | * @param int $maxResults |
b84a8055 NL |
67 | * @return Paginator |
68 | */ | |
163eae0b | 69 | public function findStarredByUser($userId, $firstResult, $maxResults = 12) |
bd9f0815 NL |
70 | { |
71 | $qb = $this->createQueryBuilder('e') | |
72 | ->select('e') | |
163eae0b NL |
73 | ->setFirstResult($firstResult) |
74 | ->setMaxResults($maxResults) | |
905ae369 | 75 | ->where('e.isStarred = true') |
bd9f0815 | 76 | ->andWhere('e.userId =:userId')->setParameter('userId', $userId) |
905ae369 | 77 | ->andWhere('e.isDeleted=false') |
bc782eaa | 78 | ->orderBy('e.createdAt', 'desc') |
b84a8055 NL |
79 | ->getQuery(); |
80 | ||
81 | $paginator = new Paginator($qb); | |
bd9f0815 | 82 | |
b84a8055 | 83 | return $paginator; |
bd9f0815 | 84 | } |
a8c90c5c NL |
85 | |
86 | public function findEntries($userId, $isArchived, $isStarred, $isDeleted, $sort, $order) | |
87 | { | |
88 | $qb = $this->createQueryBuilder('e') | |
89 | ->select('e') | |
6079aaa3 | 90 | ->where('e.userId =:userId')->setParameter('userId', $userId); |
6e334aba NL |
91 | |
92 | if (!is_null($isArchived)) { | |
905ae369 | 93 | $qb->andWhere('e.isArchived =:isArchived')->setParameter('isArchived', $isArchived); |
6e334aba NL |
94 | } |
95 | ||
96 | if (!is_null($isStarred)) { | |
905ae369 | 97 | $qb->andWhere('e.isStarred =:isStarred')->setParameter('isStarred', $isStarred); |
6e334aba NL |
98 | } |
99 | ||
6079aaa3 NL |
100 | if (!is_null($isDeleted)) { |
101 | $qb->andWhere('e.isDeleted =:isDeleted')->setParameter('isDeleted', $isDeleted); | |
102 | } | |
103 | ||
bc782eaa NL |
104 | if ('created' === $sort) { |
105 | $qb->orderBy('e.createdAt', $order); | |
106 | } elseif ('updated' === $sort) { | |
107 | $qb->orderBy('e.updatedAt', $order); | |
108 | } | |
109 | ||
6e334aba | 110 | return $qb |
a8c90c5c NL |
111 | ->getQuery() |
112 | ->getResult(Query::HYDRATE_ARRAY); | |
a8c90c5c | 113 | } |
9d50517c | 114 | } |