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