Code Duplication    Length = 146-147 lines in 2 locations

src/Kunstmaan/UserManagementBundle/Controller/GroupsController.php 1 location

@@ 25-171 (lines=147) @@
22
/**
23
 * Settings controller handling everything related to creating, editing, deleting and listing groups in an admin list
24
 */
25
class GroupsController extends BaseSettingsController
26
{
27
    /**
28
     * List groups
29
     *
30
     * @Route("/", name="KunstmaanUserManagementBundle_settings_groups")
31
     * @Template("KunstmaanAdminListBundle:Default:list.html.twig")
32
     *
33
     * @throws AccessDeniedException
34
     * @return array
35
     */
36
    public function listAction(Request $request)
37
    {
38
        $this->denyAccessUnlessGranted('ROLE_SUPER_ADMIN');
39
40
        /* @var $em EntityManager */
41
        $em = $this->getDoctrine()->getManager();
42
        /* @var AdminList $adminlist */
43
        $adminlist = $this->get("kunstmaan_adminlist.factory")->createList(new GroupAdminListConfigurator($em));
44
        $adminlist->bindRequest($request);
45
46
        return array(
47
            'adminlist' => $adminlist,
48
        );
49
    }
50
51
    /**
52
     * Add a group
53
     *
54
     * @Route("/add", name="KunstmaanUserManagementBundle_settings_groups_add")
55
     * @Method({"GET", "POST"})
56
     * @Template()
57
     *
58
     * @throws AccessDeniedException
59
     * @return array
60
     */
61
    public function addAction(Request $request)
62
    {
63
        $this->denyAccessUnlessGranted('ROLE_SUPER_ADMIN');
64
65
        /* @var $em EntityManager */
66
        $em = $this->getDoctrine()->getManager();
67
        $group = new Group();
68
        $form = $this->createForm(GroupType::class, $group);
69
70
        if ($request->isMethod('POST')) {
71
            $form->handleRequest($request);
72
            if ($form->isSubmitted() && $form->isValid()) {
73
                $em->persist($group);
74
                $em->flush();
75
76
                $this->addFlash(
77
                    FlashTypes::SUCCESS,
78
                    $this->get('translator')->trans('kuma_user.group.add.flash.success', array(
79
                        '%groupname%' => $group->getName()
80
                    ))
81
                );
82
83
                return new RedirectResponse($this->generateUrl('KunstmaanUserManagementBundle_settings_groups'));
84
            }
85
        }
86
87
        return array(
88
            'form' => $form->createView(),
89
        );
90
    }
91
92
    /**
93
     * Edit a group
94
     *
95
     * @param int $id
96
     *
97
     * @Route("/{id}/edit", requirements={"id" = "\d+"}, name="KunstmaanUserManagementBundle_settings_groups_edit")
98
     * @Method({"GET", "POST"})
99
     * @Template()
100
     *
101
     * @throws AccessDeniedException
102
     * @return array
103
     */
104
    public function editAction(Request $request, $id)
105
    {
106
        $this->denyAccessUnlessGranted('ROLE_SUPER_ADMIN');
107
108
        /* @var $em EntityManager */
109
        $em = $this->getDoctrine()->getManager();
110
        /* @var Group $group */
111
        $group = $em->getRepository('KunstmaanAdminBundle:Group')->find($id);
112
        $form = $this->createForm(GroupType::class, $group);
113
114
        if ($request->isMethod('POST')) {
115
            $form->handleRequest($request);
116
            if ($form->isSubmitted() && $form->isValid()) {
117
                $em->persist($group);
118
                $em->flush();
119
120
                $this->addFlash(
121
                    FlashTypes::SUCCESS,
122
                    $this->get('translator')->trans('kuma_user.group.edit.flash.success', array(
123
                        '%groupname%' => $group->getName()
124
                    ))
125
                );
126
127
                return new RedirectResponse($this->generateUrl('KunstmaanUserManagementBundle_settings_groups'));
128
            }
129
        }
130
131
        return array(
132
            'form'  => $form->createView(),
133
            'group' => $group
134
        );
135
    }
136
137
    /**
138
     * Delete a group
139
     *
140
     * @param int $id
141
     *
142
     * @Route("/{id}/delete", requirements={"id" = "\d+"}, name="KunstmaanUserManagementBundle_settings_groups_delete")
143
     * @Method({"GET", "POST"})
144
     * @Template()
145
     *
146
     * @throws AccessDeniedException
147
     * @return RedirectResponse
148
     */
149
    public function deleteAction($id)
150
    {
151
        $this->denyAccessUnlessGranted('ROLE_SUPER_ADMIN');
152
153
        /* @var $em EntityManager */
154
        $em = $this->getDoctrine()->getManager();
155
        $group = $em->getRepository('KunstmaanAdminBundle:Group')->find($id);
156
        if (!is_null($group)) {
157
            $em->remove($group);
158
            $em->flush();
159
160
            $this->addFlash(
161
                FlashTypes::SUCCESS,
162
                $this->get('translator')->trans('kuma_user.group.delete.flash.success', array(
163
                    '%groupname%' => $group->getName()
164
                ))
165
            );
166
        }
167
168
        return new RedirectResponse($this->generateUrl('KunstmaanUserManagementBundle_settings_groups'));
169
    }
170
171
}
172

src/Kunstmaan/UserManagementBundle/Controller/RolesController.php 1 location

@@ 23-168 (lines=146) @@
20
/**
21
 * Settings controller handling everything related to creating, editing, deleting and listing roles in an admin list
22
 */
23
class RolesController extends BaseSettingsController
24
{
25
    /**
26
     * List roles
27
     *
28
     * @Route   ("/", name="KunstmaanUserManagementBundle_settings_roles")
29
     * @Template("KunstmaanAdminListBundle:Default:list.html.twig")
30
     *
31
     * @throws AccessDeniedException
32
     * @return array
33
     */
34
    public function listAction(Request $request)
35
    {
36
        $this->denyAccessUnlessGranted('ROLE_SUPER_ADMIN');
37
38
        $em        = $this->getDoctrine()->getManager();
39
        /* @var AdminList $adminlist */
40
        $adminlist = $this->get("kunstmaan_adminlist.factory")->createList(new RoleAdminListConfigurator($em));
41
        $adminlist->bindRequest($request);
42
43
        return array(
44
            'adminlist' => $adminlist,
45
        );
46
    }
47
48
    /**
49
     * Add a role
50
     *
51
     * @Route("/add", name="KunstmaanUserManagementBundle_settings_roles_add")
52
     * @Method({"GET", "POST"})
53
     * @Template()
54
     *
55
     * @throws AccessDeniedException
56
     * @return array|RedirectResponse
57
     */
58
    public function addAction(Request $request)
59
    {
60
        $this->denyAccessUnlessGranted('ROLE_SUPER_ADMIN');
61
62
        /* @var $em EntityManager */
63
        $em = $this->getDoctrine()->getManager();
64
        $role = new Role('');
65
        $form = $this->createForm(RoleType::class, $role);
66
67
        if ($request->isMethod('POST')) {
68
            $form->handleRequest($request);
69
            if ($form->isSubmitted() && $form->isValid()) {
70
                $em->persist($role);
71
                $em->flush();
72
73
                $this->addFlash(
74
                    FlashTypes::SUCCESS,
75
                    $this->get('translator')->trans('kuma_user.roles.add.flash.success.%role%', [
76
                        '%role%' => $role->getRole()
77
                    ])
78
                );
79
80
                return new RedirectResponse($this->generateUrl('KunstmaanUserManagementBundle_settings_roles'));
81
            }
82
        }
83
84
        return array(
85
            'form' => $form->createView(),
86
        );
87
    }
88
89
    /**
90
     * Edit a role
91
     *
92
     * @param int $id
93
     *
94
     * @Route("/{id}/edit", requirements={"id" = "\d+"}, name="KunstmaanUserManagementBundle_settings_roles_edit")
95
     * @Method({"GET", "POST"})
96
     * @Template()
97
     *
98
     * @throws AccessDeniedException
99
     * @return array|RedirectResponse
100
     */
101
    public function editAction(Request $request, $id)
102
    {
103
        $this->denyAccessUnlessGranted('ROLE_SUPER_ADMIN');
104
105
        /* @var $em EntityManager */
106
        $em = $this->getDoctrine()->getManager();
107
        /* @var Role $role */
108
        $role = $em->getRepository('KunstmaanAdminBundle:Role')->find($id);
109
        $form = $this->createForm(RoleType::class, $role);
110
111
        if ($request->isMethod('POST')) {
112
            $form->handleRequest($request);
113
            if ($form->isSubmitted() && $form->isValid()) {
114
                $em->persist($role);
115
                $em->flush();
116
117
                $this->addFlash(
118
                    FlashTypes::SUCCESS,
119
                    $this->get('translator')->trans('kuma_user.roles.edit.flash.success.%role%', [
120
                        '%role%' => $role->getRole()
121
                    ])
122
                );
123
124
                return new RedirectResponse($this->generateUrl('KunstmaanUserManagementBundle_settings_roles'));
125
            }
126
        }
127
128
        return array(
129
            'form' => $form->createView(),
130
            'role' => $role
131
        );
132
    }
133
134
    /**
135
     * Delete a role
136
     *
137
     * @param int $id
138
     *
139
     * @Route ("/{id}/delete", requirements={"id" = "\d+"}, name="KunstmaanUserManagementBundle_settings_roles_delete")
140
     * @Method({"GET", "POST"})
141
     *
142
     * @throws AccessDeniedException
143
     * @return RedirectResponse
144
     */
145
    public function deleteAction($id)
146
    {
147
        $this->denyAccessUnlessGranted('ROLE_SUPER_ADMIN');
148
149
        /* @var $em EntityManager */
150
        $em = $this->getDoctrine()->getManager();
151
        /* @var Role $role */
152
        $role = $em->getRepository('KunstmaanAdminBundle:Role')->find($id);
153
        if (!is_null($role)) {
154
            $em->remove($role);
155
            $em->flush();
156
157
            $this->addFlash(
158
                FlashTypes::SUCCESS,
159
                $this->get('translator')->trans('kuma_user.roles.delete.flash.success.%role%', [
160
                    '%role%' => $role->getRole()
161
                ])
162
            );
163
        }
164
165
        return new RedirectResponse($this->generateUrl('KunstmaanUserManagementBundle_settings_roles'));
166
    }
167
168
}
169