aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag
diff options
context:
space:
mode:
Diffstat (limited to 'src/Wallabag')
-rw-r--r--src/Wallabag/CoreBundle/Controller/EntryController.php188
-rw-r--r--src/Wallabag/CoreBundle/Repository/EntryRepository.php5
2 files changed, 94 insertions, 99 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php
index 6c843ba7..669e15d7 100644
--- a/src/Wallabag/CoreBundle/Controller/EntryController.php
+++ b/src/Wallabag/CoreBundle/Controller/EntryController.php
@@ -234,6 +234,21 @@ class EntryController extends Controller
234 } 234 }
235 235
236 /** 236 /**
237 * Shows untagged articles for current user.
238 *
239 * @param Request $request
240 * @param int $page
241 *
242 * @Route("/untagged/list/{page}", name="untagged", defaults={"page" = "1"})
243 *
244 * @return \Symfony\Component\HttpFoundation\Response
245 */
246 public function showUntaggedEntriesAction(Request $request, $page)
247 {
248 return $this->showEntries('untagged', $request, $page);
249 }
250
251 /**
237 * Shows random unread entry. 252 * Shows random unread entry.
238 * 253 *
239 * @param Entry $entry 254 * @param Entry $entry
@@ -244,19 +259,7 @@ class EntryController extends Controller
244 */ 259 */
245 public function showRandomUnreadEntryAction() 260 public function showRandomUnreadEntryAction()
246 { 261 {
247 $repository = $this->get('wallabag_core.entry_repository'); 262 return $this->showRandomEntries('unread');
248
249 try {
250 $entry = $repository->getRandomEntry($this->getUser()->getId(), 'unread');
251 } catch (NoResultException $e) {
252 $bag = $this->get('session')->getFlashBag();
253 $bag->clear();
254 $bag->add('notice', 'flashes.entry.notice.no_random_entry');
255
256 return $this->redirect($this->generateUrl('homepage'));
257 }
258
259 return $this->redirect($this->generateUrl('view', ['id' => $entry->getId()]));
260 } 263 }
261 264
262 /** 265 /**
@@ -270,19 +273,7 @@ class EntryController extends Controller
270 */ 273 */
271 public function showRandomStarredEntryAction() 274 public function showRandomStarredEntryAction()
272 { 275 {
273 $repository = $this->get('wallabag_core.entry_repository'); 276 return $this->showRandomEntries('starred');
274
275 try {
276 $entry = $repository->getRandomEntry($this->getUser()->getId(), 'starred');
277 } catch (NoResultException $e) {
278 $bag = $this->get('session')->getFlashBag();
279 $bag->clear();
280 $bag->add('notice', 'flashes.entry.notice.no_random_entry');
281
282 return $this->redirect($this->generateUrl('homepage'));
283 }
284
285 return $this->redirect($this->generateUrl('view', ['id' => $entry->getId()]));
286 } 277 }
287 278
288 /** 279 /**
@@ -296,19 +287,21 @@ class EntryController extends Controller
296 */ 287 */
297 public function showRandomArchiveEntryAction() 288 public function showRandomArchiveEntryAction()
298 { 289 {
299 $repository = $this->get('wallabag_core.entry_repository'); 290 return $this->showRandomEntries('archive');
300 291 }
301 try {
302 $entry = $repository->getRandomEntry($this->getUser()->getId(), 'starred');
303 } catch (NoResultException $e) {
304 $bag = $this->get('session')->getFlashBag();
305 $bag->clear();
306 $bag->add('notice', 'flashes.entry.notice.no_random_entry');
307
308 return $this->redirect($this->generateUrl('homepage'));
309 }
310 292
311 return $this->redirect($this->generateUrl('view', ['id' => $entry->getId()])); 293 /**
294 * Shows random all entry.
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');
312 } 305 }
313 306
314 /** 307 /**
@@ -322,19 +315,7 @@ class EntryController extends Controller
322 */ 315 */
323 public function showRandomAllEntryAction() 316 public function showRandomAllEntryAction()
324 { 317 {
325 $repository = $this->get('wallabag_core.entry_repository'); 318 return $this->showRandomEntries();
326
327 try {
328 $entry = $repository->getRandomEntry($this->getUser()->getId());
329 } catch (NoResultException $e) {
330 $bag = $this->get('session')->getFlashBag();
331 $bag->clear();
332 $bag->add('notice', 'flashes.entry.notice.no_random_entry');
333
334 return $this->redirect($this->generateUrl('homepage'));
335 }
336
337 return $this->redirect($this->generateUrl('view', ['id' => $entry->getId()]));
338 } 319 }
339 320
340 /** 321 /**
@@ -571,54 +552,6 @@ class EntryController extends Controller
571 } 552 }
572 553
573 /** 554 /**
574 * Shows untagged articles for current user.
575 *
576 * @param Request $request
577 * @param int $page
578 *
579 * @Route("/untagged/list/{page}", name="untagged", defaults={"page" = "1"})
580 *
581 * @return \Symfony\Component\HttpFoundation\Response
582 */
583 public function showUntaggedEntriesAction(Request $request, $page)
584 {
585 return $this->showEntries('untagged', $request, $page);
586 }
587
588 /**
589 * Fetch content and update entry.
590 * In case it fails, $entry->getContent will return an error message.
591 *
592 * @param Entry $entry
593 * @param string $prefixMessage Should be the translation key: entry_saved or entry_reloaded
594 */
595 private function updateEntry(Entry $entry, $prefixMessage = 'entry_saved')
596 {
597 $message = 'flashes.entry.notice.' . $prefixMessage;
598
599 try {
600 $this->get('wallabag_core.content_proxy')->updateEntry($entry, $entry->getUrl());
601 } catch (\Exception $e) {
602 $this->get('logger')->error('Error while saving an entry', [
603 'exception' => $e,
604 'entry' => $entry,
605 ]);
606
607 $message = 'flashes.entry.notice.' . $prefixMessage . '_failed';
608 }
609
610 if (empty($entry->getDomainName())) {
611 $this->get('wallabag_core.content_proxy')->setEntryDomainName($entry);
612 }
613
614 if (empty($entry->getTitle())) {
615 $this->get('wallabag_core.content_proxy')->setDefaultEntryTitle($entry);
616 }
617
618 $this->get('session')->getFlashBag()->add('notice', $message);
619 }
620
621 /**
622 * Global method to retrieve entries depending on the given type 555 * Global method to retrieve entries depending on the given type
623 * It returns the response to be send. 556 * It returns the response to be send.
624 * 557 *
@@ -691,6 +624,63 @@ class EntryController extends Controller
691 } 624 }
692 625
693 /** 626 /**
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.
652 * In case it fails, $entry->getContent will return an error message.
653 *
654 * @param Entry $entry
655 * @param string $prefixMessage Should be the translation key: entry_saved or entry_reloaded
656 */
657 private function updateEntry(Entry $entry, $prefixMessage = 'entry_saved')
658 {
659 $message = 'flashes.entry.notice.' . $prefixMessage;
660
661 try {
662 $this->get('wallabag_core.content_proxy')->updateEntry($entry, $entry->getUrl());
663 } catch (\Exception $e) {
664 $this->get('logger')->error('Error while saving an entry', [
665 'exception' => $e,
666 'entry' => $entry,
667 ]);
668
669 $message = 'flashes.entry.notice.' . $prefixMessage . '_failed';
670 }
671
672 if (empty($entry->getDomainName())) {
673 $this->get('wallabag_core.content_proxy')->setEntryDomainName($entry);
674 }
675
676 if (empty($entry->getTitle())) {
677 $this->get('wallabag_core.content_proxy')->setDefaultEntryTitle($entry);
678 }
679
680 $this->get('session')->getFlashBag()->add('notice', $message);
681 }
682
683 /**
694 * Check if the logged user can manage the given entry. 684 * Check if the logged user can manage the given entry.
695 * 685 *
696 * @param Entry $entry 686 * @param Entry $entry
diff --git a/src/Wallabag/CoreBundle/Repository/EntryRepository.php b/src/Wallabag/CoreBundle/Repository/EntryRepository.php
index a26de0a8..6107e19e 100644
--- a/src/Wallabag/CoreBundle/Repository/EntryRepository.php
+++ b/src/Wallabag/CoreBundle/Repository/EntryRepository.php
@@ -464,6 +464,11 @@ class EntryRepository extends EntityRepository
464 $qb->andWhere('e.isStarred = true'); 464 $qb->andWhere('e.isStarred = true');
465 } 465 }
466 466
467 if ('untagged' === $status) {
468 $qb->leftJoin('e.tags', 't');
469 $qb->andWhere('t.id is null');
470 }
471
467 return $qb->andWhere('e.id >= :rand') 472 return $qb->andWhere('e.id >= :rand')
468 ->setParameter('rand', rand(0, $max)) 473 ->setParameter('rand', rand(0, $max))
469 ->setMaxResults(1) 474 ->setMaxResults(1)