]>
Commit | Line | Data |
---|---|---|
1 | <?php | |
2 | ||
3 | namespace Wallabag\CoreBundle\Repository; | |
4 | ||
5 | use Doctrine\ORM\Query; | |
6 | use Doctrine\ORM\EntityRepository; | |
7 | use Doctrine\ORM\Tools\Pagination\Paginator; | |
8 | use Wallabag\CoreBundle\Entity\Entries; | |
9 | use Wallabag\CoreBundle\Service\Extractor; | |
10 | ||
11 | class EntriesRepository extends EntityRepository | |
12 | { | |
13 | /** | |
14 | * Retrieves unread entries for a user | |
15 | * | |
16 | * @param $userId | |
17 | * @param $firstResult | |
18 | * @param int $maxResults | |
19 | * @return Paginator | |
20 | */ | |
21 | public function findUnreadByUser($userId, $firstResult, $maxResults = 12) | |
22 | { | |
23 | $qb = $this->createQueryBuilder('e') | |
24 | ->select('e') | |
25 | ->setFirstResult($firstResult) | |
26 | ->setMaxResults($maxResults) | |
27 | ->where('e.isRead = 0') | |
28 | ->andWhere('e.userId =:userId')->setParameter('userId', $userId) | |
29 | ->getQuery(); | |
30 | ||
31 | $paginator = new Paginator($qb); | |
32 | ||
33 | return $paginator; | |
34 | } | |
35 | ||
36 | /** | |
37 | * Retrieves read entries for a user | |
38 | * | |
39 | * @param $userId | |
40 | * @param $firstResult | |
41 | * @param int $maxResults | |
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 | ->where('e.isRead = 1') | |
51 | ->andWhere('e.userId =:userId')->setParameter('userId', $userId) | |
52 | ->getQuery(); | |
53 | ||
54 | $paginator = new Paginator($qb); | |
55 | ||
56 | return $paginator; | |
57 | } | |
58 | ||
59 | /** | |
60 | * Retrieves starred entries for a user | |
61 | * | |
62 | * @param $userId | |
63 | * @param $firstResult | |
64 | * @param int $maxResults | |
65 | * @return Paginator | |
66 | */ | |
67 | public function findStarredByUser($userId, $firstResult, $maxResults = 12) | |
68 | { | |
69 | $qb = $this->createQueryBuilder('e') | |
70 | ->select('e') | |
71 | ->setFirstResult($firstResult) | |
72 | ->setMaxResults($maxResults) | |
73 | ->where('e.isFav = 1') | |
74 | ->andWhere('e.userId =:userId')->setParameter('userId', $userId) | |
75 | ->getQuery(); | |
76 | ||
77 | $paginator = new Paginator($qb); | |
78 | ||
79 | return $paginator; | |
80 | } | |
81 | ||
82 | public function findEntries($userId, $isArchived, $isStarred, $isDeleted, $sort, $order) | |
83 | { | |
84 | //TODO tous les paramètres ne sont pas utilisés, à corriger | |
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 | } | |
95 | } |