aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Repository/EntryRepository.php
diff options
context:
space:
mode:
authorJeremy <jeremy.benoist@gmail.com>2015-02-08 23:05:51 +0100
committerJeremy <jeremy.benoist@gmail.com>2015-02-08 23:13:40 +0100
commit3b815d2de5a852fe2ebad5827bd4c9070aa175ea (patch)
tree504e54ecfd8ae6203f76a19a910e5e6c5dee1c3e /src/Wallabag/CoreBundle/Repository/EntryRepository.php
parentd91691573f108422cc2080462af35ebd62dc93fb (diff)
downloadwallabag-3b815d2de5a852fe2ebad5827bd4c9070aa175ea.tar.gz
wallabag-3b815d2de5a852fe2ebad5827bd4c9070aa175ea.tar.zst
wallabag-3b815d2de5a852fe2ebad5827bd4c9070aa175ea.zip
Add some fixtures
Improve test, so user can login Fix some leftJoin Cleanup EntryController
Diffstat (limited to 'src/Wallabag/CoreBundle/Repository/EntryRepository.php')
-rw-r--r--src/Wallabag/CoreBundle/Repository/EntryRepository.php63
1 files changed, 40 insertions, 23 deletions
diff --git a/src/Wallabag/CoreBundle/Repository/EntryRepository.php b/src/Wallabag/CoreBundle/Repository/EntryRepository.php
index f4c803f9..5ae1337a 100644
--- a/src/Wallabag/CoreBundle/Repository/EntryRepository.php
+++ b/src/Wallabag/CoreBundle/Repository/EntryRepository.php
@@ -11,19 +11,20 @@ class EntryRepository extends EntityRepository
11 /** 11 /**
12 * Retrieves unread entries for a user 12 * Retrieves unread entries for a user
13 * 13 *
14 * @param $userId 14 * @param int $userId
15 * @param $firstResult 15 * @param int $firstResult
16 * @param int $maxResults 16 * @param int $maxResults
17 *
17 * @return Paginator 18 * @return Paginator
18 */ 19 */
19 public function findUnreadByUser($userId, $firstResult, $maxResults = 12) 20 public function findUnreadByUser($userId, $firstResult, $maxResults = 12)
20 { 21 {
21 $qb = $this->createQueryBuilder('e') 22 $qb = $this->createQueryBuilder('e')
22 ->select('e')
23 ->setFirstResult($firstResult) 23 ->setFirstResult($firstResult)
24 ->setMaxResults($maxResults) 24 ->setMaxResults($maxResults)
25 ->leftJoin('e.user', 'u')
25 ->where('e.isArchived = false') 26 ->where('e.isArchived = false')
26 ->andWhere('e.userId =:userId')->setParameter('userId', $userId) 27 ->andWhere('u.id =:userId')->setParameter('userId', $userId)
27 ->andWhere('e.isDeleted=false') 28 ->andWhere('e.isDeleted=false')
28 ->orderBy('e.createdAt', 'desc') 29 ->orderBy('e.createdAt', 'desc')
29 ->getQuery(); 30 ->getQuery();
@@ -36,9 +37,10 @@ class EntryRepository extends EntityRepository
36 /** 37 /**
37 * Retrieves read entries for a user 38 * Retrieves read entries for a user
38 * 39 *
39 * @param $userId 40 * @param int $userId
40 * @param $firstResult 41 * @param int $firstResult
41 * @param int $maxResults 42 * @param int $maxResults
43 *
42 * @return Paginator 44 * @return Paginator
43 */ 45 */
44 public function findArchiveByUser($userId, $firstResult, $maxResults = 12) 46 public function findArchiveByUser($userId, $firstResult, $maxResults = 12)
@@ -47,8 +49,9 @@ class EntryRepository extends EntityRepository
47 ->select('e') 49 ->select('e')
48 ->setFirstResult($firstResult) 50 ->setFirstResult($firstResult)
49 ->setMaxResults($maxResults) 51 ->setMaxResults($maxResults)
52 ->leftJoin('e.user', 'u')
50 ->where('e.isArchived = true') 53 ->where('e.isArchived = true')
51 ->andWhere('e.userId =:userId')->setParameter('userId', $userId) 54 ->andWhere('u.id =:userId')->setParameter('userId', $userId)
52 ->andWhere('e.isDeleted=false') 55 ->andWhere('e.isDeleted=false')
53 ->orderBy('e.createdAt', 'desc') 56 ->orderBy('e.createdAt', 'desc')
54 ->getQuery(); 57 ->getQuery();
@@ -61,9 +64,10 @@ class EntryRepository extends EntityRepository
61 /** 64 /**
62 * Retrieves starred entries for a user 65 * Retrieves starred entries for a user
63 * 66 *
64 * @param $userId 67 * @param int $userId
65 * @param $firstResult 68 * @param int $firstResult
66 * @param int $maxResults 69 * @param int $maxResults
70 *
67 * @return Paginator 71 * @return Paginator
68 */ 72 */
69 public function findStarredByUser($userId, $firstResult, $maxResults = 12) 73 public function findStarredByUser($userId, $firstResult, $maxResults = 12)
@@ -72,9 +76,10 @@ class EntryRepository extends EntityRepository
72 ->select('e') 76 ->select('e')
73 ->setFirstResult($firstResult) 77 ->setFirstResult($firstResult)
74 ->setMaxResults($maxResults) 78 ->setMaxResults($maxResults)
79 ->leftJoin('e.user', 'u')
75 ->where('e.isStarred = true') 80 ->where('e.isStarred = true')
76 ->andWhere('e.userId =:userId')->setParameter('userId', $userId) 81 ->andWhere('u.id =:userId')->setParameter('userId', $userId)
77 ->andWhere('e.isDeleted=false') 82 ->andWhere('e.isDeleted = false')
78 ->orderBy('e.createdAt', 'desc') 83 ->orderBy('e.createdAt', 'desc')
79 ->getQuery(); 84 ->getQuery();
80 85
@@ -83,22 +88,34 @@ class EntryRepository extends EntityRepository
83 return $paginator; 88 return $paginator;
84 } 89 }
85 90
86 public function findEntries($userId, $isArchived, $isStarred, $isDeleted, $sort, $order) 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 ArrayCollection
102 */
103 public function findEntries($userId, $isArchived = null, $isStarred = null, $isDeleted = null, $sort = 'created', $order = 'ASC')
87 { 104 {
88 $qb = $this->createQueryBuilder('e') 105 $qb = $this->createQueryBuilder('e')
89 ->select('e') 106 ->leftJoin('e.user', 'u')
90 ->where('e.userId =:userId')->setParameter('userId', $userId); 107 ->where('u.id =:userId')->setParameter('userId', $userId);
91 108
92 if (!is_null($isArchived)) { 109 if (null !== $isArchived) {
93 $qb->andWhere('e.isArchived =:isArchived')->setParameter('isArchived', $isArchived); 110 $qb->andWhere('e.isArchived =:isArchived')->setParameter('isArchived', (bool) $isArchived);
94 } 111 }
95 112
96 if (!is_null($isStarred)) { 113 if (null !== $isStarred) {
97 $qb->andWhere('e.isStarred =:isStarred')->setParameter('isStarred', $isStarred); 114 $qb->andWhere('e.isStarred =:isStarred')->setParameter('isStarred', (bool) $isStarred);
98 } 115 }
99 116
100 if (!is_null($isDeleted)) { 117 if (null !== $isDeleted) {
101 $qb->andWhere('e.isDeleted =:isDeleted')->setParameter('isDeleted', $isDeleted); 118 $qb->andWhere('e.isDeleted =:isDeleted')->setParameter('isDeleted', (bool) $isDeleted);
102 } 119 }
103 120
104 if ('created' === $sort) { 121 if ('created' === $sort) {