PageRenderTime 49ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/src/Ultra/ControlDocumentoBundle/Controller/DisciplinaController.php

https://gitlab.com/hersan/ultra
PHP | 340 lines | 211 code | 48 blank | 81 comment | 7 complexity | 7ceb8bfa7d9f2659f148c98810db23d4 MD5 | raw file
  1. <?php
  2. namespace Ultra\ControlDocumentoBundle\Controller;
  3. use Symfony\Component\HttpFoundation\Request;
  4. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  5. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
  6. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
  7. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  8. use Ultra\ControlDocumentoBundle\Entity\Disciplina;
  9. use Ultra\ControlDocumentoBundle\Form\DisciplinaType;
  10. use Symfony\Component\HttpFoundation\Response;
  11. /**
  12. * Disciplina controller.
  13. *
  14. * @Route("/disciplina")
  15. */
  16. class DisciplinaController extends Controller
  17. {
  18. /**
  19. * Lists all Disciplina entities.
  20. *
  21. * @Route("/", name="disciplina")
  22. * @Method("GET")
  23. * @Template()
  24. */
  25. public function indexAction()
  26. {
  27. $em = $this->getDoctrine()->getManager();
  28. $entities = $em->getRepository('ControlDocumentoBundle:Disciplina')->loadAll();
  29. return array(
  30. 'entities' => $entities,
  31. );
  32. }
  33. /**
  34. * Creates a new Disciplinas entity.
  35. *
  36. * @Route("/disciplinaspdf", name="disciplinas_pdf")
  37. * @Method("GET")
  38. * @Template()
  39. */
  40. public function disciplinaspdfAction()
  41. {
  42. $em = $this->getDoctrine()->getManager();
  43. $entities = $em->getRepository('ControlDocumentoBundle:Disciplina')->findAll();
  44. $html = $this->renderView('ControlDocumentoBundle:Disciplina:disciplinaspdf.html.twig',
  45. array(
  46. 'entities' => $entities,
  47. ));
  48. $response = new Response (
  49. $this->get('knp_snappy.pdf')->getOutputFromHtml($html,
  50. array('lowquality' => false,
  51. 'print-media-type' => true,
  52. 'encoding' => 'utf-8',
  53. 'page-size' => 'Letter',
  54. 'outline-depth' => 8,
  55. 'orientation' => 'Portrait',
  56. 'title'=> 'Áreas',
  57. 'user-style-sheet'=> 'css/bootstrap.css',
  58. 'header-right'=>'Pag. [page] de [toPage]',
  59. 'header-font-size'=>7,
  60. )),
  61. 200,
  62. array(
  63. 'Content-Type' => '/home/aloyo/public_html/Ultra/web/pdf',
  64. 'Content-Disposition' => 'attachment; filename="listadedisciplinas.pdf"',
  65. )
  66. );
  67. return $response;
  68. }
  69. /**
  70. * Creates a new Disciplina entity.
  71. *
  72. * @Route("/", name="disciplina_create")
  73. * @Method("POST")
  74. * @Template("ControlDocumentoBundle:Disciplina:new.html.twig")
  75. */
  76. public function createAction(Request $request)
  77. {
  78. $entity = new Disciplina();
  79. $form = $this->createCreateForm($entity);
  80. $form->handleRequest($request);
  81. if ($form->isValid()) {
  82. $em = $this->getDoctrine()->getManager();
  83. $em->persist($entity);
  84. $em->flush();
  85. $this->get('session')->getFlashBag()->add(
  86. 'success',
  87. 'La disciplina se agregó con los siguientes datos:'
  88. );
  89. return $this->redirect($this->generateUrl('disciplina_show', array('id' => $entity->getId())));
  90. }
  91. $this->get('session')->getFlashBag()->add(
  92. 'danger',
  93. 'La disciplina no pudo ser agregada.'
  94. );
  95. return array(
  96. 'entity' => $entity,
  97. 'form' => $form->createView(),
  98. );
  99. }
  100. /**
  101. * Creates a form to create a Disciplina entity.
  102. *
  103. * @param Disciplina $entity The entity
  104. *
  105. * @return \Symfony\Component\Form\Form The form
  106. */
  107. private function createCreateForm(Disciplina $entity)
  108. {
  109. $form = $this->createForm(new DisciplinaType(), $entity, array(
  110. 'action' => $this->generateUrl('disciplina_create'),
  111. 'method' => 'POST',
  112. ));
  113. $form->add('submit', 'usubmit', array(
  114. 'label' => ' Guardar',
  115. 'attr' => array('class' => 'btn btn-success',
  116. 'title'=>'Guardar datos'),
  117. 'glyphicon' => 'glyphicon glyphicon-floppy-saved'
  118. ));
  119. return $form;
  120. }
  121. /**
  122. * Displays a form to create a new Disciplina entity.
  123. *
  124. * @Route("/new", name="disciplina_new")
  125. * @Method("GET")
  126. * @Template()
  127. */
  128. public function newAction()
  129. {
  130. $entity = new Disciplina();
  131. $form = $this->createCreateForm($entity);
  132. return array(
  133. 'entity' => $entity,
  134. 'form' => $form->createView(),
  135. );
  136. }
  137. /**
  138. * Finds and displays a Disciplina entity.
  139. *
  140. * @Route("/{id}", name="disciplina_show")
  141. * @Method("GET")
  142. * @Template()
  143. */
  144. public function showAction($id)
  145. {
  146. $em = $this->getDoctrine()->getManager();
  147. $entity = $em->getRepository('ControlDocumentoBundle:Disciplina')->loadById($id);
  148. if (!$entity) {
  149. throw $this->createNotFoundException('Imposible encontrar la disciplina.');
  150. }
  151. $deleteForm = $this->createDeleteForm($id);
  152. return array(
  153. 'entity' => $entity,
  154. 'delete_form' => $deleteForm->createView(),
  155. );
  156. }
  157. /**
  158. * Displays a form to edit an existing Disciplina entity.
  159. *
  160. * @Route("/{id}/edit", name="disciplina_edit")
  161. * @Method("GET")
  162. * @Template()
  163. */
  164. public function editAction($id)
  165. {
  166. $em = $this->getDoctrine()->getManager();
  167. $entity = $em->getRepository('ControlDocumentoBundle:Disciplina')->find($id);
  168. if (!$entity) {
  169. throw $this->createNotFoundException('Imposible encontrar la disciplina.');
  170. }
  171. $editForm = $this->createEditForm($entity);
  172. $deleteForm = $this->createDeleteForm($id);
  173. return array(
  174. 'entity' => $entity,
  175. 'edit_form' => $editForm->createView(),
  176. 'delete_form' => $deleteForm->createView(),
  177. );
  178. }
  179. /**
  180. * Creates a form to edit a Disciplina entity.
  181. *
  182. * @param Disciplina $entity The entity
  183. *
  184. * @return \Symfony\Component\Form\Form The form
  185. */
  186. private function createEditForm(Disciplina $entity)
  187. {
  188. $form = $this->createForm(new DisciplinaType(), $entity, array(
  189. 'action' => $this->generateUrl('disciplina_update', array('id' => $entity->getId())),
  190. 'method' => 'PUT',
  191. ));
  192. $form->add('submit', 'usubmit', array(
  193. 'label' => 'Actualizar',
  194. 'attr'=>array('class'=>'btn btn-success',
  195. 'title'=>'Actualizar datos'),
  196. 'glyphicon' => 'glyphicon glyphicon-edit'
  197. ));
  198. return $form;
  199. }
  200. /**
  201. * Edits an existing Disciplina entity.
  202. *
  203. * @Route("/{id}", name="disciplina_update")
  204. * @Method("PUT")
  205. * @Template("ControlDocumentoBundle:Disciplina:edit.html.twig")
  206. */
  207. public function updateAction(Request $request, $id)
  208. {
  209. $em = $this->getDoctrine()->getManager();
  210. $entity = $em->getRepository('ControlDocumentoBundle:Disciplina')->find($id);
  211. if (!$entity) {
  212. throw $this->createNotFoundException('Imposible encontrar la disciplina.');
  213. }
  214. $deleteForm = $this->createDeleteForm($id);
  215. $editForm = $this->createEditForm($entity);
  216. $editForm->handleRequest($request);
  217. if ($editForm->isValid()) {
  218. $em->flush();
  219. $this->get('session')->getFlashBag()->add(
  220. 'success',
  221. 'La disciplina quedo actualizada con los siguientes datos:'
  222. );
  223. return $this->redirect($this->generateUrl('disciplina_show', array('id' => $id)));
  224. }
  225. else
  226. {
  227. $this->get('session')->getFlashBag()->add(
  228. 'danger',
  229. 'Los datos de la disciplina no pudieron ser actualizados.'
  230. );
  231. }
  232. return array(
  233. 'entity' => $entity,
  234. 'edit_form' => $editForm->createView(),
  235. 'delete_form' => $deleteForm->createView(),
  236. );
  237. }
  238. /**
  239. * Deletes a Disciplina entity.
  240. *
  241. * @Route("/{id}", name="disciplina_delete")
  242. * @Method("DELETE")
  243. */
  244. public function deleteAction(Request $request, $id)
  245. {
  246. $form = $this->createDeleteForm($id);
  247. $form->handleRequest($request);
  248. if ($form->isValid()) {
  249. $em = $this->getDoctrine()->getManager();
  250. $entity = $em->getRepository('ControlDocumentoBundle:Disciplina')->find($id);
  251. if (!$entity) {
  252. throw $this->createNotFoundException('Imposible encontrar la disciplina');
  253. }
  254. $em->remove($entity);
  255. $em->flush();
  256. $this->get('session')->getFlashBag()->add(
  257. 'success',
  258. 'La disciplina fue eliminada.'
  259. );
  260. return $this->redirect($this->generateUrl('disciplina'));
  261. }
  262. else
  263. {
  264. $this->get('session')->getFlashBag()->add(
  265. 'danger',
  266. 'La disciplina no se pudo eliminar.'
  267. );
  268. }
  269. return $this->redirect($this->generateUrl('disciplina'));
  270. }
  271. /**
  272. * Creates a form to delete a Disciplina entity by id.
  273. *
  274. * @param mixed $id The entity id
  275. *
  276. * @return \Symfony\Component\Form\Form The form
  277. */
  278. private function createDeleteForm($id)
  279. {
  280. return $this->createFormBuilder()
  281. ->setAction($this->generateUrl('disciplina_delete', array('id' => $id)))
  282. ->setMethod('DELETE')
  283. ->add('submit', 'usubmit', array(
  284. 'label' => 'Borrar',
  285. 'attr' => array('class'=>'btn btn-warning',
  286. 'title'=>'Borrar datos'),
  287. 'glyphicon' => 'glyphicon glyphicon-trash'
  288. ))
  289. ->getForm()
  290. ;
  291. }
  292. }