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