3 namespace Wallabag\CoreBundle\Repository
;
5 use Doctrine\ORM\Query
;
6 use Doctrine\ORM\EntityRepository
;
7 use Doctrine\ORM\Tools\Pagination\Paginator
;
8 use Wallabag\CoreBundle\Entity\Entries
;
10 class EntriesRepository
extends EntityRepository
13 * Retrieves unread entries for a user
17 * @param int $maxResults
20 public function findUnreadByUser($userId, $firstResult, $maxResults = 12)
22 $qb = $this->createQueryBuilder('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')
31 $paginator = new Paginator($qb);
37 * Retrieves read entries for a user
41 * @param int $maxResults
44 public function findArchiveByUser($userId, $firstResult, $maxResults = 12)
46 $qb = $this->createQueryBuilder('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')
55 $paginator = new Paginator($qb);
61 * Retrieves starred entries for a user
65 * @param int $maxResults
68 public function findStarredByUser($userId, $firstResult, $maxResults = 12)
70 $qb = $this->createQueryBuilder('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')
79 $paginator = new Paginator($qb);
84 public function findEntries($userId, $isArchived, $isStarred, $isDeleted, $sort, $order)
86 //TODO tous les paramètres ne sont pas utilisés, à corriger
87 $qb = $this->createQueryBuilder('e')
89 ->where('e.userId =:userId')->setParameter('userId', $userId)
90 ->andWhere('e.isDeleted=0');
92 if (!is_null($isArchived)) {
93 $qb->andWhere('e.isRead =:isArchived')->setParameter('isArchived', $isArchived);
96 if (!is_null($isStarred)) {
97 $qb->andWhere('e.isFav =:isStarred')->setParameter('isStarred', $isStarred);
102 ->getResult(Query
::HYDRATE_ARRAY
);