aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/Wallabag/CoreBundle/Controller/EntryController.php4
-rw-r--r--src/Wallabag/CoreBundle/Repository/EntryRepository.php33
2 files changed, 18 insertions, 19 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php
index ab50ebdf..dfb5eb54 100644
--- a/src/Wallabag/CoreBundle/Controller/EntryController.php
+++ b/src/Wallabag/CoreBundle/Controller/EntryController.php
@@ -251,7 +251,7 @@ class EntryController extends Controller
251 /** 251 /**
252 * Shows random entry depending on the given type. 252 * Shows random entry depending on the given type.
253 * 253 *
254 * @param Entry $entry 254 * @param string $type
255 * 255 *
256 * @Route("/{type}/random", name="random_entry", requirements={"_locale": "unread|starred|archive|untagged|all"}) 256 * @Route("/{type}/random", name="random_entry", requirements={"_locale": "unread|starred|archive|untagged|all"})
257 * 257 *
@@ -267,7 +267,7 @@ class EntryController extends Controller
267 $bag->clear(); 267 $bag->clear();
268 $bag->add('notice', 'flashes.entry.notice.no_random_entry'); 268 $bag->add('notice', 'flashes.entry.notice.no_random_entry');
269 269
270 return $this->redirect($this->generateUrl('homepage')); 270 return $this->redirect($this->generateUrl($type));
271 } 271 }
272 272
273 return $this->redirect($this->generateUrl('view', ['id' => $entry->getId()])); 273 return $this->redirect($this->generateUrl('view', ['id' => $entry->getId()]));
diff --git a/src/Wallabag/CoreBundle/Repository/EntryRepository.php b/src/Wallabag/CoreBundle/Repository/EntryRepository.php
index 6941eaee..702646fe 100644
--- a/src/Wallabag/CoreBundle/Repository/EntryRepository.php
+++ b/src/Wallabag/CoreBundle/Repository/EntryRepository.php
@@ -431,7 +431,7 @@ class EntryRepository extends EntityRepository
431 * Returns a random entry, filtering by status. 431 * Returns a random entry, filtering by status.
432 * 432 *
433 * @param $userId 433 * @param $userId
434 * @param string $status can be unread, archive or starred 434 * @param string $type can be unread, archive, starred, etc
435 * 435 *
436 * @throws \Doctrine\ORM\NoResultException 436 * @throws \Doctrine\ORM\NoResultException
437 * @throws \Doctrine\ORM\NonUniqueResultException 437 * @throws \Doctrine\ORM\NonUniqueResultException
@@ -440,26 +440,25 @@ class EntryRepository extends EntityRepository
440 * 440 *
441 * @return Entry 441 * @return Entry
442 */ 442 */
443 public function getRandomEntry($userId, $status = '') 443 public function getRandomEntry($userId, $type = '')
444 { 444 {
445 $qb = $this->getQueryBuilderByUser($userId) 445 $qb = $this->getQueryBuilderByUser($userId)
446 ->select('MIN(e.id)', 'MAX(e.id)'); 446 ->select('MIN(e.id)', 'MAX(e.id)');
447 447
448 if ('unread' === $status) { 448 switch ($type) {
449 $qb->andWhere('e.isArchived = false'); 449 case 'unread':
450 } 450 $qb->andWhere('e.isArchived = false');
451 451 break;
452 if ('archive' === $status) { 452 case 'archive':
453 $qb->andWhere('e.isArchived = true'); 453 $qb->andWhere('e.isArchived = true');
454 } 454 break;
455 455 case 'starred':
456 if ('starred' === $status) { 456 $qb->andWhere('e.isStarred = true');
457 $qb->andWhere('e.isStarred = true'); 457 break;
458 } 458 case 'untagged':
459 459 $qb->leftJoin('e.tags', 't');
460 if ('untagged' === $status) { 460 $qb->andWhere('t.id is null');
461 $qb->leftJoin('e.tags', 't'); 461 break;
462 $qb->andWhere('t.id is null');
463 } 462 }
464 463
465 $idLimits = $qb 464 $idLimits = $qb