1: <?php
2: namespace Mapbender\CoreBundle\Controller;
3: use Symfony\Bundle\FrameworkBundle\Controller\Controller;
4: use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
5: use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
6: use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
7: use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
8: use Mapbender\CoreBundle\Entity\Group;
9: use Mapbender\CoreBundle\Form\GroupType;
10:
11: 12: 13: 14: 15:
16: class GroupController extends Controller {
17:
18: 19: 20: 21: 22: 23:
24: public function indexAction(array $groupList) {
25: return array(
26: "groupList" => $groupList
27: );
28: }
29:
30: 31: 32: 33: 34:
35: public function createAction() {
36: $form = $this->get("form.factory")->create(
37: new GroupType(),
38: new Group()
39: );
40:
41:
42: return array(
43: "form" => $form->createView()
44: );
45: }
46:
47: 48: 49: 50:
51: public function addAction() {
52: $group = new Group();
53:
54: $form = $this->get("form.factory")->create(
55: new GroupType(),
56: $group
57: );
58:
59: $request = $this->get("request");
60:
61: $form->bindRequest($request);
62:
63: if($form->isValid()) {
64: $em = $this->getDoctrine()->getEntityManager();
65: $em->persist($group);
66: $em->flush();
67: return $this->redirect($this->generateUrl("mapbender_core_group_index"));
68: } else {
69: return $this->render(
70: "MapbenderCoreBundle:Group:create.html.twig",
71: array("form" => $form->createView())
72: );
73: }
74: }
75:
76:
77: 78: 79: 80: 81:
82: public function editAction(Group $group) {
83: $form = $this->get("form.factory")->create(
84: new GroupType(),
85: $group
86: );
87:
88: return array(
89: "form" => $form->createView(),
90: "group" => $group
91: );
92: }
93:
94: 95: 96: 97:
98: public function deleteAction(Group $group) {
99: $em = $this->getDoctrine()->getEntityManager();
100: try {
101: $em->remove($group);
102: $em->flush();
103: } catch(\Exception $E) {
104: $this->get("logger")->info("Could not delete group. ".$E->getMessage());
105: $this->get("session")->setFlash("error","Could not delete group.");
106: return $this->redirect($this->generateUrl("mapbender_core_group_index"));
107: }
108:
109: $this->get("session")->setFlash("success","Your group has been deleted.");
110: return $this->redirect($this->generateUrl("mapbender_core_group_index"));
111: }
112:
113: 114: 115: 116: 117:
118: public function confirmdeleteAction(Group $group) {
119:
120: return array(
121: "group" => $group
122: );
123: }
124:
125: 126: 127: 128:
129: public function saveAction(Group $group) {
130: $form = $this->get("form.factory")->create(
131: new GroupType(),
132: $group
133: );
134:
135: $request = $this->get("request");
136:
137: $form->bindRequest($request);
138:
139: if($form->isValid()) {
140: try {
141: $em = $this->getDoctrine()->getEntityManager();
142: $em->persist($group);
143: $em->flush();
144: } catch(\Exception $E) {
145: $this->get("logger")->err("Could not save group. ".$E->getMessage());
146: $this->get("session")->setFlash("error","Could not save group");
147: return $this->redirect($this->generateUrl("mapbender_core_group_edit",array("groupId" => $group->getId())));
148: }
149: return $this->redirect($this->generateUrl("mapbender_core_group_index"));
150: } else {
151: return $this->render(
152: "MapbenderCoreBundle:Group:edit.html.twig",
153: array(
154: "form" => $form->createView(),
155: "group" => $group
156: )
157: );
158: }
159: }
160: }
161: