X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FWallabag%2FCoreBundle%2FController%2FExportController.php;h=282fd733b63d5e1b0d03a704611d5f5be38b0aca;hb=8668796106b856ca041512af27268ce6e49d2caf;hp=c8ef49a2ffcbf59d05054fbda25ec705d150f839;hpb=cceca9ea1d93ccf1420c2506330a16dc07f6433c;p=github%2Fwallabag%2Fwallabag.git diff --git a/src/Wallabag/CoreBundle/Controller/ExportController.php b/src/Wallabag/CoreBundle/Controller/ExportController.php index c8ef49a2..282fd733 100644 --- a/src/Wallabag/CoreBundle/Controller/ExportController.php +++ b/src/Wallabag/CoreBundle/Controller/ExportController.php @@ -2,9 +2,10 @@ namespace Wallabag\CoreBundle\Controller; -use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Symfony\Bundle\FrameworkBundle\Controller\Controller; +use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; +use Symfony\Component\Routing\Annotation\Route; use Wallabag\CoreBundle\Entity\Entry; /** @@ -16,12 +17,14 @@ class ExportController extends Controller /** * Gets one entry content. * - * @param Entry $entry + * @param string $format * * @Route("/export/{id}.{format}", name="export_entry", requirements={ * "format": "epub|mobi|pdf|json|xml|txt|csv", * "id": "\d+" * }) + * + * @return \Symfony\Component\HttpFoundation\Response */ public function downloadEntryAction(Entry $entry, $format) { @@ -29,6 +32,7 @@ class ExportController extends Controller return $this->get('wallabag_core.helper.entries_export') ->setEntries($entry) ->updateTitle('entry') + ->updateAuthor('entry') ->exportAs($format); } catch (\InvalidArgumentException $e) { throw new NotFoundHttpException($e->getMessage()); @@ -38,25 +42,44 @@ class ExportController extends Controller /** * Export all entries for current user. * + * @param string $format + * @param string $category + * * @Route("/export/{category}.{format}", name="export_entries", requirements={ * "format": "epub|mobi|pdf|json|xml|txt|csv", - * "category": "all|unread|starred|archive" + * "category": "all|unread|starred|archive|tag_entries|untagged|search" * }) + * + * @return \Symfony\Component\HttpFoundation\Response */ - public function downloadEntriesAction($format, $category) + public function downloadEntriesAction(Request $request, $format, $category) { $method = ucfirst($category); - $methodBuilder = 'getBuilderFor'.$method.'ByUser'; - $entries = $this->getDoctrine() - ->getRepository('WallabagCoreBundle:Entry') - ->$methodBuilder($this->getUser()->getId()) - ->getQuery() - ->getResult(); + $methodBuilder = 'getBuilderFor' . $method . 'ByUser'; + $repository = $this->get('wallabag_core.entry_repository'); + $title = $method; + + if ('tag_entries' === $category) { + $tag = $this->get('wallabag_core.tag_repository')->findOneBySlug($request->query->get('tag')); + + $entries = $repository->findAllByTagId( + $this->getUser()->getId(), + $tag->getId() + ); + + $title = 'Tag ' . $tag->getLabel(); + } else { + $entries = $repository + ->$methodBuilder($this->getUser()->getId()) + ->getQuery() + ->getResult(); + } try { return $this->get('wallabag_core.helper.entries_export') ->setEntries($entries) - ->updateTitle($method) + ->updateTitle($title) + ->updateAuthor($method) ->exportAs($format); } catch (\InvalidArgumentException $e) { throw new NotFoundHttpException($e->getMessage());