aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/Wallabag/CoreBundle/Repository/TagRepository.php121
1 files changed, 121 insertions, 0 deletions
diff --git a/src/Wallabag/CoreBundle/Repository/TagRepository.php b/src/Wallabag/CoreBundle/Repository/TagRepository.php
new file mode 100644
index 00000000..005142fc
--- /dev/null
+++ b/src/Wallabag/CoreBundle/Repository/TagRepository.php
@@ -0,0 +1,121 @@
1<?php
2
3namespace Wallabag\CoreBundle\Repository;
4
5use Doctrine\ORM\EntityRepository;
6use Doctrine\ORM\Tools\Pagination\Paginator;
7
8class EntryRepository extends EntityRepository
9{
10 /**
11 * Retrieves unread entries for a user
12 *
13 * @param int $userId
14 * @param int $firstResult
15 * @param int $maxResults
16 *
17 * @return Paginator
18 */
19 public function findUnreadByUser($userId, $firstResult, $maxResults = 12)
20 {
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')
28 ->getQuery();
29
30 $paginator = new Paginator($qb);
31
32 return $paginator;
33 }
34
35 /**
36 * Retrieves read entries for a user
37 *
38 * @param int $userId
39 * @param int $firstResult
40 * @param int $maxResults
41 *
42 * @return Paginator
43 */
44 public function findArchiveByUser($userId, $firstResult, $maxResults = 12)
45 {
46 $qb = $this->createQueryBuilder('e')
47 ->select('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')
54 ->getQuery();
55
56 $paginator = new Paginator($qb);
57
58 return $paginator;
59 }
60
61 /**
62 * Retrieves starred entries for a user
63 *
64 * @param int $userId
65 * @param int $firstResult
66 * @param int $maxResults
67 *
68 * @return Paginator
69 */
70 public function findStarredByUser($userId, $firstResult, $maxResults = 12)
71 {
72 $qb = $this->createQueryBuilder('e')
73 ->select('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')
80 ->getQuery();
81
82 $paginator = new Paginator($qb);
83
84 return $paginator;
85 }
86
87 /**
88 * Find Entries
89 *
90 * @param int $userId
91 * @param bool $isArchived
92 * @param bool $isStarred
93 * @param string $sort
94 * @param string $order
95 *
96 * @return array
97 */
98 public function findEntries($userId, $isArchived = null, $isStarred = null, $sort = 'created', $order = 'ASC')
99 {
100 $qb = $this->createQueryBuilder('e')
101 ->where('e.user =:userId')->setParameter('userId', $userId);
102
103 if (null !== $isArchived) {
104 $qb->andWhere('e.isArchived =:isArchived')->setParameter('isArchived', (bool) $isArchived);
105 }
106
107 if (null !== $isStarred) {
108 $qb->andWhere('e.isStarred =:isStarred')->setParameter('isStarred', (bool) $isStarred);
109 }
110
111 if ('created' === $sort) {
112 $qb->orderBy('e.createdAt', $order);
113 } elseif ('updated' === $sort) {
114 $qb->orderBy('e.updatedAt', $order);
115 }
116
117 return $qb
118 ->getQuery()
119 ->getResult();
120 }
121}