diff options
Diffstat (limited to 'src/Wallabag/GroupBundle/Controller')
-rw-r--r-- | src/Wallabag/GroupBundle/Controller/ManageController.php | 137 |
1 files changed, 137 insertions, 0 deletions
diff --git a/src/Wallabag/GroupBundle/Controller/ManageController.php b/src/Wallabag/GroupBundle/Controller/ManageController.php new file mode 100644 index 00000000..7015a465 --- /dev/null +++ b/src/Wallabag/GroupBundle/Controller/ManageController.php | |||
@@ -0,0 +1,137 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Wallabag\GroupBundle\Controller; | ||
4 | |||
5 | use Symfony\Component\HttpFoundation\Request; | ||
6 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; | ||
7 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; | ||
8 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; | ||
9 | use Wallabag\GroupBundle\Entity\Group; | ||
10 | |||
11 | /** | ||
12 | * Group controller. | ||
13 | */ | ||
14 | class ManageController extends Controller | ||
15 | { | ||
16 | /** | ||
17 | * Lists all Group entities. | ||
18 | * | ||
19 | * @Route("/", name="group_index") | ||
20 | * @Method("GET") | ||
21 | */ | ||
22 | public function indexAction() | ||
23 | { | ||
24 | $em = $this->getDoctrine()->getManager(); | ||
25 | |||
26 | $groups = $em->getRepository('WallabagGroupBundle:Group')->findAll(); | ||
27 | |||
28 | return $this->render('WallabagGroupBundle:Manage:index.html.twig', array( | ||
29 | 'groups' => $groups, | ||
30 | )); | ||
31 | } | ||
32 | |||
33 | /** | ||
34 | * Creates a new Group entity. | ||
35 | * | ||
36 | * @Route("/new", name="group_new") | ||
37 | * @Method({"GET", "POST"}) | ||
38 | */ | ||
39 | public function newAction(Request $request) | ||
40 | { | ||
41 | $group = new Group(''); | ||
42 | |||
43 | $form = $this->createForm('Wallabag\GroupBundle\Form\NewGroupType', $group); | ||
44 | $form->handleRequest($request); | ||
45 | |||
46 | if ($form->isSubmitted() && $form->isValid()) { | ||
47 | $em = $this->getDoctrine()->getManager(); | ||
48 | $em->persist($group); | ||
49 | $em->flush(); | ||
50 | |||
51 | $this->get('session')->getFlashBag()->add( | ||
52 | 'notice', | ||
53 | $this->get('translator')->trans('flashes.group.notice.added', ['%name%' => $group->getName()]) | ||
54 | ); | ||
55 | |||
56 | return $this->redirectToRoute('group_edit', array('id' => $group->getId())); | ||
57 | } | ||
58 | |||
59 | return $this->render('WallabagGroupBundle:Manage:new.html.twig', array( | ||
60 | 'group' => $group, | ||
61 | 'form' => $form->createView(), | ||
62 | )); | ||
63 | } | ||
64 | |||
65 | /** | ||
66 | * Displays a form to edit an existing Group entity. | ||
67 | * | ||
68 | * @Route("/{id}/edit", name="group_edit") | ||
69 | * @Method({"GET", "POST"}) | ||
70 | */ | ||
71 | public function editAction(Request $request, Group $group) | ||
72 | { | ||
73 | $deleteForm = $this->createDeleteForm($group); | ||
74 | $editForm = $this->createForm('Wallabag\GroupBundle\Form\GroupType', $group); | ||
75 | $editForm->handleRequest($request); | ||
76 | |||
77 | if ($editForm->isSubmitted() && $editForm->isValid()) { | ||
78 | $em = $this->getDoctrine()->getManager(); | ||
79 | $em->persist($group); | ||
80 | $em->flush(); | ||
81 | |||
82 | $this->get('session')->getFlashBag()->add( | ||
83 | 'notice', | ||
84 | $this->get('translator')->trans('flashes.group.notice.updated', ['%name%' => $group->getName()]) | ||
85 | ); | ||
86 | |||
87 | return $this->redirectToRoute('group_edit', array('id' => $group->getId())); | ||
88 | } | ||
89 | |||
90 | return $this->render('WallabagGroupBundle:Manage:edit.html.twig', array( | ||
91 | 'group' => $group, | ||
92 | 'edit_form' => $editForm->createView(), | ||
93 | 'delete_form' => $deleteForm->createView(), | ||
94 | )); | ||
95 | } | ||
96 | |||
97 | /** | ||
98 | * Deletes a Group entity. | ||
99 | * | ||
100 | * @Route("/{id}", name="group_delete") | ||
101 | * @Method("DELETE") | ||
102 | */ | ||
103 | public function deleteAction(Request $request, Group $group) | ||
104 | { | ||
105 | $form = $this->createDeleteForm($group); | ||
106 | $form->handleRequest($request); | ||
107 | |||
108 | if ($form->isSubmitted() && $form->isValid()) { | ||
109 | $this->get('session')->getFlashBag()->add( | ||
110 | 'notice', | ||
111 | $this->get('translator')->trans('flashes.group.notice.deleted', ['%name%' => $group->getName()]) | ||
112 | ); | ||
113 | |||
114 | $em = $this->getDoctrine()->getManager(); | ||
115 | $em->remove($group); | ||
116 | $em->flush(); | ||
117 | } | ||
118 | |||
119 | return $this->redirectToRoute('group_index'); | ||
120 | } | ||
121 | |||
122 | /** | ||
123 | * Creates a form to delete a Group entity. | ||
124 | * | ||
125 | * @param Group $group The Group entity | ||
126 | * | ||
127 | * @return \Symfony\Component\Form\Form The form | ||
128 | */ | ||
129 | private function createDeleteForm(Group $group) | ||
130 | { | ||
131 | return $this->createFormBuilder() | ||
132 | ->setAction($this->generateUrl('group_delete', array('id' => $group->getId()))) | ||
133 | ->setMethod('DELETE') | ||
134 | ->getForm() | ||
135 | ; | ||
136 | } | ||
137 | } | ||