]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/CoreBundle/Controller/EntryController.php
Merge branch 'v2-edit-title' into v2
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Controller / EntryController.php
index 89677befb6c347a003429513392254ee2fe1e00c..4a7a0644a364b851942537b2b9fe44c65d2c3357 100644 (file)
@@ -7,7 +7,8 @@ use Symfony\Bundle\FrameworkBundle\Controller\Controller;
 use Symfony\Component\HttpFoundation\Request;
 use Wallabag\CoreBundle\Entity\Entry;
 use Wallabag\CoreBundle\Service\Extractor;
-use Wallabag\CoreBundle\Helper\Url;
+use Wallabag\CoreBundle\Form\Type\NewEntryType;
+use Wallabag\CoreBundle\Form\Type\EditEntryType;
 
 class EntryController extends Controller
 {
@@ -22,10 +23,7 @@ class EntryController extends Controller
     {
         $entry = new Entry($this->getUser());
 
-        $form = $this->createFormBuilder($entry)
-            ->add('url', 'url')
-            ->add('save', 'submit')
-            ->getForm();
+        $form = $this->createForm(new NewEntryType(), $entry);
 
         $form->handleRequest($request);
 
@@ -53,7 +51,43 @@ class EntryController extends Controller
     }
 
     /**
-     * Shows unread entries for current user
+     * Edit an entry content.
+     *
+     * @param Request $request
+     * @param Entry   $entry
+     *
+     * @Route("/edit/{id}", requirements={"id" = "\d+"}, name="edit")
+     *
+     * @return \Symfony\Component\HttpFoundation\Response
+     */
+    public function editEntryAction(Request $request, Entry $entry)
+    {
+        $this->checkUserAction($entry);
+
+        $form = $this->createForm(new EditEntryType(), $entry);
+
+        $form->handleRequest($request);
+
+        if ($form->isValid()) {
+            $em = $this->getDoctrine()->getManager();
+            $em->persist($entry);
+            $em->flush();
+
+            $this->get('session')->getFlashBag()->add(
+                'notice',
+                'Entry updated'
+            );
+
+            return $this->redirect($this->generateUrl('view', array('id' => $entry->getId())));
+        }
+
+        return $this->render('WallabagCoreBundle:Entry:edit.html.twig', array(
+            'form' => $form->createView(),
+        ));
+    }
+
+    /**
+     * Shows unread entries for current user.
      *
      * @Route("/unread", name="unread")
      *
@@ -73,7 +107,7 @@ class EntryController extends Controller
     }
 
     /**
-     * Shows read entries for current user
+     * Shows read entries for current user.
      *
      * @Route("/archive", name="archive")
      *
@@ -93,7 +127,7 @@ class EntryController extends Controller
     }
 
     /**
-     * Shows starred entries for current user
+     * Shows starred entries for current user.
      *
      * @Route("/starred", name="starred")
      *
@@ -113,7 +147,7 @@ class EntryController extends Controller
     }
 
     /**
-     * Shows entry content
+     * Shows entry content.
      *
      * @param Entry $entry
      *
@@ -132,7 +166,7 @@ class EntryController extends Controller
     }
 
     /**
-     * Changes read status for an entry
+     * Changes read status for an entry.
      *
      * @param Request $request
      * @param Entry   $entry
@@ -157,7 +191,7 @@ class EntryController extends Controller
     }
 
     /**
-     * Changes favorite status for an entry
+     * Changes favorite status for an entry.
      *
      * @param Request $request
      * @param Entry   $entry
@@ -182,7 +216,7 @@ class EntryController extends Controller
     }
 
     /**
-     * Deletes entry
+     * Deletes entry.
      *
      * @param Request $request
      * @param Entry   $entry
@@ -195,8 +229,9 @@ class EntryController extends Controller
     {
         $this->checkUserAction($entry);
 
-        $entry->setDeleted(1);
-        $this->getDoctrine()->getManager()->flush();
+        $em = $this->getDoctrine()->getManager();
+        $em->remove($entry);
+        $em->flush();
 
         $this->get('session')->getFlashBag()->add(
             'notice',
@@ -207,14 +242,14 @@ class EntryController extends Controller
     }
 
     /**
-     * Check if the logged user can manage the given entry
+     * Check if the logged user can manage the given entry.
      *
      * @param Entry $entry
      */
     private function checkUserAction(Entry $entry)
     {
         if ($this->getUser()->getId() != $entry->getUser()->getId()) {
-            throw $this->createAccessDeniedException('You can not use this entry.');
+            throw $this->createAccessDeniedException('You can not access this entry.');
         }
     }
 }