]>
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 | * |
add597ba JB |
19 | * @param Entry $entry |
20 | * | |
cceca9ea JB |
21 | * @Route("/export/{id}.{format}", name="export_entry", requirements={ |
22 | * "format": "epub|mobi|pdf|json|xml|txt|csv", | |
23 | * "id": "\d+" | |
24 | * }) | |
03690d13 | 25 | */ |
add597ba | 26 | public function downloadEntryAction(Entry $entry, $format) |
03690d13 | 27 | { |
add597ba JB |
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()); | |
03690d13 | 35 | } |
03690d13 TC |
36 | } |
37 | ||
38 | /** | |
add597ba | 39 | * Export all entries for current user. |
03690d13 | 40 | * |
add597ba | 41 | * @Route("/export/{category}.{format}", name="export_entries", requirements={ |
cceca9ea | 42 | * "format": "epub|mobi|pdf|json|xml|txt|csv", |
add597ba JB |
43 | * "category": "all|unread|starred|archive" |
44 | * }) | |
03690d13 | 45 | */ |
add597ba | 46 | public function downloadEntriesAction($format, $category) |
03690d13 | 47 | { |
add597ba JB |
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 | } | |
03690d13 TC |
64 | } |
65 | } |