From: Nicolas LÅ“uillet Date: Sat, 29 Oct 2016 12:27:46 +0000 (+0200) Subject: Merge pull request #2506 from wallabag/fix-export-with-tags X-Git-Tag: 2.1.3~14 X-Git-Url: https://git.immae.eu/?p=github%2Fwallabag%2Fwallabag.git;a=commitdiff_plain;h=67b270d9967a023538c7598bfb520dd1007dd2ab;hp=267087d969e68e2f5abcb18f526120d835d9a686 Merge pull request #2506 from wallabag/fix-export-with-tags Fixed entries export filtered with a tag --- diff --git a/src/Wallabag/CoreBundle/Controller/ExportController.php b/src/Wallabag/CoreBundle/Controller/ExportController.php index 6191d5d7..79653cfe 100644 --- a/src/Wallabag/CoreBundle/Controller/ExportController.php +++ b/src/Wallabag/CoreBundle/Controller/ExportController.php @@ -4,8 +4,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 Wallabag\CoreBundle\Entity\Entry; +use Wallabag\CoreBundle\Entity\Tag; /** * The try/catch can be removed once all formats will be implemented. @@ -51,15 +53,24 @@ class ExportController extends Controller * * @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(); + + if ($category == 'tag_entries') { + $tag = $this->getDoctrine()->getRepository('WallabagCoreBundle:Tag')->findOneBySlug($request->query->get('tag')); + + $entries = $this->getDoctrine() + ->getRepository('WallabagCoreBundle:Entry') + ->findAllByTagId($this->getUser()->getId(), $tag->getId()); + } else { + $entries = $this->getDoctrine() + ->getRepository('WallabagCoreBundle:Entry') + ->$methodBuilder($this->getUser()->getId()) + ->getQuery() + ->getResult(); + } try { return $this->get('wallabag_core.helper.entries_export') diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Entry/entries.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Entry/entries.html.twig index f19f2922..5d657c7e 100644 --- a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Entry/entries.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Entry/entries.html.twig @@ -53,19 +53,23 @@ diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entries.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entries.html.twig index 5c7cfd65..1225e680 100644 --- a/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entries.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entries.html.twig @@ -99,18 +99,22 @@
{% set currentRoute = app.request.attributes.get('_route') %} + {% set currentTag = '' %} + {% if tag is defined %} + {% set currentTag = tag %} + {% endif %} {% if currentRoute == 'homepage' %} {% set currentRoute = 'unread' %} {% endif %}

{{ 'entry.list.export_title'|trans }}

diff --git a/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php index 9ecd8bc4..5ca886bd 100644 --- a/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php @@ -117,6 +117,17 @@ class ExportControllerTest extends WallabagCoreTestCase $this->assertEquals('application/pdf', $headers->get('content-type')); $this->assertEquals('attachment; filename="All articles.pdf"', $headers->get('content-disposition')); $this->assertEquals('binary', $headers->get('content-transfer-encoding')); + + ob_start(); + $crawler = $client->request('GET', '/export/tag_entries.pdf?tag=foo'); + ob_end_clean(); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + + $headers = $client->getResponse()->headers; + $this->assertEquals('application/pdf', $headers->get('content-type')); + $this->assertEquals('attachment; filename="Tag_entries articles.pdf"', $headers->get('content-disposition')); + $this->assertEquals('binary', $headers->get('content-transfer-encoding')); } public function testTxtExport()