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