diff options
Diffstat (limited to 'src/Wallabag/CoreBundle/Controller')
4 files changed, 120 insertions, 41 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/ConfigController.php b/src/Wallabag/CoreBundle/Controller/ConfigController.php index 89d27425..d4170d39 100644 --- a/src/Wallabag/CoreBundle/Controller/ConfigController.php +++ b/src/Wallabag/CoreBundle/Controller/ConfigController.php | |||
@@ -152,8 +152,7 @@ class ConfigController extends Controller | |||
152 | ], | 152 | ], |
153 | 'twofactor_auth' => $this->getParameter('twofactor_auth'), | 153 | 'twofactor_auth' => $this->getParameter('twofactor_auth'), |
154 | 'wallabag_url' => $this->getParameter('domain_name'), | 154 | 'wallabag_url' => $this->getParameter('domain_name'), |
155 | 'enabled_users' => $this->getDoctrine() | 155 | 'enabled_users' => $this->get('wallabag_user.user_repository') |
156 | ->getRepository('WallabagUserBundle:User') | ||
157 | ->getSumEnabledUsers(), | 156 | ->getSumEnabledUsers(), |
158 | ]); | 157 | ]); |
159 | } | 158 | } |
@@ -257,9 +256,7 @@ class ConfigController extends Controller | |||
257 | // manually remove tags to avoid orphan tag | 256 | // manually remove tags to avoid orphan tag |
258 | $this->removeAllTagsByUserId($this->getUser()->getId()); | 257 | $this->removeAllTagsByUserId($this->getUser()->getId()); |
259 | 258 | ||
260 | $this->getDoctrine() | 259 | $this->get('wallabag_core.entry_repository')->removeAllByUserId($this->getUser()->getId()); |
261 | ->getRepository('WallabagCoreBundle:Entry') | ||
262 | ->removeAllByUserId($this->getUser()->getId()); | ||
263 | break; | 260 | break; |
264 | case 'archived': | 261 | case 'archived': |
265 | if ($this->get('doctrine')->getConnection()->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\SqlitePlatform) { | 262 | if ($this->get('doctrine')->getConnection()->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\SqlitePlatform) { |
@@ -269,9 +266,7 @@ class ConfigController extends Controller | |||
269 | // manually remove tags to avoid orphan tag | 266 | // manually remove tags to avoid orphan tag |
270 | $this->removeTagsForArchivedByUserId($this->getUser()->getId()); | 267 | $this->removeTagsForArchivedByUserId($this->getUser()->getId()); |
271 | 268 | ||
272 | $this->getDoctrine() | 269 | $this->get('wallabag_core.entry_repository')->removeArchivedByUserId($this->getUser()->getId()); |
273 | ->getRepository('WallabagCoreBundle:Entry') | ||
274 | ->removeArchivedByUserId($this->getUser()->getId()); | ||
275 | break; | 270 | break; |
276 | } | 271 | } |
277 | 272 | ||
@@ -295,8 +290,7 @@ class ConfigController extends Controller | |||
295 | return; | 290 | return; |
296 | } | 291 | } |
297 | 292 | ||
298 | $this->getDoctrine() | 293 | $this->get('wallabag_core.entry_repository') |
299 | ->getRepository('WallabagCoreBundle:Entry') | ||
300 | ->removeTags($userId, $tags); | 294 | ->removeTags($userId, $tags); |
301 | 295 | ||
302 | // cleanup orphan tags | 296 | // cleanup orphan tags |
@@ -318,7 +312,7 @@ class ConfigController extends Controller | |||
318 | */ | 312 | */ |
319 | private function removeAllTagsByUserId($userId) | 313 | private function removeAllTagsByUserId($userId) |
320 | { | 314 | { |
321 | $tags = $this->getDoctrine()->getRepository('WallabagCoreBundle:Tag')->findAllTags($userId); | 315 | $tags = $this->get('wallabag_core.tag_repository')->findAllTags($userId); |
322 | $this->removeAllTagsByStatusAndUserId($tags, $userId); | 316 | $this->removeAllTagsByStatusAndUserId($tags, $userId); |
323 | } | 317 | } |
324 | 318 | ||
@@ -329,7 +323,7 @@ class ConfigController extends Controller | |||
329 | */ | 323 | */ |
330 | private function removeTagsForArchivedByUserId($userId) | 324 | private function removeTagsForArchivedByUserId($userId) |
331 | { | 325 | { |
332 | $tags = $this->getDoctrine()->getRepository('WallabagCoreBundle:Tag')->findForArchivedArticlesByUser($userId); | 326 | $tags = $this->get('wallabag_core.tag_repository')->findForArchivedArticlesByUser($userId); |
333 | $this->removeAllTagsByStatusAndUserId($tags, $userId); | 327 | $this->removeAllTagsByStatusAndUserId($tags, $userId); |
334 | } | 328 | } |
335 | 329 | ||
@@ -393,8 +387,7 @@ class ConfigController extends Controller | |||
393 | */ | 387 | */ |
394 | public function deleteAccountAction(Request $request) | 388 | public function deleteAccountAction(Request $request) |
395 | { | 389 | { |
396 | $enabledUsers = $this->getDoctrine() | 390 | $enabledUsers = $this->get('wallabag_user.user_repository') |
397 | ->getRepository('WallabagUserBundle:User') | ||
398 | ->getSumEnabledUsers(); | 391 | ->getSumEnabledUsers(); |
399 | 392 | ||
400 | if ($enabledUsers <= 1) { | 393 | if ($enabledUsers <= 1) { |
diff --git a/src/Wallabag/CoreBundle/Controller/ExportController.php b/src/Wallabag/CoreBundle/Controller/ExportController.php index abc3336a..fda04cfb 100644 --- a/src/Wallabag/CoreBundle/Controller/ExportController.php +++ b/src/Wallabag/CoreBundle/Controller/ExportController.php | |||
@@ -7,7 +7,6 @@ use Symfony\Bundle\FrameworkBundle\Controller\Controller; | |||
7 | use Symfony\Component\HttpFoundation\Request; | 7 | use Symfony\Component\HttpFoundation\Request; |
8 | use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; | 8 | use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
9 | use Wallabag\CoreBundle\Entity\Entry; | 9 | use Wallabag\CoreBundle\Entity\Entry; |
10 | use Wallabag\CoreBundle\Entity\Tag; | ||
11 | 10 | ||
12 | /** | 11 | /** |
13 | * The try/catch can be removed once all formats will be implemented. | 12 | * The try/catch can be removed once all formats will be implemented. |
@@ -57,16 +56,17 @@ class ExportController extends Controller | |||
57 | { | 56 | { |
58 | $method = ucfirst($category); | 57 | $method = ucfirst($category); |
59 | $methodBuilder = 'getBuilderFor'.$method.'ByUser'; | 58 | $methodBuilder = 'getBuilderFor'.$method.'ByUser'; |
59 | $repository = $this->get('wallabag_core.entry_repository'); | ||
60 | 60 | ||
61 | if ($category == 'tag_entries') { | 61 | if ($category == 'tag_entries') { |
62 | $tag = $this->getDoctrine()->getRepository('WallabagCoreBundle:Tag')->findOneBySlug($request->query->get('tag')); | 62 | $tag = $this->get('wallabag_core.tag_repository')->findOneBySlug($request->query->get('tag')); |
63 | 63 | ||
64 | $entries = $this->getDoctrine() | 64 | $entries = $repository->findAllByTagId( |
65 | ->getRepository('WallabagCoreBundle:Entry') | 65 | $this->getUser()->getId(), |
66 | ->findAllByTagId($this->getUser()->getId(), $tag->getId()); | 66 | $tag->getId() |
67 | ); | ||
67 | } else { | 68 | } else { |
68 | $entries = $this->getDoctrine() | 69 | $entries = $repository |
69 | ->getRepository('WallabagCoreBundle:Entry') | ||
70 | ->$methodBuilder($this->getUser()->getId()) | 70 | ->$methodBuilder($this->getUser()->getId()) |
71 | ->getQuery() | 71 | ->getQuery() |
72 | ->getResult(); | 72 | ->getResult(); |
diff --git a/src/Wallabag/CoreBundle/Controller/RssController.php b/src/Wallabag/CoreBundle/Controller/RssController.php index 92f18707..e87dd9a1 100644 --- a/src/Wallabag/CoreBundle/Controller/RssController.php +++ b/src/Wallabag/CoreBundle/Controller/RssController.php | |||
@@ -3,13 +3,16 @@ | |||
3 | namespace Wallabag\CoreBundle\Controller; | 3 | namespace Wallabag\CoreBundle\Controller; |
4 | 4 | ||
5 | use Pagerfanta\Adapter\DoctrineORMAdapter; | 5 | use Pagerfanta\Adapter\DoctrineORMAdapter; |
6 | use Pagerfanta\Adapter\ArrayAdapter; | ||
6 | use Pagerfanta\Exception\OutOfRangeCurrentPageException; | 7 | use Pagerfanta\Exception\OutOfRangeCurrentPageException; |
7 | use Pagerfanta\Pagerfanta; | 8 | use Pagerfanta\Pagerfanta; |
8 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; | 9 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; |
9 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; | 10 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
10 | use Symfony\Component\HttpFoundation\Request; | 11 | use Symfony\Component\HttpFoundation\Request; |
12 | use Symfony\Component\HttpFoundation\Response; | ||
11 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; | 13 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
12 | use Wallabag\CoreBundle\Entity\Entry; | 14 | use Wallabag\CoreBundle\Entity\Entry; |
15 | use Wallabag\CoreBundle\Entity\Tag; | ||
13 | use Wallabag\UserBundle\Entity\User; | 16 | use Wallabag\UserBundle\Entity\User; |
14 | use Symfony\Component\Routing\Generator\UrlGeneratorInterface; | 17 | use Symfony\Component\Routing\Generator\UrlGeneratorInterface; |
15 | 18 | ||
@@ -23,7 +26,7 @@ class RssController extends Controller | |||
23 | * | 26 | * |
24 | * @return \Symfony\Component\HttpFoundation\Response | 27 | * @return \Symfony\Component\HttpFoundation\Response |
25 | */ | 28 | */ |
26 | public function showUnreadAction(Request $request, User $user) | 29 | public function showUnreadRSSAction(Request $request, User $user) |
27 | { | 30 | { |
28 | return $this->showEntries('unread', $user, $request->query->get('page', 1)); | 31 | return $this->showEntries('unread', $user, $request->query->get('page', 1)); |
29 | } | 32 | } |
@@ -31,12 +34,12 @@ class RssController extends Controller | |||
31 | /** | 34 | /** |
32 | * Shows read entries for current user. | 35 | * Shows read entries for current user. |
33 | * | 36 | * |
34 | * @Route("/{username}/{token}/archive.xml", name="archive_rss") | 37 | * @Route("/{username}/{token}/archive.xml", name="archive_rss", defaults={"_format"="xml"}) |
35 | * @ParamConverter("user", class="WallabagUserBundle:User", converter="username_rsstoken_converter") | 38 | * @ParamConverter("user", class="WallabagUserBundle:User", converter="username_rsstoken_converter") |
36 | * | 39 | * |
37 | * @return \Symfony\Component\HttpFoundation\Response | 40 | * @return \Symfony\Component\HttpFoundation\Response |
38 | */ | 41 | */ |
39 | public function showArchiveAction(Request $request, User $user) | 42 | public function showArchiveRSSAction(Request $request, User $user) |
40 | { | 43 | { |
41 | return $this->showEntries('archive', $user, $request->query->get('page', 1)); | 44 | return $this->showEntries('archive', $user, $request->query->get('page', 1)); |
42 | } | 45 | } |
@@ -44,17 +47,89 @@ class RssController extends Controller | |||
44 | /** | 47 | /** |
45 | * Shows starred entries for current user. | 48 | * Shows starred entries for current user. |
46 | * | 49 | * |
47 | * @Route("/{username}/{token}/starred.xml", name="starred_rss") | 50 | * @Route("/{username}/{token}/starred.xml", name="starred_rss", defaults={"_format"="xml"}) |
48 | * @ParamConverter("user", class="WallabagUserBundle:User", converter="username_rsstoken_converter") | 51 | * @ParamConverter("user", class="WallabagUserBundle:User", converter="username_rsstoken_converter") |
49 | * | 52 | * |
50 | * @return \Symfony\Component\HttpFoundation\Response | 53 | * @return \Symfony\Component\HttpFoundation\Response |
51 | */ | 54 | */ |
52 | public function showStarredAction(Request $request, User $user) | 55 | public function showStarredRSSAction(Request $request, User $user) |
53 | { | 56 | { |
54 | return $this->showEntries('starred', $user, $request->query->get('page', 1)); | 57 | return $this->showEntries('starred', $user, $request->query->get('page', 1)); |
55 | } | 58 | } |
56 | 59 | ||
57 | /** | 60 | /** |
61 | * Shows all entries for current user. | ||
62 | * | ||
63 | * @Route("/{username}/{token}/all.xml", name="all_rss", defaults={"_format"="xml"}) | ||
64 | * @ParamConverter("user", class="WallabagUserBundle:User", converter="username_rsstoken_converter") | ||
65 | * | ||
66 | * @return \Symfony\Component\HttpFoundation\Response | ||
67 | */ | ||
68 | public function showAllRSSAction(Request $request, User $user) | ||
69 | { | ||
70 | return $this->showEntries('all', $user, $request->query->get('page', 1)); | ||
71 | } | ||
72 | |||
73 | /** | ||
74 | * Shows entries associated to a tag for current user. | ||
75 | * | ||
76 | * @Route("/{username}/{token}/tags/{slug}.xml", name="tag_rss", defaults={"_format"="xml"}) | ||
77 | * @ParamConverter("user", class="WallabagUserBundle:User", converter="username_rsstoken_converter") | ||
78 | * @ParamConverter("tag", options={"mapping": {"slug": "slug"}}) | ||
79 | * | ||
80 | * @return \Symfony\Component\HttpFoundation\Response | ||
81 | */ | ||
82 | public function showTagsAction(Request $request, User $user, Tag $tag) | ||
83 | { | ||
84 | $page = $request->query->get('page', 1); | ||
85 | |||
86 | $url = $this->generateUrl( | ||
87 | 'tag_rss', | ||
88 | [ | ||
89 | 'username' => $user->getUsername(), | ||
90 | 'token' => $user->getConfig()->getRssToken(), | ||
91 | 'slug' => $tag->getSlug(), | ||
92 | ], | ||
93 | UrlGeneratorInterface::ABSOLUTE_URL | ||
94 | ); | ||
95 | |||
96 | $entriesByTag = $this->get('wallabag_core.entry_repository')->findAllByTagId( | ||
97 | $user->getId(), | ||
98 | $tag->getId() | ||
99 | ); | ||
100 | |||
101 | $pagerAdapter = new ArrayAdapter($entriesByTag); | ||
102 | |||
103 | $entries = $this->get('wallabag_core.helper.prepare_pager_for_entries')->prepare( | ||
104 | $pagerAdapter, | ||
105 | $user | ||
106 | ); | ||
107 | |||
108 | if (null === $entries) { | ||
109 | throw $this->createNotFoundException('No entries found?'); | ||
110 | } | ||
111 | |||
112 | try { | ||
113 | $entries->setCurrentPage($page); | ||
114 | } catch (OutOfRangeCurrentPageException $e) { | ||
115 | if ($page > 1) { | ||
116 | return $this->redirect($url.'?page='.$entries->getNbPages(), 302); | ||
117 | } | ||
118 | } | ||
119 | |||
120 | return $this->render( | ||
121 | '@WallabagCore/themes/common/Entry/entries.xml.twig', | ||
122 | [ | ||
123 | 'url_html' => $this->generateUrl('tag_entries', ['slug' => $tag->getSlug()], UrlGeneratorInterface::ABSOLUTE_URL), | ||
124 | 'type' => 'tag ('.$tag->getLabel().')', | ||
125 | 'url' => $url, | ||
126 | 'entries' => $entries, | ||
127 | ], | ||
128 | new Response('', 200, ['Content-Type' => 'application/rss+xml']) | ||
129 | ); | ||
130 | } | ||
131 | |||
132 | /** | ||
58 | * Global method to retrieve entries depending on the given type | 133 | * Global method to retrieve entries depending on the given type |
59 | * It returns the response to be send. | 134 | * It returns the response to be send. |
60 | * | 135 | * |
@@ -66,7 +141,7 @@ class RssController extends Controller | |||
66 | */ | 141 | */ |
67 | private function showEntries($type, User $user, $page = 1) | 142 | private function showEntries($type, User $user, $page = 1) |
68 | { | 143 | { |
69 | $repository = $this->getDoctrine()->getRepository('WallabagCoreBundle:Entry'); | 144 | $repository = $this->get('wallabag_core.entry_repository'); |
70 | 145 | ||
71 | switch ($type) { | 146 | switch ($type) { |
72 | case 'starred': | 147 | case 'starred': |
@@ -81,6 +156,10 @@ class RssController extends Controller | |||
81 | $qb = $repository->getBuilderForUnreadByUser($user->getId()); | 156 | $qb = $repository->getBuilderForUnreadByUser($user->getId()); |
82 | break; | 157 | break; |
83 | 158 | ||
159 | case 'all': | ||
160 | $qb = $repository->getBuilderForAllByUser($user->getId()); | ||
161 | break; | ||
162 | |||
84 | default: | 163 | default: |
85 | throw new \InvalidArgumentException(sprintf('Type "%s" is not implemented.', $type)); | 164 | throw new \InvalidArgumentException(sprintf('Type "%s" is not implemented.', $type)); |
86 | } | 165 | } |
@@ -108,10 +187,15 @@ class RssController extends Controller | |||
108 | } | 187 | } |
109 | } | 188 | } |
110 | 189 | ||
111 | return $this->render('@WallabagCore/themes/common/Entry/entries.xml.twig', [ | 190 | return $this->render( |
112 | 'type' => $type, | 191 | '@WallabagCore/themes/common/Entry/entries.xml.twig', |
113 | 'url' => $url, | 192 | [ |
114 | 'entries' => $entries, | 193 | 'url_html' => $this->generateUrl($type, [], UrlGeneratorInterface::ABSOLUTE_URL), |
115 | ]); | 194 | 'type' => $type, |
195 | 'url' => $url, | ||
196 | 'entries' => $entries, | ||
197 | ], | ||
198 | new Response('', 200, ['Content-Type' => 'application/rss+xml']) | ||
199 | ); | ||
116 | } | 200 | } |
117 | } | 201 | } |
diff --git a/src/Wallabag/CoreBundle/Controller/TagController.php b/src/Wallabag/CoreBundle/Controller/TagController.php index 9422bae4..a8b1eadd 100644 --- a/src/Wallabag/CoreBundle/Controller/TagController.php +++ b/src/Wallabag/CoreBundle/Controller/TagController.php | |||
@@ -84,16 +84,17 @@ class TagController extends Controller | |||
84 | */ | 84 | */ |
85 | public function showTagAction() | 85 | public function showTagAction() |
86 | { | 86 | { |
87 | $tags = $this->getDoctrine() | 87 | $repository = $this->get('wallabag_core.entry_repository'); |
88 | ->getRepository('WallabagCoreBundle:Tag') | 88 | $tags = $this->get('wallabag_core.tag_repository') |
89 | ->findAllTags($this->getUser()->getId()); | 89 | ->findAllTags($this->getUser()->getId()); |
90 | 90 | ||
91 | $flatTags = []; | 91 | $flatTags = []; |
92 | 92 | ||
93 | foreach ($tags as $tag) { | 93 | foreach ($tags as $tag) { |
94 | $nbEntries = $this->getDoctrine() | 94 | $nbEntries = $repository->countAllEntriesByUserIdAndTagId( |
95 | ->getRepository('WallabagCoreBundle:Entry') | 95 | $this->getUser()->getId(), |
96 | ->countAllEntriesByUserIdAndTagId($this->getUser()->getId(), $tag->getId()); | 96 | $tag->getId() |
97 | ); | ||
97 | 98 | ||
98 | $flatTags[] = [ | 99 | $flatTags[] = [ |
99 | 'id' => $tag->getId(), | 100 | 'id' => $tag->getId(), |
@@ -119,9 +120,10 @@ class TagController extends Controller | |||
119 | */ | 120 | */ |
120 | public function showEntriesForTagAction(Tag $tag, $page, Request $request) | 121 | public function showEntriesForTagAction(Tag $tag, $page, Request $request) |
121 | { | 122 | { |
122 | $entriesByTag = $this->getDoctrine() | 123 | $entriesByTag = $this->get('wallabag_core.entry_repository')->findAllByTagId( |
123 | ->getRepository('WallabagCoreBundle:Entry') | 124 | $this->getUser()->getId(), |
124 | ->findAllByTagId($this->getUser()->getId(), $tag->getId()); | 125 | $tag->getId() |
126 | ); | ||
125 | 127 | ||
126 | $pagerAdapter = new ArrayAdapter($entriesByTag); | 128 | $pagerAdapter = new ArrayAdapter($entriesByTag); |
127 | 129 | ||
@@ -142,7 +144,7 @@ class TagController extends Controller | |||
142 | 'form' => null, | 144 | 'form' => null, |
143 | 'entries' => $entries, | 145 | 'entries' => $entries, |
144 | 'currentPage' => $page, | 146 | 'currentPage' => $page, |
145 | 'tag' => $tag->getSlug(), | 147 | 'tag' => $tag, |
146 | ]); | 148 | ]); |
147 | } | 149 | } |
148 | } | 150 | } |