X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FWallabag%2FCoreBundle%2FController%2FEntryController.php;h=6c843ba7a8991039e67b1a2b7159dcbfe64cbcf1;hb=09ef25c3c3882db94b3941f3ba33ebc78b5dbe4d;hp=ac372a333594f20a48c925d95272130ee96b7d5c;hpb=c73025ad8b684de1ac21ba7583f1af6f1d185159;p=github%2Fwallabag%2Fwallabag.git diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php index ac372a33..6c843ba7 100644 --- a/src/Wallabag/CoreBundle/Controller/EntryController.php +++ b/src/Wallabag/CoreBundle/Controller/EntryController.php @@ -2,6 +2,7 @@ namespace Wallabag\CoreBundle\Controller; +use Doctrine\ORM\NoResultException; use Pagerfanta\Adapter\DoctrineORMAdapter; use Pagerfanta\Exception\OutOfRangeCurrentPageException; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache; @@ -232,6 +233,110 @@ class EntryController extends Controller return $this->showEntries('starred', $request, $page); } + /** + * Shows random unread entry. + * + * @param Entry $entry + * + * @Route("/unread/random", name="unread_random") + * + * @return \Symfony\Component\HttpFoundation\Response + */ + public function showRandomUnreadEntryAction() + { + $repository = $this->get('wallabag_core.entry_repository'); + + try { + $entry = $repository->getRandomEntry($this->getUser()->getId(), 'unread'); + } catch (NoResultException $e) { + $bag = $this->get('session')->getFlashBag(); + $bag->clear(); + $bag->add('notice', 'flashes.entry.notice.no_random_entry'); + + return $this->redirect($this->generateUrl('homepage')); + } + + return $this->redirect($this->generateUrl('view', ['id' => $entry->getId()])); + } + + /** + * Shows random favorite entry. + * + * @param Entry $entry + * + * @Route("/starred/random", name="starred_random") + * + * @return \Symfony\Component\HttpFoundation\Response + */ + public function showRandomStarredEntryAction() + { + $repository = $this->get('wallabag_core.entry_repository'); + + try { + $entry = $repository->getRandomEntry($this->getUser()->getId(), 'starred'); + } catch (NoResultException $e) { + $bag = $this->get('session')->getFlashBag(); + $bag->clear(); + $bag->add('notice', 'flashes.entry.notice.no_random_entry'); + + return $this->redirect($this->generateUrl('homepage')); + } + + return $this->redirect($this->generateUrl('view', ['id' => $entry->getId()])); + } + + /** + * Shows random archived entry. + * + * @param Entry $entry + * + * @Route("/archive/random", name="archive_random") + * + * @return \Symfony\Component\HttpFoundation\Response + */ + public function showRandomArchiveEntryAction() + { + $repository = $this->get('wallabag_core.entry_repository'); + + try { + $entry = $repository->getRandomEntry($this->getUser()->getId(), 'starred'); + } catch (NoResultException $e) { + $bag = $this->get('session')->getFlashBag(); + $bag->clear(); + $bag->add('notice', 'flashes.entry.notice.no_random_entry'); + + return $this->redirect($this->generateUrl('homepage')); + } + + return $this->redirect($this->generateUrl('view', ['id' => $entry->getId()])); + } + + /** + * Shows random all entry. + * + * @param Entry $entry + * + * @Route("/all/random", name="all_random") + * + * @return \Symfony\Component\HttpFoundation\Response + */ + public function showRandomAllEntryAction() + { + $repository = $this->get('wallabag_core.entry_repository'); + + try { + $entry = $repository->getRandomEntry($this->getUser()->getId()); + } catch (NoResultException $e) { + $bag = $this->get('session')->getFlashBag(); + $bag->clear(); + $bag->add('notice', 'flashes.entry.notice.no_random_entry'); + + return $this->redirect($this->generateUrl('homepage')); + } + + return $this->redirect($this->generateUrl('view', ['id' => $entry->getId()])); + } + /** * Shows entry content. *