]> git.immae.eu Git - github/wallabag/wallabag.git/blame - src/Wallabag/CoreBundle/Controller/ExportController.php
use JMS Serializer
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Controller / ExportController.php
CommitLineData
03690d13
TC
1<?php
2
3namespace Wallabag\CoreBundle\Controller;
4
5use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
6use Symfony\Bundle\FrameworkBundle\Controller\Controller;
add597ba 7use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
03690d13 8use Wallabag\CoreBundle\Entity\Entry;
03690d13
TC
9
10class ExportController extends Controller
11{
12 /**
add597ba 13 * Gets one entry content.
03690d13 14 *
add597ba
JB
15 * @param Entry $entry
16 *
17 * @Route("/export/{id}.{format}", requirements={"id" = "\d+"}, name="export_entry")
03690d13 18 */
add597ba 19 public function downloadEntryAction(Entry $entry, $format)
03690d13 20 {
add597ba
JB
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());
03690d13 28 }
03690d13
TC
29 }
30
31 /**
add597ba 32 * Export all entries for current user.
03690d13 33 *
add597ba
JB
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 * })
03690d13 38 */
add597ba 39 public function downloadEntriesAction($format, $category)
03690d13 40 {
add597ba
JB
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 }
03690d13
TC
57 }
58}