]> git.immae.eu Git - github/wallabag/wallabag.git/blob - src/Wallabag/CoreBundle/Repository/EntryRepository.php
change phpdoc
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Repository / EntryRepository.php
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
9 class EntryRepository extends EntityRepository
10 {
11 /**
12 * Retrieves unread entries for a user
13 *
14 * @param int $userId
15 * @param int $firstResult
16 * @param int $maxResults
17 *
18 * @return Paginator
19 */
20 public function findUnreadByUser($userId, $firstResult, $maxResults = 12)
21 {
22 $qb = $this->createQueryBuilder('e')
23 ->setFirstResult($firstResult)
24 ->setMaxResults($maxResults)
25 ->leftJoin('e.user', 'u')
26 ->where('e.isArchived = false')
27 ->andWhere('u.id =:userId')->setParameter('userId', $userId)
28 ->andWhere('e.isDeleted=false')
29 ->orderBy('e.createdAt', 'desc')
30 ->getQuery();
31
32 $paginator = new Paginator($qb);
33
34 return $paginator;
35 }
36
37 /**
38 * Retrieves read entries for a user
39 *
40 * @param int $userId
41 * @param int $firstResult
42 * @param int $maxResults
43 *
44 * @return Paginator
45 */
46 public function findArchiveByUser($userId, $firstResult, $maxResults = 12)
47 {
48 $qb = $this->createQueryBuilder('e')
49 ->select('e')
50 ->setFirstResult($firstResult)
51 ->setMaxResults($maxResults)
52 ->leftJoin('e.user', 'u')
53 ->where('e.isArchived = true')
54 ->andWhere('u.id =:userId')->setParameter('userId', $userId)
55 ->andWhere('e.isDeleted=false')
56 ->orderBy('e.createdAt', 'desc')
57 ->getQuery();
58
59 $paginator = new Paginator($qb);
60
61 return $paginator;
62 }
63
64 /**
65 * Retrieves starred entries for a user
66 *
67 * @param int $userId
68 * @param int $firstResult
69 * @param int $maxResults
70 *
71 * @return Paginator
72 */
73 public function findStarredByUser($userId, $firstResult, $maxResults = 12)
74 {
75 $qb = $this->createQueryBuilder('e')
76 ->select('e')
77 ->setFirstResult($firstResult)
78 ->setMaxResults($maxResults)
79 ->leftJoin('e.user', 'u')
80 ->where('e.isStarred = true')
81 ->andWhere('u.id =:userId')->setParameter('userId', $userId)
82 ->andWhere('e.isDeleted = false')
83 ->orderBy('e.createdAt', 'desc')
84 ->getQuery();
85
86 $paginator = new Paginator($qb);
87
88 return $paginator;
89 }
90
91 /**
92 * Find Entries
93 *
94 * @param int $userId
95 * @param bool $isArchived
96 * @param bool $isStarred
97 * @param bool $isDeleted
98 * @param string $sort
99 * @param string $order
100 *
101 * @return Entry
102 */
103 public function findEntries($userId, $isArchived = null, $isStarred = null, $isDeleted = null, $sort = 'created', $order = 'ASC')
104 {
105 $qb = $this->createQueryBuilder('e')
106 ->leftJoin('e.user', 'u')
107 ->where('u.id =:userId')->setParameter('userId', $userId);
108
109 if (null !== $isArchived) {
110 $qb->andWhere('e.isArchived =:isArchived')->setParameter('isArchived', (bool) $isArchived);
111 }
112
113 if (null !== $isStarred) {
114 $qb->andWhere('e.isStarred =:isStarred')->setParameter('isStarred', (bool) $isStarred);
115 }
116
117 if (null !== $isDeleted) {
118 $qb->andWhere('e.isDeleted =:isDeleted')->setParameter('isDeleted', (bool) $isDeleted);
119 }
120
121 if ('created' === $sort) {
122 $qb->orderBy('e.createdAt', $order);
123 } elseif ('updated' === $sort) {
124 $qb->orderBy('e.updatedAt', $order);
125 }
126
127 return $qb
128 ->getQuery()
129 ->getResult();
130 }
131 }