From 0447a75b06142afe59a179bb59ee94f1978aa7a9 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Fri, 12 Oct 2018 21:41:05 +0200 Subject: [PATCH] Use only one method to randomize Instead of one per type, one for all is ok. --- .../CoreBundle/Controller/EntryController.php | 97 +++---------------- .../themes/baggy/Entry/entries.html.twig | 2 +- .../themes/material/Entry/entries.html.twig | 2 +- .../Controller/EntryControllerTest.php | 26 +++++ 4 files changed, 42 insertions(+), 85 deletions(-) diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php index 669e15d7..ab50ebdf 100644 --- a/src/Wallabag/CoreBundle/Controller/EntryController.php +++ b/src/Wallabag/CoreBundle/Controller/EntryController.php @@ -249,73 +249,28 @@ class EntryController extends Controller } /** - * Shows random unread entry. + * Shows random entry depending on the given type. * * @param Entry $entry * - * @Route("/unread/random", name="unread_random") + * @Route("/{type}/random", name="random_entry", requirements={"_locale": "unread|starred|archive|untagged|all"}) * - * @return \Symfony\Component\HttpFoundation\Response - */ - public function showRandomUnreadEntryAction() - { - return $this->showRandomEntries('unread'); - } - - /** - * Shows random favorite entry. - * - * @param Entry $entry - * - * @Route("/starred/random", name="starred_random") - * - * @return \Symfony\Component\HttpFoundation\Response - */ - public function showRandomStarredEntryAction() - { - return $this->showRandomEntries('starred'); - } - - /** - * Shows random archived entry. - * - * @param Entry $entry - * - * @Route("/archive/random", name="archive_random") - * - * @return \Symfony\Component\HttpFoundation\Response + * @return \Symfony\Component\HttpFoundation\RedirectResponse */ - public function showRandomArchiveEntryAction() + public function redirectRandomEntryAction($type = 'all') { - return $this->showRandomEntries('archive'); - } + try { + $entry = $this->get('wallabag_core.entry_repository') + ->getRandomEntry($this->getUser()->getId(), $type); + } catch (NoResultException $e) { + $bag = $this->get('session')->getFlashBag(); + $bag->clear(); + $bag->add('notice', 'flashes.entry.notice.no_random_entry'); - /** - * Shows random all entry. - * - * @param Entry $entry - * - * @Route("/untagged/random", name="untagged_random") - * - * @return \Symfony\Component\HttpFoundation\Response - */ - public function showRandomUntaggedEntryAction() - { - return $this->showRandomEntries('untagged'); - } + return $this->redirect($this->generateUrl('homepage')); + } - /** - * Shows random all entry. - * - * @param Entry $entry - * - * @Route("/all/random", name="all_random") - * - * @return \Symfony\Component\HttpFoundation\Response - */ - public function showRandomAllEntryAction() - { - return $this->showRandomEntries(); + return $this->redirect($this->generateUrl('view', ['id' => $entry->getId()])); } /** @@ -623,30 +578,6 @@ class EntryController extends Controller ); } - /** - * Global method to retrieve random entries depending on the given type. - * - * @param string $type Entries type: unread, starred, archive or untagged - * - * @return \Symfony\Component\HttpFoundation\RedirectResponse - */ - private function showRandomEntries($type) - { - $repository = $this->get('wallabag_core.entry_repository'); - - try { - $entry = $repository->getRandomEntry($this->getUser()->getId(), $type); - } 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()])); - } - /** * Fetch content and update entry. * In case it fails, $entry->getContent will return an error message. diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Entry/entries.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Entry/entries.html.twig index 7108efbd..f3baae2c 100644 --- a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Entry/entries.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Entry/entries.html.twig @@ -28,7 +28,7 @@
{{ 'entry.list.number_on_the_page'|transchoice(entries.count) }}