|
2
|
1 |
<?php |
|
|
2 |
|
|
|
3 |
namespace Company\BaseBundle\Controller; |
|
|
4 |
|
|
|
5 |
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
|
|
6 |
|
|
|
7 |
use Company\BaseBundle\Entity\Document; |
|
|
8 |
use Company\BaseBundle\Form\DocumentType; |
|
|
9 |
|
|
|
10 |
/** |
|
|
11 |
* Document controller. |
|
|
12 |
* |
|
|
13 |
*/ |
|
|
14 |
class DocumentController extends Controller |
|
|
15 |
{ |
|
|
16 |
/** |
|
|
17 |
* Lists all Document entities. |
|
|
18 |
* |
|
|
19 |
*/ |
|
|
20 |
public function indexAction() |
|
|
21 |
{ |
|
|
22 |
$em = $this->getDoctrine()->getEntityManager(); |
|
|
23 |
|
|
|
24 |
$entities = $em->getRepository('CompanyBaseBundle:Document')->findAll(); |
|
|
25 |
|
|
|
26 |
return $this->render('CompanyBaseBundle:Document:index.html.twig', array( |
|
|
27 |
'entities' => $entities |
|
|
28 |
)); |
|
|
29 |
} |
|
|
30 |
|
|
|
31 |
/** |
|
|
32 |
* Finds and displays a Document entity. |
|
|
33 |
* |
|
|
34 |
*/ |
|
|
35 |
public function showAction($id) |
|
|
36 |
{ |
|
|
37 |
$em = $this->getDoctrine()->getEntityManager(); |
|
|
38 |
|
|
|
39 |
$entity = $em->getRepository('CompanyBaseBundle:Document')->find($id); |
|
|
40 |
|
|
|
41 |
if (!$entity) { |
|
|
42 |
throw $this->createNotFoundException('Unable to find Document entity.'); |
|
|
43 |
} |
|
|
44 |
|
|
|
45 |
$deleteForm = $this->createDeleteForm($id); |
|
|
46 |
|
|
|
47 |
return $this->render('CompanyBaseBundle:Document:show.html.twig', array( |
|
|
48 |
'entity' => $entity, |
|
|
49 |
'delete_form' => $deleteForm->createView(), |
|
|
50 |
|
|
|
51 |
)); |
|
|
52 |
} |
|
|
53 |
|
|
|
54 |
/** |
|
|
55 |
* Displays a form to create a new Document entity. |
|
|
56 |
* |
|
|
57 |
*/ |
|
|
58 |
public function newAction() |
|
|
59 |
{ |
|
|
60 |
$entity = new Document(); |
|
|
61 |
$form = $this->createForm(new DocumentType(), $entity); |
|
|
62 |
|
|
|
63 |
return $this->render('CompanyBaseBundle:Document:new.html.twig', array( |
|
|
64 |
'entity' => $entity, |
|
|
65 |
'form' => $form->createView() |
|
|
66 |
)); |
|
|
67 |
} |
|
|
68 |
|
|
|
69 |
/** |
|
|
70 |
* Creates a new Document entity. |
|
|
71 |
* |
|
|
72 |
*/ |
|
|
73 |
public function createAction() |
|
|
74 |
{ |
|
|
75 |
$entity = new Document(); |
|
|
76 |
$request = $this->getRequest(); |
|
|
77 |
$form = $this->createForm(new DocumentType(), $entity); |
|
|
78 |
$form->bindRequest($request); |
|
|
79 |
|
|
|
80 |
if ($form->isValid()) { |
|
|
81 |
$em = $this->getDoctrine()->getEntityManager(); |
|
|
82 |
$em->persist($entity); |
|
|
83 |
$em->flush(); |
|
|
84 |
|
|
|
85 |
return $this->redirect($this->generateUrl('document_show', array('id' => $entity->getId()))); |
|
|
86 |
|
|
|
87 |
} |
|
|
88 |
|
|
|
89 |
return $this->render('CompanyBaseBundle:Document:new.html.twig', array( |
|
|
90 |
'entity' => $entity, |
|
|
91 |
'form' => $form->createView() |
|
|
92 |
)); |
|
|
93 |
} |
|
|
94 |
|
|
|
95 |
/** |
|
|
96 |
* Displays a form to edit an existing Document entity. |
|
|
97 |
* |
|
|
98 |
*/ |
|
|
99 |
public function editAction($id) |
|
|
100 |
{ |
|
|
101 |
$em = $this->getDoctrine()->getEntityManager(); |
|
|
102 |
|
|
|
103 |
$entity = $em->getRepository('CompanyBaseBundle:Document')->find($id); |
|
|
104 |
|
|
|
105 |
if (!$entity) { |
|
|
106 |
throw $this->createNotFoundException('Unable to find Document entity.'); |
|
|
107 |
} |
|
|
108 |
|
|
|
109 |
$editForm = $this->createForm(new DocumentType(), $entity); |
|
|
110 |
$deleteForm = $this->createDeleteForm($id); |
|
|
111 |
|
|
|
112 |
return $this->render('CompanyBaseBundle:Document:edit.html.twig', array( |
|
|
113 |
'entity' => $entity, |
|
|
114 |
'edit_form' => $editForm->createView(), |
|
|
115 |
'delete_form' => $deleteForm->createView(), |
|
|
116 |
)); |
|
|
117 |
} |
|
|
118 |
|
|
|
119 |
/** |
|
|
120 |
* Edits an existing Document entity. |
|
|
121 |
* |
|
|
122 |
*/ |
|
|
123 |
public function updateAction($id) |
|
|
124 |
{ |
|
|
125 |
$em = $this->getDoctrine()->getEntityManager(); |
|
|
126 |
|
|
|
127 |
$entity = $em->getRepository('CompanyBaseBundle:Document')->find($id); |
|
|
128 |
|
|
|
129 |
if (!$entity) { |
|
|
130 |
throw $this->createNotFoundException('Unable to find Document entity.'); |
|
|
131 |
} |
|
|
132 |
|
|
|
133 |
$editForm = $this->createForm(new DocumentType(), $entity); |
|
|
134 |
$deleteForm = $this->createDeleteForm($id); |
|
|
135 |
|
|
|
136 |
$request = $this->getRequest(); |
|
|
137 |
|
|
|
138 |
$editForm->bindRequest($request); |
|
|
139 |
|
|
|
140 |
if ($editForm->isValid()) { |
|
|
141 |
$em->persist($entity); |
|
|
142 |
$em->flush(); |
|
|
143 |
|
|
|
144 |
return $this->redirect($this->generateUrl('document_edit', array('id' => $id))); |
|
|
145 |
} |
|
|
146 |
|
|
|
147 |
return $this->render('CompanyBaseBundle:Document:edit.html.twig', array( |
|
|
148 |
'entity' => $entity, |
|
|
149 |
'edit_form' => $editForm->createView(), |
|
|
150 |
'delete_form' => $deleteForm->createView(), |
|
|
151 |
)); |
|
|
152 |
} |
|
|
153 |
|
|
|
154 |
/** |
|
|
155 |
* Deletes a Document entity. |
|
|
156 |
* |
|
|
157 |
*/ |
|
|
158 |
public function deleteAction($id) |
|
|
159 |
{ |
|
|
160 |
$form = $this->createDeleteForm($id); |
|
|
161 |
$request = $this->getRequest(); |
|
|
162 |
|
|
|
163 |
$form->bindRequest($request); |
|
|
164 |
|
|
|
165 |
if ($form->isValid()) { |
|
|
166 |
$em = $this->getDoctrine()->getEntityManager(); |
|
|
167 |
$entity = $em->getRepository('CompanyBaseBundle:Document')->find($id); |
|
|
168 |
|
|
|
169 |
if (!$entity) { |
|
|
170 |
throw $this->createNotFoundException('Unable to find Document entity.'); |
|
|
171 |
} |
|
|
172 |
|
|
|
173 |
$em->remove($entity); |
|
|
174 |
$em->flush(); |
|
|
175 |
} |
|
|
176 |
|
|
|
177 |
return $this->redirect($this->generateUrl('document')); |
|
|
178 |
} |
|
|
179 |
|
|
|
180 |
private function createDeleteForm($id) |
|
|
181 |
{ |
|
|
182 |
return $this->createFormBuilder(array('id' => $id)) |
|
|
183 |
->add('id', 'hidden') |
|
|
184 |
->getForm() |
|
|
185 |
; |
|
|
186 |
} |
|
|
187 |
} |