diff options
Diffstat (limited to 'src/Wallabag/CoreBundle/Controller/EntryController.php')
-rw-r--r-- | src/Wallabag/CoreBundle/Controller/EntryController.php | 122 |
1 files changed, 74 insertions, 48 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php index ac372a33..5c8ecb40 100644 --- a/src/Wallabag/CoreBundle/Controller/EntryController.php +++ b/src/Wallabag/CoreBundle/Controller/EntryController.php | |||
@@ -2,6 +2,7 @@ | |||
2 | 2 | ||
3 | namespace Wallabag\CoreBundle\Controller; | 3 | namespace Wallabag\CoreBundle\Controller; |
4 | 4 | ||
5 | use Doctrine\ORM\NoResultException; | ||
5 | use Pagerfanta\Adapter\DoctrineORMAdapter; | 6 | use Pagerfanta\Adapter\DoctrineORMAdapter; |
6 | use Pagerfanta\Exception\OutOfRangeCurrentPageException; | 7 | use Pagerfanta\Exception\OutOfRangeCurrentPageException; |
7 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache; | 8 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache; |
@@ -233,6 +234,46 @@ class EntryController extends Controller | |||
233 | } | 234 | } |
234 | 235 | ||
235 | /** | 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 | /** | ||
252 | * Shows random entry depending on the given type. | ||
253 | * | ||
254 | * @param string $type | ||
255 | * | ||
256 | * @Route("/{type}/random", name="random_entry", requirements={"type": "unread|starred|archive|untagged|all"}) | ||
257 | * | ||
258 | * @return \Symfony\Component\HttpFoundation\RedirectResponse | ||
259 | */ | ||
260 | public function redirectRandomEntryAction($type = 'all') | ||
261 | { | ||
262 | try { | ||
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'); | ||
269 | |||
270 | return $this->redirect($this->generateUrl($type)); | ||
271 | } | ||
272 | |||
273 | return $this->redirect($this->generateUrl('view', ['id' => $entry->getId()])); | ||
274 | } | ||
275 | |||
276 | /** | ||
236 | * Shows entry content. | 277 | * Shows entry content. |
237 | * | 278 | * |
238 | * @param Entry $entry | 279 | * @param Entry $entry |
@@ -466,54 +507,6 @@ class EntryController extends Controller | |||
466 | } | 507 | } |
467 | 508 | ||
468 | /** | 509 | /** |
469 | * Shows untagged articles for current user. | ||
470 | * | ||
471 | * @param Request $request | ||
472 | * @param int $page | ||
473 | * | ||
474 | * @Route("/untagged/list/{page}", name="untagged", defaults={"page" = "1"}) | ||
475 | * | ||
476 | * @return \Symfony\Component\HttpFoundation\Response | ||
477 | */ | ||
478 | public function showUntaggedEntriesAction(Request $request, $page) | ||
479 | { | ||
480 | return $this->showEntries('untagged', $request, $page); | ||
481 | } | ||
482 | |||
483 | /** | ||
484 | * Fetch content and update entry. | ||
485 | * In case it fails, $entry->getContent will return an error message. | ||
486 | * | ||
487 | * @param Entry $entry | ||
488 | * @param string $prefixMessage Should be the translation key: entry_saved or entry_reloaded | ||
489 | */ | ||
490 | private function updateEntry(Entry $entry, $prefixMessage = 'entry_saved') | ||
491 | { | ||
492 | $message = 'flashes.entry.notice.' . $prefixMessage; | ||
493 | |||
494 | try { | ||
495 | $this->get('wallabag_core.content_proxy')->updateEntry($entry, $entry->getUrl()); | ||
496 | } catch (\Exception $e) { | ||
497 | $this->get('logger')->error('Error while saving an entry', [ | ||
498 | 'exception' => $e, | ||
499 | 'entry' => $entry, | ||
500 | ]); | ||
501 | |||
502 | $message = 'flashes.entry.notice.' . $prefixMessage . '_failed'; | ||
503 | } | ||
504 | |||
505 | if (empty($entry->getDomainName())) { | ||
506 | $this->get('wallabag_core.content_proxy')->setEntryDomainName($entry); | ||
507 | } | ||
508 | |||
509 | if (empty($entry->getTitle())) { | ||
510 | $this->get('wallabag_core.content_proxy')->setDefaultEntryTitle($entry); | ||
511 | } | ||
512 | |||
513 | $this->get('session')->getFlashBag()->add('notice', $message); | ||
514 | } | ||
515 | |||
516 | /** | ||
517 | * Global method to retrieve entries depending on the given type | 510 | * Global method to retrieve entries depending on the given type |
518 | * It returns the response to be send. | 511 | * It returns the response to be send. |
519 | * | 512 | * |
@@ -586,6 +579,39 @@ class EntryController extends Controller | |||
586 | } | 579 | } |
587 | 580 | ||
588 | /** | 581 | /** |
582 | * Fetch content and update entry. | ||
583 | * In case it fails, $entry->getContent will return an error message. | ||
584 | * | ||
585 | * @param Entry $entry | ||
586 | * @param string $prefixMessage Should be the translation key: entry_saved or entry_reloaded | ||
587 | */ | ||
588 | private function updateEntry(Entry $entry, $prefixMessage = 'entry_saved') | ||
589 | { | ||
590 | $message = 'flashes.entry.notice.' . $prefixMessage; | ||
591 | |||
592 | try { | ||
593 | $this->get('wallabag_core.content_proxy')->updateEntry($entry, $entry->getUrl()); | ||
594 | } catch (\Exception $e) { | ||
595 | $this->get('logger')->error('Error while saving an entry', [ | ||
596 | 'exception' => $e, | ||
597 | 'entry' => $entry, | ||
598 | ]); | ||
599 | |||
600 | $message = 'flashes.entry.notice.' . $prefixMessage . '_failed'; | ||
601 | } | ||
602 | |||
603 | if (empty($entry->getDomainName())) { | ||
604 | $this->get('wallabag_core.content_proxy')->setEntryDomainName($entry); | ||
605 | } | ||
606 | |||
607 | if (empty($entry->getTitle())) { | ||
608 | $this->get('wallabag_core.content_proxy')->setDefaultEntryTitle($entry); | ||
609 | } | ||
610 | |||
611 | $this->get('session')->getFlashBag()->add('notice', $message); | ||
612 | } | ||
613 | |||
614 | /** | ||
589 | * Check if the logged user can manage the given entry. | 615 | * Check if the logged user can manage the given entry. |
590 | * | 616 | * |
591 | * @param Entry $entry | 617 | * @param Entry $entry |