]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/CoreBundle/Controller/ExportController.php
User existing service instead of getDoctrine
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Controller / ExportController.php
index 959b308d8bc0e5cff8bfce213b9e8f50c2970e19..b9e5a974acede4fc9d5f8cbcce36e3f1561b10c4 100644 (file)
@@ -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.
@@ -46,20 +48,30 @@ class ExportController extends Controller
      *
      * @Route("/export/{category}.{format}", name="export_entries", requirements={
      *     "format": "epub|mobi|pdf|json|xml|txt|csv",
-     *     "category": "all|unread|starred|archive|tag_entries"
+     *     "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();
+        $epository = $this->get('wallabag_core.entry_repository');
+
+        if ($category == 'tag_entries') {
+            $tag = $this->get('wallabag_core.tag_repository')->findOneBySlug($request->query->get('tag'));
+
+            $entries = $epository->findAllByTagId(
+                $this->getUser()->getId(),
+                $tag->getId()
+            );
+        } else {
+            $entries = $epository
+                ->$methodBuilder($this->getUser()->getId())
+                ->getQuery()
+                ->getResult();
+        }
 
         try {
             return $this->get('wallabag_core.helper.entries_export')