3 namespace Wallabag\GroupBundle\Controller
;
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
;
14 class ManageController
extends Controller
17 * Lists all Group entities.
19 * @Route("/", name="group_index")
22 public function indexAction()
24 $em = $this->getDoctrine()->getManager();
26 $groups = $em->getRepository('WallabagGroupBundle:Group')->findAll();
28 return $this->render('WallabagGroupBundle:Manage:index.html.twig', array(
34 * Creates a new Group entity.
36 * @Route("/new", name="group_new")
37 * @Method({"GET", "POST"})
39 public function newAction(Request
$request)
41 $group = new Group('');
43 $form = $this->createForm('Wallabag\GroupBundle\Form\NewGroupType', $group);
44 $form->handleRequest($request);
46 if ($form->isSubmitted() && $form->isValid()) {
47 $em = $this->getDoctrine()->getManager();
51 $this->get('session')->getFlashBag()->add(
53 $this->get('translator')->trans('flashes.group.notice.added', ['%name%' => $group->getName()])
56 return $this->redirectToRoute('group_edit', array('id' => $group->getId()));
59 return $this->render('WallabagGroupBundle:Manage:new.html.twig', array(
61 'form' => $form->createView(),
66 * Displays a form to edit an existing Group entity.
68 * @Route("/{id}/edit", name="group_edit")
69 * @Method({"GET", "POST"})
71 public function editAction(Request
$request, Group
$group)
73 $deleteForm = $this->createDeleteForm($group);
74 $editForm = $this->createForm('Wallabag\GroupBundle\Form\GroupType', $group);
75 $editForm->handleRequest($request);
77 if ($editForm->isSubmitted() && $editForm->isValid()) {
78 $em = $this->getDoctrine()->getManager();
82 $this->get('session')->getFlashBag()->add(
84 $this->get('translator')->trans('flashes.group.notice.updated', ['%name%' => $group->getName()])
87 return $this->redirectToRoute('group_edit', array('id' => $group->getId()));
90 return $this->render('WallabagGroupBundle:Manage:edit.html.twig', array(
92 'edit_form' => $editForm->createView(),
93 'delete_form' => $deleteForm->createView(),
98 * Deletes a Group entity.
100 * @Route("/{id}", name="group_delete")
103 public function deleteAction(Request
$request, Group
$group)
105 $form = $this->createDeleteForm($group);
106 $form->handleRequest($request);
108 if ($form->isSubmitted() && $form->isValid()) {
109 $this->get('session')->getFlashBag()->add(
111 $this->get('translator')->trans('flashes.group.notice.deleted', ['%name%' => $group->getName()])
114 $em = $this->getDoctrine()->getManager();
119 return $this->redirectToRoute('group_index');
123 * Creates a form to delete a Group entity.
125 * @param Group $group The Group entity
127 * @return \Symfony\Component\Form\Form The form
129 private function createDeleteForm(Group
$group)
131 return $this->createFormBuilder()
132 ->setAction($this->generateUrl('group_delete', array('id' => $group->getId())))
133 ->setMethod('DELETE')