]>
Commit | Line | Data |
---|---|---|
0c83fd59 J |
1 | <?php |
2 | ||
3 | namespace Wallabag\CoreBundle\Controller; | |
4 | ||
5 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; | |
6 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; | |
7 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; | |
8 | use Wallabag\CoreBundle\Entity\User; | |
9 | use Wallabag\CoreBundle\Entity\Entry; | |
26864574 NL |
10 | use Pagerfanta\Adapter\DoctrineORMAdapter; |
11 | use Pagerfanta\Pagerfanta; | |
0c83fd59 J |
12 | |
13 | class RssController extends Controller | |
14 | { | |
15 | /** | |
4346a860 | 16 | * Shows unread entries for current user. |
0c83fd59 J |
17 | * |
18 | * @Route("/{username}/{token}/unread.xml", name="unread_rss", defaults={"_format"="xml"}) | |
19 | * @ParamConverter("user", class="WallabagCoreBundle:User", converter="username_rsstoken_converter") | |
20 | * | |
21 | * @return \Symfony\Component\HttpFoundation\Response | |
22 | */ | |
23 | public function showUnreadAction(User $user) | |
24 | { | |
0ab7404f | 25 | return $this->showEntries('unread', $user); |
0c83fd59 J |
26 | } |
27 | ||
28 | /** | |
4346a860 | 29 | * Shows read entries for current user. |
0c83fd59 J |
30 | * |
31 | * @Route("/{username}/{token}/archive.xml", name="archive_rss") | |
32 | * @ParamConverter("user", class="WallabagCoreBundle:User", converter="username_rsstoken_converter") | |
33 | * | |
34 | * @return \Symfony\Component\HttpFoundation\Response | |
35 | */ | |
36 | public function showArchiveAction(User $user) | |
37 | { | |
0ab7404f | 38 | return $this->showEntries('archive', $user); |
0c83fd59 J |
39 | } |
40 | ||
41 | /** | |
4346a860 | 42 | * Shows starred entries for current user. |
0c83fd59 J |
43 | * |
44 | * @Route("/{username}/{token}/starred.xml", name="starred_rss") | |
45 | * @ParamConverter("user", class="WallabagCoreBundle:User", converter="username_rsstoken_converter") | |
46 | * | |
47 | * @return \Symfony\Component\HttpFoundation\Response | |
48 | */ | |
49 | public function showStarredAction(User $user) | |
50 | { | |
0ab7404f JB |
51 | return $this->showEntries('starred', $user); |
52 | } | |
53 | ||
54 | /** | |
55 | * Global method to retrieve entries depending on the given type | |
56 | * It returns the response to be send. | |
57 | * | |
58 | * @param string $type Entries type: unread, starred or archive | |
59 | * @param User $user | |
60 | * | |
61 | * @return \Symfony\Component\HttpFoundation\Response | |
62 | */ | |
63 | private function showEntries($type, User $user) | |
64 | { | |
65 | $repository = $this->getDoctrine()->getRepository('WallabagCoreBundle:Entry'); | |
66 | ||
67 | switch ($type) { | |
68 | case 'starred': | |
69 | $qb = $repository->getBuilderForStarredByUser($user->getId()); | |
70 | break; | |
71 | ||
72 | case 'archive': | |
73 | $qb = $repository->getBuilderForArchiveByUser($user->getId()); | |
74 | break; | |
75 | ||
76 | case 'unread': | |
77 | $qb = $repository->getBuilderForUnreadByUser($user->getId()); | |
78 | break; | |
79 | ||
80 | default: | |
81 | throw new \InvalidArgumentException(sprintf('Type "%s" is not implemented.', $type)); | |
82 | } | |
0c83fd59 | 83 | |
26864574 NL |
84 | $pagerAdapter = new DoctrineORMAdapter($qb->getQuery()); |
85 | $entries = new Pagerfanta($pagerAdapter); | |
86 | ||
9fb6ac83 FG |
87 | $perPage = $user->getConfig()->getRssLimit() ?: $this->container->getParameter('rss_limit'); |
88 | $entries->setMaxPerPage($perPage); | |
89 | ||
0c83fd59 | 90 | return $this->render('WallabagCoreBundle:Entry:entries.xml.twig', array( |
0ab7404f | 91 | 'type' => $type, |
0c83fd59 J |
92 | 'entries' => $entries, |
93 | )); | |
94 | } | |
95 | } |