3 namespace Wallabag\CoreBundle\Controller
;
5 use Symfony\Bundle\FrameworkBundle\Controller\Controller
;
6 use Symfony\Component\HttpFoundation\Request
;
7 use Symfony\Component\HttpKernel\Exception\NotFoundHttpException
;
8 use Symfony\Component\Routing\Annotation\Route
;
9 use Wallabag\CoreBundle\Entity\Entry
;
12 * The try/catch can be removed once all formats will be implemented.
13 * Still need implementation: txt.
15 class ExportController
extends Controller
18 * Gets one entry content.
21 * @param string $format
23 * @Route("/export/{id}.{format}", name="export_entry", requirements={
24 * "format": "epub|mobi|pdf|json|xml|txt|csv",
28 * @return \Symfony\Component\HttpFoundation\Response
30 public function downloadEntryAction(Entry
$entry, $format)
33 return $this->get('wallabag_core.helper.entries_export')
35 ->updateTitle('entry')
36 ->updateAuthor('entry')
38 } catch (\InvalidArgumentException
$e) {
39 throw new NotFoundHttpException($e->getMessage());
44 * Export all entries for current user.
46 * @param string $format
47 * @param string $category
49 * @Route("/export/{category}.{format}", name="export_entries", requirements={
50 * "format": "epub|mobi|pdf|json|xml|txt|csv",
51 * "category": "all|unread|starred|archive|tag_entries|untagged|search"
54 * @return \Symfony\Component\HttpFoundation\Response
56 public function downloadEntriesAction(Request
$request, $format, $category)
58 $method = ucfirst($category);
59 $methodBuilder = 'getBuilderFor' . $method . 'ByUser';
60 $repository = $this->get('wallabag_core.entry_repository');
62 if ('tag_entries' === $category) {
63 $tag = $this->get('wallabag_core.tag_repository')->findOneBySlug($request->query
->get('tag'));
65 $entries = $repository->findAllByTagId(
66 $this->getUser()->getId(),
70 $entries = $repository
71 ->$methodBuilder($this->getUser()->getId())
77 return $this->get('wallabag_core.helper.entries_export')
78 ->setEntries($entries)
79 ->updateTitle($method)
80 ->updateAuthor($method)
82 } catch (\InvalidArgumentException
$e) {
83 throw new NotFoundHttpException($e->getMessage());