|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace AppBundle\Controller\Admin; |
|
4
|
|
|
|
|
5
|
|
|
use AppBundle\Entity\District; |
|
6
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
|
7
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
|
8
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
9
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; |
|
10
|
|
|
use AppBundle\Form\DistrictType; |
|
11
|
|
|
use Symfony\Component\Form\Extension\Core\Type\SubmitType; |
|
12
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; |
|
13
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
14
|
|
|
|
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @Route("/admin") |
|
18
|
|
|
*/ |
|
19
|
|
|
class AdminDistrictController extends Controller |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @Route("/districts", name="admin_districts") |
|
23
|
|
|
* @Method("GET") |
|
24
|
|
|
*/ |
|
25
|
|
|
public function districtsAction(Request $request) |
|
26
|
|
|
{ |
|
27
|
|
|
$districts = $this->getDoctrine()->getRepository('AppBundle:District')->findAll(); |
|
28
|
|
|
return $this->render('@App/admin/district/districts.html.twig', array('districts' => $districts)); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @Route("/district/show/{slug}", name="admin_district_show") |
|
33
|
|
|
* @Method("GET") |
|
34
|
|
|
* @ParamConverter("district", options={"mapping": {"slug": "slug"}}) |
|
35
|
|
|
*/ |
|
36
|
|
|
public function estateShowAction(District $district, Request $request) |
|
37
|
|
|
{ |
|
38
|
|
|
$deleteForm = $this->createDeleteForm($district); |
|
39
|
|
|
return $this->render('@App/admin/district/show_district.html.twig', array( |
|
40
|
|
|
'district' => $district, |
|
41
|
|
|
'delete_form' => $deleteForm->createView(), |
|
42
|
|
|
)); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @Route("/district/new", name="admin_district_new") |
|
47
|
|
|
* @Method({"GET", "POST"}) |
|
48
|
|
|
*/ |
|
49
|
|
|
public function newDistrictAction(Request $request) |
|
50
|
|
|
{ |
|
51
|
|
|
$entityManager = $this->getDoctrine()->getManager(); |
|
52
|
|
|
$district = new District(); |
|
53
|
|
|
//$this->denyAccessUnlessGranted('create', $estate); |
|
|
|
|
|
|
54
|
|
|
$form = $this->createForm(DistrictType::class, $district)->add('saveAndCreateNew', SubmitType::class); |
|
55
|
|
|
$form->handleRequest($request); |
|
56
|
|
|
if ($form->isSubmitted() && $form->isValid()) { |
|
57
|
|
|
$entityManager->persist($district); |
|
58
|
|
|
$entityManager->flush(); |
|
59
|
|
|
$nextAction = $form->get('saveAndCreateNew')->isClicked() |
|
|
|
|
|
|
60
|
|
|
? 'admin_district_new' |
|
61
|
|
|
: 'admin_districts'; |
|
62
|
|
|
return $this->redirectToRoute($nextAction); |
|
63
|
|
|
} |
|
64
|
|
|
return $this->render('@App/admin/district/new_district.html.twig', array( |
|
65
|
|
|
'district' => $district, |
|
66
|
|
|
'form' => $form->createView(), |
|
67
|
|
|
)); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @Route("/district/edit/{slug}", name="admin_district_edit") |
|
72
|
|
|
* @Method({"GET", "POST"}) |
|
73
|
|
|
* @ParamConverter("district", options={"mapping": {"slug": "slug"}}) |
|
74
|
|
|
*/ |
|
75
|
|
|
public function estateEditAction(District $district, Request $request) |
|
76
|
|
|
{ |
|
77
|
|
|
$entityManager = $this->getDoctrine()->getManager(); |
|
78
|
|
|
$editForm = $this->createForm(DistrictType::class, $district); |
|
79
|
|
|
$deleteForm = $this->createDeleteForm($district); |
|
80
|
|
|
$editForm->handleRequest($request); |
|
81
|
|
|
if ($editForm->isSubmitted() && $editForm->isValid()) { |
|
82
|
|
|
$entityManager->persist($district); |
|
83
|
|
|
$entityManager->flush(); |
|
84
|
|
|
return $this->redirectToRoute('admin_districts'); |
|
85
|
|
|
} |
|
86
|
|
|
return $this->render('@App/admin/district/edit_district.html.twig', array( |
|
87
|
|
|
'district' => $district, |
|
88
|
|
|
'edit_form' => $editForm->createView(), |
|
89
|
|
|
'delete_form' => $deleteForm->createView(), |
|
90
|
|
|
)); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* @Route("/district/delete/{slug}", name="admin_district_delete") |
|
95
|
|
|
* @Method("DELETE") |
|
96
|
|
|
* @ParamConverter("district", options={"mapping": {"slug": "slug"}}) |
|
97
|
|
|
*/ |
|
98
|
|
View Code Duplication |
public function DistrictDeleteAction(Request $request, District $district) |
|
|
|
|
|
|
99
|
|
|
{ |
|
100
|
|
|
$form = $this->createDeleteForm($district); |
|
101
|
|
|
$form->handleRequest($request); |
|
102
|
|
|
if ($form->isSubmitted() && $form->isValid()) { |
|
103
|
|
|
$entityManager = $this->getDoctrine()->getManager(); |
|
104
|
|
|
|
|
105
|
|
|
$entityManager->remove($district); |
|
106
|
|
|
$entityManager->flush(); |
|
107
|
|
|
} |
|
108
|
|
|
return $this->redirectToRoute('admin_districts'); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
View Code Duplication |
private function createDeleteForm(District $district) |
|
|
|
|
|
|
112
|
|
|
{ |
|
113
|
|
|
return $this->createFormBuilder() |
|
114
|
|
|
->setAction($this->generateUrl('admin_district_delete', array('slug' => $district->getSlug()))) |
|
115
|
|
|
->setMethod('DELETE') |
|
116
|
|
|
->getForm() |
|
117
|
|
|
; |
|
118
|
|
|
} |
|
119
|
|
|
} |
|
120
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.