diff options
Diffstat (limited to 'src/Wallabag/CoreBundle/Controller')
-rw-r--r-- | src/Wallabag/CoreBundle/Controller/EntryController.php | 43 |
1 files changed, 40 insertions, 3 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php index 7fd982c9..4a7a0644 100644 --- a/src/Wallabag/CoreBundle/Controller/EntryController.php +++ b/src/Wallabag/CoreBundle/Controller/EntryController.php | |||
@@ -7,7 +7,8 @@ use Symfony\Bundle\FrameworkBundle\Controller\Controller; | |||
7 | use Symfony\Component\HttpFoundation\Request; | 7 | use Symfony\Component\HttpFoundation\Request; |
8 | use Wallabag\CoreBundle\Entity\Entry; | 8 | use Wallabag\CoreBundle\Entity\Entry; |
9 | use Wallabag\CoreBundle\Service\Extractor; | 9 | use Wallabag\CoreBundle\Service\Extractor; |
10 | use Wallabag\CoreBundle\Form\Type\EntryType; | 10 | use Wallabag\CoreBundle\Form\Type\NewEntryType; |
11 | use Wallabag\CoreBundle\Form\Type\EditEntryType; | ||
11 | 12 | ||
12 | class EntryController extends Controller | 13 | class EntryController extends Controller |
13 | { | 14 | { |
@@ -22,7 +23,7 @@ class EntryController extends Controller | |||
22 | { | 23 | { |
23 | $entry = new Entry($this->getUser()); | 24 | $entry = new Entry($this->getUser()); |
24 | 25 | ||
25 | $form = $this->createForm(new EntryType(), $entry); | 26 | $form = $this->createForm(new NewEntryType(), $entry); |
26 | 27 | ||
27 | $form->handleRequest($request); | 28 | $form->handleRequest($request); |
28 | 29 | ||
@@ -50,6 +51,42 @@ class EntryController extends Controller | |||
50 | } | 51 | } |
51 | 52 | ||
52 | /** | 53 | /** |
54 | * Edit an entry content. | ||
55 | * | ||
56 | * @param Request $request | ||
57 | * @param Entry $entry | ||
58 | * | ||
59 | * @Route("/edit/{id}", requirements={"id" = "\d+"}, name="edit") | ||
60 | * | ||
61 | * @return \Symfony\Component\HttpFoundation\Response | ||
62 | */ | ||
63 | public function editEntryAction(Request $request, Entry $entry) | ||
64 | { | ||
65 | $this->checkUserAction($entry); | ||
66 | |||
67 | $form = $this->createForm(new EditEntryType(), $entry); | ||
68 | |||
69 | $form->handleRequest($request); | ||
70 | |||
71 | if ($form->isValid()) { | ||
72 | $em = $this->getDoctrine()->getManager(); | ||
73 | $em->persist($entry); | ||
74 | $em->flush(); | ||
75 | |||
76 | $this->get('session')->getFlashBag()->add( | ||
77 | 'notice', | ||
78 | 'Entry updated' | ||
79 | ); | ||
80 | |||
81 | return $this->redirect($this->generateUrl('view', array('id' => $entry->getId()))); | ||
82 | } | ||
83 | |||
84 | return $this->render('WallabagCoreBundle:Entry:edit.html.twig', array( | ||
85 | 'form' => $form->createView(), | ||
86 | )); | ||
87 | } | ||
88 | |||
89 | /** | ||
53 | * Shows unread entries for current user. | 90 | * Shows unread entries for current user. |
54 | * | 91 | * |
55 | * @Route("/unread", name="unread") | 92 | * @Route("/unread", name="unread") |
@@ -212,7 +249,7 @@ class EntryController extends Controller | |||
212 | private function checkUserAction(Entry $entry) | 249 | private function checkUserAction(Entry $entry) |
213 | { | 250 | { |
214 | if ($this->getUser()->getId() != $entry->getUser()->getId()) { | 251 | if ($this->getUser()->getId() != $entry->getUser()->getId()) { |
215 | throw $this->createAccessDeniedException('You can not use this entry.'); | 252 | throw $this->createAccessDeniedException('You can not access this entry.'); |
216 | } | 253 | } |
217 | } | 254 | } |
218 | } | 255 | } |