]>
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 | ->andWhere('e.isDeleted=0') | |
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 | ->andWhere('e.isDeleted=0') | |
53 | ->getQuery(); | |
54 | ||
55 | $paginator = new Paginator($qb); | |
56 | ||
57 | return $paginator; | |
58 | } | |
59 | ||
60 | /** | |
61 | * Retrieves starred entries for a user | |
62 | * | |
63 | * @param $userId | |
64 | * @param $firstResult | |
65 | * @param int $maxResults | |
66 | * @return Paginator | |
67 | */ | |
68 | public function findStarredByUser($userId, $firstResult, $maxResults = 12) | |
69 | { | |
70 | $qb = $this->createQueryBuilder('e') | |
71 | ->select('e') | |
72 | ->setFirstResult($firstResult) | |
73 | ->setMaxResults($maxResults) | |
74 | ->where('e.isFav = 1') | |
75 | ->andWhere('e.userId =:userId')->setParameter('userId', $userId) | |
76 | ->andWhere('e.isDeleted=0') | |
77 | ->getQuery(); | |
78 | ||
79 | $paginator = new Paginator($qb); | |
80 | ||
81 | return $paginator; | |
82 | } | |
83 | ||
84 | public function findEntries($userId, $isArchived, $isStarred, $isDeleted, $sort, $order) | |
85 | { | |
86 | //TODO tous les paramètres ne sont pas utilisés, à corriger | |
87 | $qb = $this->createQueryBuilder('e') | |
88 | ->select('e') | |
89 | ->where('e.isFav =:isStarred')->setParameter('isStarred', $isStarred) | |
90 | ->andWhere('e.isRead =:isArchived')->setParameter('isArchived', $isArchived) | |
91 | ->andWhere('e.userId =:userId')->setParameter('userId', $userId) | |
92 | ->andWhere('e.isDeleted=0') | |
93 | ->getQuery() | |
94 | ->getResult(Query::HYDRATE_ARRAY); | |
95 | ||
96 | return $qb; | |
97 | } | |
98 | } |