@@ 61-95 (lines=35) @@ | ||
58 | * |
|
59 | * @return Response |
|
60 | */ |
|
61 | public function editArticleAction($id, $action, Request $request) |
|
62 | { |
|
63 | $em = $this->getDoctrine()->getManager(); |
|
64 | if ($action == "edit") { |
|
65 | $article = $em->getRepository('AppBundle:Article') |
|
66 | ->find($id); |
|
67 | $title = 'Edit article id: '.$id; |
|
68 | } |
|
69 | else { |
|
70 | $article = new Article(); |
|
71 | $title = 'Create new article'; |
|
72 | } |
|
73 | ||
74 | $form = $this->createForm(ArticleType::class, $article, [ |
|
75 | 'em' => $em, |
|
76 | 'action' => $this->generateUrl('articleEdit', ['action' => $action, 'id' => $id]), |
|
77 | 'method' => Request::METHOD_POST, |
|
78 | ]) |
|
79 | ->add('save', SubmitType::class, array('label' => 'Save')); |
|
80 | ||
81 | if ($request->getMethod() == 'POST') { |
|
82 | $form->handleRequest($request); |
|
83 | if ($form->isValid()) { |
|
84 | $em->persist($article); |
|
85 | $em->flush(); |
|
86 | ||
87 | return $this->redirectToRoute('articlesAdmin'); |
|
88 | } |
|
89 | } |
|
90 | ||
91 | return [ |
|
92 | 'title' => $title, |
|
93 | 'form' => $form->createView(), |
|
94 | ]; |
|
95 | } |
|
96 | ||
97 | /** |
|
98 | * @param $id |
@@ 62-97 (lines=36) @@ | ||
59 | * |
|
60 | * @return Response |
|
61 | */ |
|
62 | public function editRoleAction($id, $action, Request $request) |
|
63 | { |
|
64 | $em = $this->getDoctrine()->getManager(); |
|
65 | if ($action == "edit") { |
|
66 | $role = $em->getRepository('AppBundle:Role') |
|
67 | ->find($id); |
|
68 | $title = 'Edit role id: '.$id; |
|
69 | } |
|
70 | else { |
|
71 | $role = new Role(); |
|
72 | $title = 'Create new role'; |
|
73 | } |
|
74 | ||
75 | ||
76 | $form = $this->createForm(RoleType::class, $role, [ |
|
77 | 'em' => $em, |
|
78 | 'action' => $this->generateUrl('roleEdit', ['action' => $action, 'id' => $id]), |
|
79 | 'method' => Request::METHOD_POST, |
|
80 | ]) |
|
81 | ->add('save', SubmitType::class, array('label' => 'Save')); |
|
82 | ||
83 | if ($request->getMethod() == 'POST') { |
|
84 | $form->handleRequest($request); |
|
85 | if ($form->isValid()) { |
|
86 | $em->persist($role); |
|
87 | $em->flush(); |
|
88 | ||
89 | return $this->redirectToRoute('rolesAdmin'); |
|
90 | } |
|
91 | } |
|
92 | ||
93 | return [ |
|
94 | 'title' => $title, |
|
95 | 'form' => $form->createView(), |
|
96 | ]; |
|
97 | } |
|
98 | ||
99 | /** |
|
100 | * @param $id |
@@ 62-97 (lines=36) @@ | ||
59 | * |
|
60 | * @return Response |
|
61 | */ |
|
62 | public function editUserAction($id, $action, Request $request) |
|
63 | { |
|
64 | $em = $this->getDoctrine()->getManager(); |
|
65 | if ($action == "edit") { |
|
66 | $user = $em->getRepository('AppBundle:User') |
|
67 | ->find($id); |
|
68 | $title = 'Edit user id: '.$id; |
|
69 | } |
|
70 | else { |
|
71 | $user = new User(); |
|
72 | $title = 'Create new user'; |
|
73 | } |
|
74 | ||
75 | ||
76 | $form = $this->createForm(UserType::class, $user, [ |
|
77 | 'em' => $em, |
|
78 | 'action' => $this->generateUrl('userEdit', ['action' => $action, 'id' => $id]), |
|
79 | 'method' => Request::METHOD_POST, |
|
80 | ]) |
|
81 | ->add('save', SubmitType::class, array('label' => 'Save')); |
|
82 | ||
83 | if ($request->getMethod() == 'POST') { |
|
84 | $form->handleRequest($request); |
|
85 | if ($form->isValid()) { |
|
86 | $em->persist($user); |
|
87 | $em->flush(); |
|
88 | ||
89 | return $this->redirectToRoute('usersAdmin'); |
|
90 | } |
|
91 | } |
|
92 | ||
93 | return [ |
|
94 | 'title' => $title, |
|
95 | 'form' => $form->createView(), |
|
96 | ]; |
|
97 | } |
|
98 | ||
99 | /** |
|
100 | * @param $id |