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