]>
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 | |
9d50517c NL |
9 | class EntriesRepository extends EntityRepository |
10 | { | |
b84a8055 NL |
11 | /** |
12 | * Retrieves unread entries for a user | |
13 | * | |
14 | * @param $userId | |
15 | * @param $firstResult | |
16 | * @param int $maxResults | |
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) | |
9d50517c NL |
25 | ->where('e.isRead = 0') |
26 | ->andWhere('e.userId =:userId')->setParameter('userId', $userId) | |
163eae0b | 27 | ->getQuery(); |
9d50517c | 28 | |
b84a8055 | 29 | $paginator = new Paginator($qb); |
163eae0b | 30 | |
b84a8055 | 31 | return $paginator; |
9d50517c | 32 | } |
bd9f0815 | 33 | |
b84a8055 NL |
34 | /** |
35 | * Retrieves read entries for a user | |
36 | * | |
37 | * @param $userId | |
38 | * @param $firstResult | |
39 | * @param int $maxResults | |
40 | * @return Paginator | |
41 | */ | |
163eae0b | 42 | public function findArchiveByUser($userId, $firstResult, $maxResults = 12) |
bd9f0815 NL |
43 | { |
44 | $qb = $this->createQueryBuilder('e') | |
45 | ->select('e') | |
163eae0b NL |
46 | ->setFirstResult($firstResult) |
47 | ->setMaxResults($maxResults) | |
bd9f0815 NL |
48 | ->where('e.isRead = 1') |
49 | ->andWhere('e.userId =:userId')->setParameter('userId', $userId) | |
b84a8055 NL |
50 | ->getQuery(); |
51 | ||
52 | $paginator = new Paginator($qb); | |
bd9f0815 | 53 | |
b84a8055 | 54 | return $paginator; |
bd9f0815 NL |
55 | } |
56 | ||
b84a8055 NL |
57 | /** |
58 | * Retrieves starred entries for a user | |
59 | * | |
60 | * @param $userId | |
61 | * @param $firstResult | |
62 | * @param int $maxResults | |
63 | * @return Paginator | |
64 | */ | |
163eae0b | 65 | public function findStarredByUser($userId, $firstResult, $maxResults = 12) |
bd9f0815 NL |
66 | { |
67 | $qb = $this->createQueryBuilder('e') | |
68 | ->select('e') | |
163eae0b NL |
69 | ->setFirstResult($firstResult) |
70 | ->setMaxResults($maxResults) | |
bd9f0815 NL |
71 | ->where('e.isFav = 1') |
72 | ->andWhere('e.userId =:userId')->setParameter('userId', $userId) | |
b84a8055 NL |
73 | ->getQuery(); |
74 | ||
75 | $paginator = new Paginator($qb); | |
bd9f0815 | 76 | |
b84a8055 | 77 | return $paginator; |
bd9f0815 | 78 | } |
a8c90c5c NL |
79 | |
80 | public function findEntries($userId, $isArchived, $isStarred, $isDeleted, $sort, $order) | |
81 | { | |
82 | $qb = $this->createQueryBuilder('e') | |
83 | ->select('e') | |
84 | ->where('e.isFav =:isStarred')->setParameter('isStarred', $isStarred) | |
85 | ->andWhere('e.isRead =:isArchived')->setParameter('isArchived', $isArchived) | |
86 | ->andWhere('e.userId =:userId')->setParameter('userId', $userId) | |
87 | ->getQuery() | |
88 | ->getResult(Query::HYDRATE_ARRAY); | |
89 | ||
90 | return $qb; | |
91 | } | |
9d50517c | 92 | } |