]> git.immae.eu Git - github/wallabag/wallabag.git/blob - src/Wallabag/CoreBundle/Controller/ExportController.php
Rework on export
[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 class ExportController extends Controller
11 {
12 /**
13 * Gets one entry content.
14 *
15 * @param Entry $entry
16 *
17 * @Route("/export/{id}.{format}", requirements={"id" = "\d+"}, name="export_entry")
18 */
19 public function downloadEntryAction(Entry $entry, $format)
20 {
21 try {
22 return $this->get('wallabag_core.helper.entries_export')
23 ->setEntries($entry)
24 ->updateTitle('entry')
25 ->exportAs($format);
26 } catch (\InvalidArgumentException $e) {
27 throw new NotFoundHttpException($e->getMessage());
28 }
29 }
30
31 /**
32 * Export all entries for current user.
33 *
34 * @Route("/export/{category}.{format}", name="export_entries", requirements={
35 * "_format": "epub|mobi|pdf|json|xml|txt|csv",
36 * "category": "all|unread|starred|archive"
37 * })
38 */
39 public function downloadEntriesAction($format, $category)
40 {
41 $method = ucfirst($category);
42 $methodBuilder = 'getBuilderFor'.$method.'ByUser';
43 $entries = $this->getDoctrine()
44 ->getRepository('WallabagCoreBundle:Entry')
45 ->$methodBuilder($this->getUser()->getId())
46 ->getQuery()
47 ->getResult();
48
49 try {
50 return $this->get('wallabag_core.helper.entries_export')
51 ->setEntries($entries)
52 ->updateTitle($method)
53 ->exportAs($format);
54 } catch (\InvalidArgumentException $e) {
55 throw new NotFoundHttpException($e->getMessage());
56 }
57 }
58 }