diff options
Diffstat (limited to 'src/Wallabag/CoreBundle/Repository/EntryRepository.php')
-rw-r--r-- | src/Wallabag/CoreBundle/Repository/EntryRepository.php | 38 |
1 files changed, 24 insertions, 14 deletions
diff --git a/src/Wallabag/CoreBundle/Repository/EntryRepository.php b/src/Wallabag/CoreBundle/Repository/EntryRepository.php index bedc90d2..53e8e2ba 100644 --- a/src/Wallabag/CoreBundle/Repository/EntryRepository.php +++ b/src/Wallabag/CoreBundle/Repository/EntryRepository.php | |||
@@ -4,6 +4,8 @@ namespace Wallabag\CoreBundle\Repository; | |||
4 | 4 | ||
5 | use Doctrine\ORM\EntityRepository; | 5 | use Doctrine\ORM\EntityRepository; |
6 | use Doctrine\ORM\Tools\Pagination\Paginator; | 6 | use Doctrine\ORM\Tools\Pagination\Paginator; |
7 | use Pagerfanta\Adapter\DoctrineORMAdapter; | ||
8 | use Pagerfanta\Pagerfanta; | ||
7 | 9 | ||
8 | class EntryRepository extends EntityRepository | 10 | class EntryRepository extends EntityRepository |
9 | { | 11 | { |
@@ -24,7 +26,6 @@ class EntryRepository extends EntityRepository | |||
24 | ->leftJoin('e.user', 'u') | 26 | ->leftJoin('e.user', 'u') |
25 | ->where('e.isArchived = false') | 27 | ->where('e.isArchived = false') |
26 | ->andWhere('u.id =:userId')->setParameter('userId', $userId) | 28 | ->andWhere('u.id =:userId')->setParameter('userId', $userId) |
27 | ->andWhere('e.isDeleted=false') | ||
28 | ->orderBy('e.createdAt', 'desc') | 29 | ->orderBy('e.createdAt', 'desc') |
29 | ->getQuery(); | 30 | ->getQuery(); |
30 | 31 | ||
@@ -51,7 +52,6 @@ class EntryRepository extends EntityRepository | |||
51 | ->leftJoin('e.user', 'u') | 52 | ->leftJoin('e.user', 'u') |
52 | ->where('e.isArchived = true') | 53 | ->where('e.isArchived = true') |
53 | ->andWhere('u.id =:userId')->setParameter('userId', $userId) | 54 | ->andWhere('u.id =:userId')->setParameter('userId', $userId) |
54 | ->andWhere('e.isDeleted=false') | ||
55 | ->orderBy('e.createdAt', 'desc') | 55 | ->orderBy('e.createdAt', 'desc') |
56 | ->getQuery(); | 56 | ->getQuery(); |
57 | 57 | ||
@@ -78,7 +78,6 @@ class EntryRepository extends EntityRepository | |||
78 | ->leftJoin('e.user', 'u') | 78 | ->leftJoin('e.user', 'u') |
79 | ->where('e.isStarred = true') | 79 | ->where('e.isStarred = true') |
80 | ->andWhere('u.id =:userId')->setParameter('userId', $userId) | 80 | ->andWhere('u.id =:userId')->setParameter('userId', $userId) |
81 | ->andWhere('e.isDeleted = false') | ||
82 | ->orderBy('e.createdAt', 'desc') | 81 | ->orderBy('e.createdAt', 'desc') |
83 | ->getQuery(); | 82 | ->getQuery(); |
84 | 83 | ||
@@ -93,17 +92,15 @@ class EntryRepository extends EntityRepository | |||
93 | * @param int $userId | 92 | * @param int $userId |
94 | * @param bool $isArchived | 93 | * @param bool $isArchived |
95 | * @param bool $isStarred | 94 | * @param bool $isStarred |
96 | * @param bool $isDeleted | ||
97 | * @param string $sort | 95 | * @param string $sort |
98 | * @param string $order | 96 | * @param string $order |
99 | * | 97 | * |
100 | * @return array | 98 | * @return array |
101 | */ | 99 | */ |
102 | public function findEntries($userId, $isArchived = null, $isStarred = null, $isDeleted = null, $sort = 'created', $order = 'ASC') | 100 | public function findEntries($userId, $isArchived = null, $isStarred = null, $sort = 'created', $order = 'ASC') |
103 | { | 101 | { |
104 | $qb = $this->createQueryBuilder('e') | 102 | $qb = $this->createQueryBuilder('e') |
105 | ->leftJoin('e.user', 'u') | 103 | ->where('e.user =:userId')->setParameter('userId', $userId); |
106 | ->where('u.id =:userId')->setParameter('userId', $userId); | ||
107 | 104 | ||
108 | if (null !== $isArchived) { | 105 | if (null !== $isArchived) { |
109 | $qb->andWhere('e.isArchived =:isArchived')->setParameter('isArchived', (bool) $isArchived); | 106 | $qb->andWhere('e.isArchived =:isArchived')->setParameter('isArchived', (bool) $isArchived); |
@@ -113,18 +110,31 @@ class EntryRepository extends EntityRepository | |||
113 | $qb->andWhere('e.isStarred =:isStarred')->setParameter('isStarred', (bool) $isStarred); | 110 | $qb->andWhere('e.isStarred =:isStarred')->setParameter('isStarred', (bool) $isStarred); |
114 | } | 111 | } |
115 | 112 | ||
116 | if (null !== $isDeleted) { | ||
117 | $qb->andWhere('e.isDeleted =:isDeleted')->setParameter('isDeleted', (bool) $isDeleted); | ||
118 | } | ||
119 | |||
120 | if ('created' === $sort) { | 113 | if ('created' === $sort) { |
121 | $qb->orderBy('e.createdAt', $order); | 114 | $qb->orderBy('e.createdAt', $order); |
122 | } elseif ('updated' === $sort) { | 115 | } elseif ('updated' === $sort) { |
123 | $qb->orderBy('e.updatedAt', $order); | 116 | $qb->orderBy('e.updatedAt', $order); |
124 | } | 117 | } |
125 | 118 | ||
126 | return $qb | 119 | $pagerAdapter = new DoctrineORMAdapter($qb); |
127 | ->getQuery() | 120 | |
128 | ->getResult(); | 121 | return new Pagerfanta($pagerAdapter); |
122 | } | ||
123 | |||
124 | /** | ||
125 | * Fetch an entry with a tag. Only used for tests. | ||
126 | * | ||
127 | * @return Entry | ||
128 | */ | ||
129 | public function findOneWithTags($userId) | ||
130 | { | ||
131 | $qb = $this->createQueryBuilder('e') | ||
132 | ->innerJoin('e.tags', 't') | ||
133 | ->innerJoin('e.user', 'u') | ||
134 | ->addSelect('t', 'u') | ||
135 | ->where('e.user=:userId')->setParameter('userId', $userId) | ||
136 | ; | ||
137 | |||
138 | return $qb->getQuery()->getResult(); | ||
129 | } | 139 | } |
130 | } | 140 | } |