]> git.immae.eu Git - github/wallabag/wallabag.git/blame - src/Wallabag/CoreBundle/Repository/EntriesRepository.php
implement delete method
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Repository / EntriesRepository.php
CommitLineData
9d50517c
NL
1<?php
2
ad4d1caa 3namespace Wallabag\CoreBundle\Repository;
9d50517c
NL
4
5use Doctrine\ORM\Query;
6use Doctrine\ORM\EntityRepository;
163eae0b 7use Doctrine\ORM\Tools\Pagination\Paginator;
c3235553 8use Wallabag\CoreBundle\Entity\Entries;
9d50517c 9
9d50517c
NL
10class 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)
42a90646 28 ->andWhere('e.isDeleted=0')
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
7df80cb3 41 * @param int $maxResults
b84a8055
NL
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)
42a90646 52 ->andWhere('e.isDeleted=0')
b84a8055
NL
53 ->getQuery();
54
55 $paginator = new Paginator($qb);
bd9f0815 56
b84a8055 57 return $paginator;
bd9f0815
NL
58 }
59
b84a8055
NL
60 /**
61 * Retrieves starred entries for a user
62 *
63 * @param $userId
64 * @param $firstResult
7df80cb3 65 * @param int $maxResults
b84a8055
NL
66 * @return Paginator
67 */
163eae0b 68 public function findStarredByUser($userId, $firstResult, $maxResults = 12)
bd9f0815
NL
69 {
70 $qb = $this->createQueryBuilder('e')
71 ->select('e')
163eae0b
NL
72 ->setFirstResult($firstResult)
73 ->setMaxResults($maxResults)
bd9f0815
NL
74 ->where('e.isFav = 1')
75 ->andWhere('e.userId =:userId')->setParameter('userId', $userId)
42a90646 76 ->andWhere('e.isDeleted=0')
b84a8055
NL
77 ->getQuery();
78
79 $paginator = new Paginator($qb);
bd9f0815 80
b84a8055 81 return $paginator;
bd9f0815 82 }
a8c90c5c
NL
83
84 public function findEntries($userId, $isArchived, $isStarred, $isDeleted, $sort, $order)
85 {
c3235553 86 //TODO tous les paramètres ne sont pas utilisés, à corriger
a8c90c5c
NL
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)
42a90646 92 ->andWhere('e.isDeleted=0')
a8c90c5c
NL
93 ->getQuery()
94 ->getResult(Query::HYDRATE_ARRAY);
95
96 return $qb;
97 }
9d50517c 98}