]> git.immae.eu Git - github/wallabag/wallabag.git/blob - src/Wallabag/CoreBundle/Controller/ExportController.php
Fix route parameters
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Controller / ExportController.php
1 <?php
2
3 namespace Wallabag\CoreBundle\Controller;
4
5 use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
6 use Symfony\Bundle\FrameworkBundle\Controller\Controller;
7 use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
8 use Wallabag\CoreBundle\Entity\Entry;
9
10 /**
11 * The try/catch can be removed once all formats will be implemented.
12 * Still need implementation: txt.
13 */
14 class ExportController extends Controller
15 {
16 /**
17 * Gets one entry content.
18 *
19 * @param Entry $entry
20 *
21 * @Route("/export/{id}.{format}", name="export_entry", requirements={
22 * "format": "epub|mobi|pdf|json|xml|txt|csv",
23 * "id": "\d+"
24 * })
25 */
26 public function downloadEntryAction(Entry $entry, $format)
27 {
28 try {
29 return $this->get('wallabag_core.helper.entries_export')
30 ->setEntries($entry)
31 ->updateTitle('entry')
32 ->exportAs($format);
33 } catch (\InvalidArgumentException $e) {
34 throw new NotFoundHttpException($e->getMessage());
35 }
36 }
37
38 /**
39 * Export all entries for current user.
40 *
41 * @Route("/export/{category}.{format}", name="export_entries", requirements={
42 * "format": "epub|mobi|pdf|json|xml|txt|csv",
43 * "category": "all|unread|starred|archive"
44 * })
45 */
46 public function downloadEntriesAction($format, $category)
47 {
48 $method = ucfirst($category);
49 $methodBuilder = 'getBuilderFor'.$method.'ByUser';
50 $entries = $this->getDoctrine()
51 ->getRepository('WallabagCoreBundle:Entry')
52 ->$methodBuilder($this->getUser()->getId())
53 ->getQuery()
54 ->getResult();
55
56 try {
57 return $this->get('wallabag_core.helper.entries_export')
58 ->setEntries($entries)
59 ->updateTitle($method)
60 ->exportAs($format);
61 } catch (\InvalidArgumentException $e) {
62 throw new NotFoundHttpException($e->getMessage());
63 }
64 }
65 }