aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Controller
diff options
context:
space:
mode:
authorJeremy Benoist <jeremy.benoist@gmail.com>2018-10-12 21:41:05 +0200
committerJeremy Benoist <jeremy.benoist@gmail.com>2019-01-19 21:09:33 +0100
commit0447a75b06142afe59a179bb59ee94f1978aa7a9 (patch)
tree6fb21a4cef53c62cb7f2d703c0fb6957ce4de3cb /src/Wallabag/CoreBundle/Controller
parentf85d220c19872dd7e9199fd150060555584a2886 (diff)
downloadwallabag-0447a75b06142afe59a179bb59ee94f1978aa7a9.tar.gz
wallabag-0447a75b06142afe59a179bb59ee94f1978aa7a9.tar.zst
wallabag-0447a75b06142afe59a179bb59ee94f1978aa7a9.zip
Use only one method to randomize
Instead of one per type, one for all is ok.
Diffstat (limited to 'src/Wallabag/CoreBundle/Controller')
-rw-r--r--src/Wallabag/CoreBundle/Controller/EntryController.php97
1 files changed, 14 insertions, 83 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
249 } 249 }
250 250
251 /** 251 /**
252 * Shows random unread entry. 252 * Shows random entry depending on the given type.
253 * 253 *
254 * @param Entry $entry 254 * @param Entry $entry
255 * 255 *
256 * @Route("/unread/random", name="unread_random") 256 * @Route("/{type}/random", name="random_entry", requirements={"_locale": "unread|starred|archive|untagged|all"})
257 * 257 *
258 * @return \Symfony\Component\HttpFoundation\Response 258 * @return \Symfony\Component\HttpFoundation\RedirectResponse
259 */
260 public function showRandomUnreadEntryAction()
261 {
262 return $this->showRandomEntries('unread');
263 }
264
265 /**
266 * Shows random favorite entry.
267 *
268 * @param Entry $entry
269 *
270 * @Route("/starred/random", name="starred_random")
271 *
272 * @return \Symfony\Component\HttpFoundation\Response
273 */
274 public function showRandomStarredEntryAction()
275 {
276 return $this->showRandomEntries('starred');
277 }
278
279 /**
280 * Shows random archived entry.
281 *
282 * @param Entry $entry
283 *
284 * @Route("/archive/random", name="archive_random")
285 *
286 * @return \Symfony\Component\HttpFoundation\Response
287 */ 259 */
288 public function showRandomArchiveEntryAction() 260 public function redirectRandomEntryAction($type = 'all')
289 { 261 {
290 return $this->showRandomEntries('archive'); 262 try {
291 } 263 $entry = $this->get('wallabag_core.entry_repository')
264 ->getRandomEntry($this->getUser()->getId(), $type);
265 } catch (NoResultException $e) {
266 $bag = $this->get('session')->getFlashBag();
267 $bag->clear();
268 $bag->add('notice', 'flashes.entry.notice.no_random_entry');
292 269
293 /** 270 return $this->redirect($this->generateUrl('homepage'));
294 * Shows random all entry. 271 }
295 *
296 * @param Entry $entry
297 *
298 * @Route("/untagged/random", name="untagged_random")
299 *
300 * @return \Symfony\Component\HttpFoundation\Response
301 */
302 public function showRandomUntaggedEntryAction()
303 {
304 return $this->showRandomEntries('untagged');
305 }
306 272
307 /** 273 return $this->redirect($this->generateUrl('view', ['id' => $entry->getId()]));
308 * Shows random all entry.
309 *
310 * @param Entry $entry
311 *
312 * @Route("/all/random", name="all_random")
313 *
314 * @return \Symfony\Component\HttpFoundation\Response
315 */
316 public function showRandomAllEntryAction()
317 {
318 return $this->showRandomEntries();
319 } 274 }
320 275
321 /** 276 /**
@@ -624,30 +579,6 @@ class EntryController extends Controller
624 } 579 }
625 580
626 /** 581 /**
627 * Global method to retrieve random entries depending on the given type.
628 *
629 * @param string $type Entries type: unread, starred, archive or untagged
630 *
631 * @return \Symfony\Component\HttpFoundation\RedirectResponse
632 */
633 private function showRandomEntries($type)
634 {
635 $repository = $this->get('wallabag_core.entry_repository');
636
637 try {
638 $entry = $repository->getRandomEntry($this->getUser()->getId(), $type);
639 } catch (NoResultException $e) {
640 $bag = $this->get('session')->getFlashBag();
641 $bag->clear();
642 $bag->add('notice', 'flashes.entry.notice.no_random_entry');
643
644 return $this->redirect($this->generateUrl('homepage'));
645 }
646
647 return $this->redirect($this->generateUrl('view', ['id' => $entry->getId()]));
648 }
649
650 /**
651 * Fetch content and update entry. 582 * Fetch content and update entry.
652 * In case it fails, $entry->getContent will return an error message. 583 * In case it fails, $entry->getContent will return an error message.
653 * 584 *