]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/CoreBundle/Controller/EntryController.php
Add some fixtures
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Controller / EntryController.php
index 25f1871152d104b2f0e76d00c872888695ec5d5e..e0697ca3ef3852af631eef32eb91813b8b7acdab 100644 (file)
@@ -5,24 +5,21 @@ namespace Wallabag\CoreBundle\Controller;
 use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
 use Symfony\Bundle\FrameworkBundle\Controller\Controller;
 use Symfony\Component\HttpFoundation\Request;
+use Wallabag\CoreBundle\Entity\Entry;
 use Wallabag\CoreBundle\Repository;
-use Wallabag\CoreBundle\Entity\Entries;
 use Wallabag\CoreBundle\Service\Extractor;
-use Wallabag\CoreBundle\Helper\Tools;
 use Wallabag\CoreBundle\Helper\Url;
 
 class EntryController extends Controller
 {
-
     /**
-     * @param Request $request
+     * @param  Request                                    $request
      * @Route("/new", name="new_entry")
      * @return \Symfony\Component\HttpFoundation\Response
      */
     public function addEntryAction(Request $request)
     {
-        $entry = new Entries();
-        $entry->setUserId(1);
+        $entry = new Entry($this->getUser());
 
         $form = $this->createFormBuilder($entry)
             ->add('url', 'url')
@@ -32,7 +29,6 @@ class EntryController extends Controller
         $form->handleRequest($request);
 
         if ($form->isValid()) {
-
             $content = Extractor::extract($entry->getUrl());
 
             $entry->setTitle($content->getTitle());
@@ -63,10 +59,10 @@ class EntryController extends Controller
      */
     public function showUnreadAction()
     {
-        $repository = $this->getDoctrine()->getRepository('WallabagCoreBundle:Entries');
-        // TODO don't give the user ID like this
         // TODO change pagination
-        $entries = $repository->findUnreadByUser(1, 0);
+        $entries = $this->getDoctrine()
+            ->getRepository('WallabagCoreBundle:Entry')
+            ->findUnreadByUser($this->getUser()->getId(), 0);
 
         return $this->render(
             'WallabagCoreBundle:Entry:entries.html.twig',
@@ -82,10 +78,10 @@ class EntryController extends Controller
      */
     public function showArchiveAction()
     {
-        $repository = $this->getDoctrine()->getRepository('WallabagCoreBundle:Entries');
-        // TODO don't give the user ID like this
         // TODO change pagination
-        $entries = $repository->findArchiveByUser(1, 0);
+        $entries = $this->getDoctrine()
+            ->getRepository('WallabagCoreBundle:Entry')
+            ->findArchiveByUser($this->getUser()->getId(), 0);
 
         return $this->render(
             'WallabagCoreBundle:Entry:entries.html.twig',
@@ -101,10 +97,10 @@ class EntryController extends Controller
      */
     public function showStarredAction()
     {
-        $repository = $this->getDoctrine()->getRepository('WallabagCoreBundle:Entries');
-        // TODO don't give the user ID like this
         // TODO change pagination
-        $entries = $repository->findStarredByUser(1, 0);
+        $entries = $this->getDoctrine()
+            ->getRepository('WallabagCoreBundle:Entry')
+            ->findStarredByUser($this->getUser()->getId(), 0);
 
         return $this->render(
             'WallabagCoreBundle:Entry:entries.html.twig',
@@ -115,11 +111,11 @@ class EntryController extends Controller
     /**
      * Shows entry content
      *
-     * @param Entries $entry
+     * @param  Entry                                      $entry
      * @Route("/view/{id}", requirements={"id" = "\d+"}, name="view")
      * @return \Symfony\Component\HttpFoundation\Response
      */
-    public function viewAction(Entries $entry)
+    public function viewAction(Entry $entry)
     {
         return $this->render(
             'WallabagCoreBundle:Entry:entry.html.twig',
@@ -130,12 +126,12 @@ class EntryController extends Controller
     /**
      * Changes read status for an entry
      *
-     * @param Request $request
-     * @param Entries $entry
+     * @param  Request                                            $request
+     * @param  Entry                                              $entry
      * @Route("/archive/{id}", requirements={"id" = "\d+"}, name="archive_entry")
      * @return \Symfony\Component\HttpFoundation\RedirectResponse
      */
-    public function toggleArchiveAction(Request $request, Entries $entry)
+    public function toggleArchiveAction(Request $request, Entry $entry)
     {
         $entry->toggleArchive();
         $this->getDoctrine()->getManager()->flush();
@@ -151,12 +147,12 @@ class EntryController extends Controller
     /**
      * Changes favorite status for an entry
      *
-     * @param Request $request
-     * @param Entries $entry
+     * @param  Request                                            $request
+     * @param  Entry                                              $entry
      * @Route("/star/{id}", requirements={"id" = "\d+"}, name="star_entry")
      * @return \Symfony\Component\HttpFoundation\RedirectResponse
      */
-    public function toggleStarAction(Request $request, Entries $entry)
+    public function toggleStarAction(Request $request, Entry $entry)
     {
         $entry->toggleStar();
         $this->getDoctrine()->getManager()->flush();
@@ -172,15 +168,16 @@ class EntryController extends Controller
     /**
      * Deletes entry
      *
-     * @param Request $request
-     * @param Entries $entry
+     * @param  Request                                            $request
+     * @param  Entry                                              $entry
      * @Route("/delete/{id}", requirements={"id" = "\d+"}, name="delete_entry")
      * @return \Symfony\Component\HttpFoundation\RedirectResponse
      */
-    public function deleteEntryAction(Request $request, Entries $entry)
+    public function deleteEntryAction(Request $request, Entry $entry)
     {
         $em = $this->getDoctrine()->getManager();
-        $em->remove($entry);
+        $entry->setDeleted(1);
+        $em->persist($entry);
         $em->flush();
 
         $this->get('session')->getFlashBag()->add(