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.
20 * @param string $format
22 * @Route("/export/{id}.{format}", name="export_entry", requirements={
23 * "format": "epub|mobi|pdf|json|xml|txt|csv",
27 * @return \Symfony\Component\HttpFoundation\Response
29 public function downloadEntryAction(Entry
$entry, $format)
32 return $this->get('wallabag_core.helper.entries_export')
34 ->updateTitle('entry')
35 ->updateAuthor('entry')
37 } catch (\InvalidArgumentException
$e) {
38 throw new NotFoundHttpException($e->getMessage());
43 * Export all entries for current user.
45 * @param string $format
46 * @param string $category
48 * @Route("/export/{category}.{format}", name="export_entries", requirements={
49 * "format": "epub|mobi|pdf|json|xml|txt|csv",
50 * "category": "all|unread|starred|archive|tag_entries|untagged|search"
53 * @return \Symfony\Component\HttpFoundation\Response
55 public function downloadEntriesAction(Request
$request, $format, $category)
57 $method = ucfirst($category);
58 $methodBuilder = 'getBuilderFor' . $method . 'ByUser';
59 $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 $title = 'Tag ' . $tag->getLabel();
71 } elseif ('search' === $category) {
72 $searchTerm = (isset($request->get('search_entry')['term']) ? $request->get('search_entry')['term'] : '');
73 $currentRoute = (null !== $request->query
->get('currentRoute') ? $request->query
->get('currentRoute') : '');
75 $entries = $repository->getBuilderForSearchByUser(
76 $this->getUser()->getId(),
82 $title = 'Search ' . $searchTerm;
84 $entries = $repository
85 ->$methodBuilder($this->getUser()->getId())
91 return $this->get('wallabag_core.helper.entries_export')
92 ->setEntries($entries)
94 ->updateAuthor($method)
96 } catch (\InvalidArgumentException
$e) {
97 throw new NotFoundHttpException($e->getMessage());