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