|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace AppBundle\Controller; |
|
4
|
|
|
|
|
5
|
|
|
use AppBundle\Entity\Estate; |
|
6
|
|
|
use AppBundle\Entity\File; |
|
7
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
|
8
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
|
9
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
10
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; |
|
11
|
|
|
use AppBundle\Form\EstateType; |
|
12
|
|
|
use Symfony\Component\Form\Extension\Core\Type\SubmitType; |
|
13
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; |
|
14
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
15
|
|
|
|
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @Route("/admin") |
|
19
|
|
|
*/ |
|
20
|
|
|
class AdminController extends Controller |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* @Route("/", name="admin_index") |
|
24
|
|
|
*/ |
|
25
|
|
|
public function indexAction(Request $request) |
|
26
|
|
|
{ |
|
27
|
|
|
// replace this example code with whatever you need |
|
28
|
|
|
return $this->render('AppBundle::admin/index.html.twig', array( |
|
29
|
|
|
'base_dir' => realpath($this->getParameter('kernel.root_dir') . '/..'), |
|
30
|
|
|
)); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @Route("/estates", name="admin_estates") |
|
35
|
|
|
* @Method("GET") |
|
36
|
|
|
*/ |
|
37
|
|
|
public function estatesAction(Request $request) |
|
38
|
|
|
{ |
|
39
|
|
|
$estates = $this->getDoctrine()->getRepository('AppBundle:Estate')->findAll(); |
|
40
|
|
|
$paginator = $this->get('knp_paginator'); |
|
41
|
|
|
$pagination = $paginator->paginate( |
|
42
|
|
|
$estates, |
|
43
|
|
|
$request->query->getInt('page', 1), |
|
44
|
|
|
20 |
|
45
|
|
|
); |
|
46
|
|
|
|
|
47
|
|
|
return $this->render('@App/admin/estates.html.twig', array('pagination' => $pagination)); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @Route("/estate/show/{slug}", name="admin_estate_show") |
|
52
|
|
|
* @Method("GET") |
|
53
|
|
|
*/ |
|
54
|
|
|
public function estateShowAction(Estate $estate, $slug) |
|
|
|
|
|
|
55
|
|
|
{ |
|
56
|
|
|
$estate = $this->getDoctrine()->getRepository('AppBundle:Estate')->findOneBy(array('slug' => $slug)); |
|
57
|
|
|
$deleteForm = $this->createDeleteForm($estate); |
|
58
|
|
|
return $this->render('@App/admin/show_estate.html.twig', array( |
|
59
|
|
|
'estate' => $estate, |
|
60
|
|
|
'delete_form' => $deleteForm->createView(), |
|
61
|
|
|
)); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @Route("/estate/edit/{slug}", name="admin_estate_edit") |
|
66
|
|
|
* @Method({"GET", "POST"}) |
|
67
|
|
|
*/ |
|
68
|
|
|
public function estateEditAction(Estate $estate, Request $request) |
|
69
|
|
|
{ |
|
70
|
|
|
$entityManager = $this->getDoctrine()->getManager(); |
|
71
|
|
|
$editForm = $this->createForm(EstateType::class, $estate); |
|
72
|
|
|
$deleteForm = $this->createDeleteForm($estate); |
|
73
|
|
|
$editForm->handleRequest($request); |
|
74
|
|
|
if ($editForm->isSubmitted() && $editForm->isValid()) { |
|
75
|
|
|
$estate = $this->get('app.file_manager')->fileManager($estate); |
|
76
|
|
|
$entityManager->persist($estate); |
|
77
|
|
|
$entityManager->flush(); |
|
78
|
|
|
return $this->redirectToRoute('admin_estate_show', array('slug' => $estate->getSlug())); |
|
79
|
|
|
} |
|
80
|
|
|
return $this->render('@App/admin/edit_estate.html.twig', array( |
|
81
|
|
|
'estate' => $estate, |
|
82
|
|
|
'edit_form' => $editForm->createView(), |
|
83
|
|
|
'delete_form' => $deleteForm->createView(), |
|
84
|
|
|
)); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* @Route("/estate/delete/{slug}", name="admin_estate_delete") |
|
89
|
|
|
* @Method("DELETE") |
|
90
|
|
|
*/ |
|
91
|
|
|
public function estateDeleteAction(Request $request, Estate $estate) |
|
92
|
|
|
{ |
|
93
|
|
|
$form = $this->createDeleteForm($estate); |
|
94
|
|
|
$form->handleRequest($request); |
|
95
|
|
|
|
|
96
|
|
|
if ($form->isSubmitted() && $form->isValid()) { |
|
97
|
|
|
$entityManager = $this->getDoctrine()->getManager(); |
|
98
|
|
|
|
|
99
|
|
|
$entityManager->remove($estate); |
|
100
|
|
|
$entityManager->flush(); |
|
101
|
|
|
} |
|
102
|
|
|
return $this->redirectToRoute('admin_index'); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
private function createDeleteForm(Estate $estate) |
|
106
|
|
|
{ |
|
107
|
|
|
return $this->createFormBuilder() |
|
108
|
|
|
->setAction($this->generateUrl('admin_estate_delete', array('slug' => $estate->getSlug()))) |
|
109
|
|
|
->setMethod('DELETE') |
|
110
|
|
|
->getForm() |
|
111
|
|
|
; |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* @Route("/estate/new", name="admin_estate_new") |
|
117
|
|
|
* @Method({"GET", "POST"}) |
|
118
|
|
|
*/ |
|
119
|
|
|
public function newEstateAction(Request $request) |
|
120
|
|
|
{ |
|
121
|
|
|
$entityManager = $this->getDoctrine()->getManager(); |
|
122
|
|
|
$estate = new Estate(); |
|
123
|
|
|
//$this->denyAccessUnlessGranted('create', $estate); |
|
|
|
|
|
|
124
|
|
|
$form = $this->createForm(EstateType::class, $estate)->add('saveAndCreateNew', SubmitType::class); |
|
125
|
|
|
$form->handleRequest($request); |
|
126
|
|
|
if ($form->isSubmitted() && $form->isValid()) { |
|
127
|
|
|
$estate = $this->get('app.file_manager')->fileManager($estate); |
|
128
|
|
|
$entityManager->persist($estate); |
|
129
|
|
|
$entityManager->flush(); |
|
130
|
|
|
$nextAction = $form->get('saveAndCreateNew')->isClicked() |
|
|
|
|
|
|
131
|
|
|
? 'admin_estate_new' |
|
132
|
|
|
: 'admin_index'; |
|
133
|
|
|
return $this->redirectToRoute($nextAction); |
|
134
|
|
|
} |
|
135
|
|
|
return $this->render('@App/admin/new_estate.html.twig', array( |
|
136
|
|
|
'estate' => $estate, |
|
137
|
|
|
'form' => $form->createView(), |
|
138
|
|
|
)); |
|
139
|
|
|
} |
|
140
|
|
|
} |
|
141
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.