diff options
Diffstat (limited to 'src/Wallabag/CoreBundle/Repository/EntryRepository.php')
-rw-r--r-- | src/Wallabag/CoreBundle/Repository/EntryRepository.php | 51 |
1 files changed, 47 insertions, 4 deletions
diff --git a/src/Wallabag/CoreBundle/Repository/EntryRepository.php b/src/Wallabag/CoreBundle/Repository/EntryRepository.php index 4071301d..9bda4e15 100644 --- a/src/Wallabag/CoreBundle/Repository/EntryRepository.php +++ b/src/Wallabag/CoreBundle/Repository/EntryRepository.php | |||
@@ -135,6 +135,7 @@ class EntryRepository extends EntityRepository | |||
135 | * @param int $userId | 135 | * @param int $userId |
136 | * @param bool $isArchived | 136 | * @param bool $isArchived |
137 | * @param bool $isStarred | 137 | * @param bool $isStarred |
138 | * @param bool $isPublic | ||
138 | * @param string $sort | 139 | * @param string $sort |
139 | * @param string $order | 140 | * @param string $order |
140 | * @param int $since | 141 | * @param int $since |
@@ -142,18 +143,22 @@ class EntryRepository extends EntityRepository | |||
142 | * | 143 | * |
143 | * @return array | 144 | * @return array |
144 | */ | 145 | */ |
145 | public function findEntries($userId, $isArchived = null, $isStarred = null, $sort = 'created', $order = 'ASC', $since = 0, $tags = '') | 146 | public function findEntries($userId, $isArchived = null, $isStarred = null, $isPublic = null, $sort = 'created', $order = 'ASC', $since = 0, $tags = '') |
146 | { | 147 | { |
147 | $qb = $this->createQueryBuilder('e') | 148 | $qb = $this->createQueryBuilder('e') |
148 | ->leftJoin('e.tags', 't') | 149 | ->leftJoin('e.tags', 't') |
149 | ->where('e.user =:userId')->setParameter('userId', $userId); | 150 | ->where('e.user =:userId')->setParameter('userId', $userId); |
150 | 151 | ||
151 | if (null !== $isArchived) { | 152 | if (null !== $isArchived) { |
152 | $qb->andWhere('e.isArchived =:isArchived')->setParameter('isArchived', (bool) $isArchived); | 153 | $qb->andWhere('e.isArchived = :isArchived')->setParameter('isArchived', (bool) $isArchived); |
153 | } | 154 | } |
154 | 155 | ||
155 | if (null !== $isStarred) { | 156 | if (null !== $isStarred) { |
156 | $qb->andWhere('e.isStarred =:isStarred')->setParameter('isStarred', (bool) $isStarred); | 157 | $qb->andWhere('e.isStarred = :isStarred')->setParameter('isStarred', (bool) $isStarred); |
158 | } | ||
159 | |||
160 | if (null !== $isPublic) { | ||
161 | $qb->andWhere('e.uid IS '.(true === $isPublic ? 'NOT' : '').' NULL'); | ||
157 | } | 162 | } |
158 | 163 | ||
159 | if ($since > 0) { | 164 | if ($since > 0) { |
@@ -328,7 +333,7 @@ class EntryRepository extends EntityRepository | |||
328 | * | 333 | * |
329 | * @return int | 334 | * @return int |
330 | */ | 335 | */ |
331 | public function countAllEntriesByUsername($userId) | 336 | public function countAllEntriesByUser($userId) |
332 | { | 337 | { |
333 | $qb = $this->createQueryBuilder('e') | 338 | $qb = $this->createQueryBuilder('e') |
334 | ->select('count(e)') | 339 | ->select('count(e)') |
@@ -371,4 +376,42 @@ class EntryRepository extends EntityRepository | |||
371 | ->setParameter('userId', $userId) | 376 | ->setParameter('userId', $userId) |
372 | ->execute(); | 377 | ->execute(); |
373 | } | 378 | } |
379 | |||
380 | public function removeArchivedByUserId($userId) | ||
381 | { | ||
382 | $this->getEntityManager() | ||
383 | ->createQuery('DELETE FROM Wallabag\CoreBundle\Entity\Entry e WHERE e.user = :userId AND e.isArchived = TRUE') | ||
384 | ->setParameter('userId', $userId) | ||
385 | ->execute(); | ||
386 | } | ||
387 | |||
388 | /** | ||
389 | * Get id and url from all entries | ||
390 | * Used for the clean-duplicates command. | ||
391 | */ | ||
392 | public function getAllEntriesIdAndUrl($userId) | ||
393 | { | ||
394 | $qb = $this->createQueryBuilder('e') | ||
395 | ->select('e.id, e.url') | ||
396 | ->where('e.user = :userid')->setParameter(':userid', $userId); | ||
397 | |||
398 | return $qb->getQuery()->getArrayResult(); | ||
399 | } | ||
400 | |||
401 | /** | ||
402 | * Find all entries by url and owner. | ||
403 | * | ||
404 | * @param $url | ||
405 | * @param $userId | ||
406 | * | ||
407 | * @return array | ||
408 | */ | ||
409 | public function findAllByUrlAndUserId($url, $userId) | ||
410 | { | ||
411 | return $this->createQueryBuilder('e') | ||
412 | ->where('e.url = :url')->setParameter('url', urldecode($url)) | ||
413 | ->andWhere('e.user = :user_id')->setParameter('user_id', $userId) | ||
414 | ->getQuery() | ||
415 | ->getResult(); | ||
416 | } | ||
374 | } | 417 | } |