]>
Commit | Line | Data |
---|---|---|
9d50517c NL |
1 | <?php |
2 | ||
ad4d1caa | 3 | namespace Wallabag\CoreBundle\Repository; |
9d50517c | 4 | |
9d50517c | 5 | use Doctrine\ORM\EntityRepository; |
163eae0b | 6 | use Doctrine\ORM\Tools\Pagination\Paginator; |
9d50517c | 7 | |
be463487 | 8 | class EntryRepository extends EntityRepository |
9d50517c | 9 | { |
b84a8055 NL |
10 | /** |
11 | * Retrieves unread entries for a user | |
12 | * | |
3b815d2d J |
13 | * @param int $userId |
14 | * @param int $firstResult | |
15 | * @param int $maxResults | |
16 | * | |
b84a8055 NL |
17 | * @return Paginator |
18 | */ | |
163eae0b | 19 | public function findUnreadByUser($userId, $firstResult, $maxResults = 12) |
9d50517c NL |
20 | { |
21 | $qb = $this->createQueryBuilder('e') | |
163eae0b NL |
22 | ->setFirstResult($firstResult) |
23 | ->setMaxResults($maxResults) | |
3b815d2d | 24 | ->leftJoin('e.user', 'u') |
905ae369 | 25 | ->where('e.isArchived = false') |
3b815d2d | 26 | ->andWhere('u.id =: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 | * | |
3b815d2d J |
39 | * @param int $userId |
40 | * @param int $firstResult | |
41 | * @param int $maxResults | |
42 | * | |
b84a8055 NL |
43 | * @return Paginator |
44 | */ | |
163eae0b | 45 | public function findArchiveByUser($userId, $firstResult, $maxResults = 12) |
bd9f0815 NL |
46 | { |
47 | $qb = $this->createQueryBuilder('e') | |
48 | ->select('e') | |
163eae0b NL |
49 | ->setFirstResult($firstResult) |
50 | ->setMaxResults($maxResults) | |
3b815d2d | 51 | ->leftJoin('e.user', 'u') |
905ae369 | 52 | ->where('e.isArchived = true') |
3b815d2d | 53 | ->andWhere('u.id =:userId')->setParameter('userId', $userId) |
905ae369 | 54 | ->andWhere('e.isDeleted=false') |
bc782eaa | 55 | ->orderBy('e.createdAt', 'desc') |
b84a8055 NL |
56 | ->getQuery(); |
57 | ||
58 | $paginator = new Paginator($qb); | |
bd9f0815 | 59 | |
b84a8055 | 60 | return $paginator; |
bd9f0815 NL |
61 | } |
62 | ||
b84a8055 NL |
63 | /** |
64 | * Retrieves starred entries for a user | |
65 | * | |
3b815d2d J |
66 | * @param int $userId |
67 | * @param int $firstResult | |
68 | * @param int $maxResults | |
69 | * | |
b84a8055 NL |
70 | * @return Paginator |
71 | */ | |
163eae0b | 72 | public function findStarredByUser($userId, $firstResult, $maxResults = 12) |
bd9f0815 NL |
73 | { |
74 | $qb = $this->createQueryBuilder('e') | |
75 | ->select('e') | |
163eae0b NL |
76 | ->setFirstResult($firstResult) |
77 | ->setMaxResults($maxResults) | |
3b815d2d | 78 | ->leftJoin('e.user', 'u') |
905ae369 | 79 | ->where('e.isStarred = true') |
3b815d2d J |
80 | ->andWhere('u.id =:userId')->setParameter('userId', $userId) |
81 | ->andWhere('e.isDeleted = false') | |
bc782eaa | 82 | ->orderBy('e.createdAt', 'desc') |
b84a8055 NL |
83 | ->getQuery(); |
84 | ||
85 | $paginator = new Paginator($qb); | |
bd9f0815 | 86 | |
b84a8055 | 87 | return $paginator; |
bd9f0815 | 88 | } |
a8c90c5c | 89 | |
3b815d2d J |
90 | /** |
91 | * Find Entries | |
92 | * | |
2a94b1d1 NL |
93 | * @param int $userId |
94 | * @param bool $isArchived | |
95 | * @param bool $isStarred | |
96 | * @param bool $isDeleted | |
97 | * @param string $sort | |
98 | * @param string $order | |
3b815d2d | 99 | * |
017e2089 | 100 | * @return array |
3b815d2d J |
101 | */ |
102 | public function findEntries($userId, $isArchived = null, $isStarred = null, $isDeleted = null, $sort = 'created', $order = 'ASC') | |
a8c90c5c NL |
103 | { |
104 | $qb = $this->createQueryBuilder('e') | |
3b815d2d J |
105 | ->leftJoin('e.user', 'u') |
106 | ->where('u.id =:userId')->setParameter('userId', $userId); | |
6e334aba | 107 | |
3b815d2d J |
108 | if (null !== $isArchived) { |
109 | $qb->andWhere('e.isArchived =:isArchived')->setParameter('isArchived', (bool) $isArchived); | |
6e334aba NL |
110 | } |
111 | ||
3b815d2d J |
112 | if (null !== $isStarred) { |
113 | $qb->andWhere('e.isStarred =:isStarred')->setParameter('isStarred', (bool) $isStarred); | |
6e334aba NL |
114 | } |
115 | ||
3b815d2d J |
116 | if (null !== $isDeleted) { |
117 | $qb->andWhere('e.isDeleted =:isDeleted')->setParameter('isDeleted', (bool) $isDeleted); | |
6079aaa3 NL |
118 | } |
119 | ||
bc782eaa NL |
120 | if ('created' === $sort) { |
121 | $qb->orderBy('e.createdAt', $order); | |
122 | } elseif ('updated' === $sort) { | |
123 | $qb->orderBy('e.updatedAt', $order); | |
124 | } | |
125 | ||
6e334aba | 126 | return $qb |
a8c90c5c | 127 | ->getQuery() |
eaf95758 | 128 | ->getResult(); |
a8c90c5c | 129 | } |
9d50517c | 130 | } |