3 namespace Wallabag\CoreBundle\Controller
;
5 use Pagerfanta\Adapter\DoctrineORMAdapter
;
6 use Pagerfanta\Exception\OutOfRangeCurrentPageException
;
7 use Pagerfanta\Pagerfanta
;
8 use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter
;
9 use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route
;
10 use Symfony\Component\HttpFoundation\Request
;
11 use Symfony\Bundle\FrameworkBundle\Controller\Controller
;
12 use Wallabag\CoreBundle\Entity\Entry
;
13 use Wallabag\UserBundle\Entity\User
;
14 use Symfony\Component\Routing\Generator\UrlGeneratorInterface
;
16 class RssController
extends Controller
19 * Shows unread entries for current user.
21 * @Route("/{username}/{token}/unread.xml", name="unread_rss", defaults={"_format"="xml"})
22 * @ParamConverter("user", class="WallabagUserBundle:User", converter="username_rsstoken_converter")
24 * @return \Symfony\Component\HttpFoundation\Response
26 public function showUnreadAction(Request
$request, User
$user)
28 return $this->showEntries('unread', $user, $request->query
->get('page', 1));
32 * Shows read entries for current user.
34 * @Route("/{username}/{token}/archive.xml", name="archive_rss")
35 * @ParamConverter("user", class="WallabagUserBundle:User", converter="username_rsstoken_converter")
37 * @return \Symfony\Component\HttpFoundation\Response
39 public function showArchiveAction(Request
$request, User
$user)
41 return $this->showEntries('archive', $user, $request->query
->get('page', 1));
45 * Shows starred entries for current user.
47 * @Route("/{username}/{token}/starred.xml", name="starred_rss")
48 * @ParamConverter("user", class="WallabagUserBundle:User", converter="username_rsstoken_converter")
50 * @return \Symfony\Component\HttpFoundation\Response
52 public function showStarredAction(Request
$request, User
$user)
54 return $this->showEntries('starred', $user, $request->query
->get('page', 1));
58 * Global method to retrieve entries depending on the given type
59 * It returns the response to be send.
61 * @param string $type Entries type: unread, starred or archive
65 * @return \Symfony\Component\HttpFoundation\Response
67 private function showEntries($type, User
$user, $page = 1)
69 $repository = $this->getDoctrine()->getRepository('WallabagCoreBundle:Entry');
73 $qb = $repository->getBuilderForStarredByUser($user->getId());
77 $qb = $repository->getBuilderForArchiveByUser($user->getId());
81 $qb = $repository->getBuilderForUnreadByUser($user->getId());
85 throw new \
InvalidArgumentException(sprintf('Type "%s" is not implemented.', $type));
88 $pagerAdapter = new DoctrineORMAdapter($qb->getQuery());
89 $entries = new Pagerfanta($pagerAdapter);
91 $perPage = $user->getConfig()->getRssLimit() ?: $this->getParameter('wallabag_core.rss_limit');
92 $entries->setMaxPerPage($perPage);
94 $url = $this->generateUrl(
97 'username' => $user->getUsername(),
98 'token' => $user->getConfig()->getRssToken(),
100 UrlGeneratorInterface
::ABSOLUTE_URL
104 $entries->setCurrentPage((int) $page);
105 } catch (OutOfRangeCurrentPageException
$e) {
107 return $this->redirect($url.'?page='.$entries->getNbPages(), 302);
111 return $this->render('@WallabagCore/themes/common/Entry/entries.xml.twig', [
114 'entries' => $entries,