From 7f94616f277036162281b1c76b65fad26414d3a1 Mon Sep 17 00:00:00 2001 From: MAIKEL NOGUERA Date: Mon, 5 Feb 2018 14:20:39 -0400 Subject: [PATCH] Creacion de formularios, fomularios embebido --- .gitignore | 1 + app/Resources/views/banco/edit.html.twig | 71 ++++++++-- app/Resources/views/banco/index.html.twig | 42 ++++-- app/Resources/views/banco/new.html.twig | 52 +++++++- app/Resources/views/banco/show.html.twig | 12 +- app/Resources/views/estado/edit.html.twig | 23 ++++ app/Resources/views/estado/index.html.twig | 41 ++++++ app/Resources/views/estado/new.html.twig | 16 +++ app/Resources/views/estado/show.html.twig | 36 ++++++ app/Resources/views/municipio/edit.html.twig | 24 ++++ app/Resources/views/municipio/index.html.twig | 43 +++++++ app/Resources/views/municipio/new.html.twig | 16 +++ app/Resources/views/municipio/show.html.twig | 38 ++++++ app/Resources/views/parroquia/edit.html.twig | 24 ++++ app/Resources/views/parroquia/index.html.twig | 44 +++++++ app/Resources/views/parroquia/new.html.twig | 16 +++ app/Resources/views/parroquia/show.html.twig | 36 ++++++ nbproject/project.properties | 7 + nbproject/project.xml | 9 ++ .../PracticaBundle/Controller/BancoController.php | 10 +- .../PracticaBundle/Controller/estadoController.php | 143 +++++++++++++++++++++ .../Controller/municipioController.php | 136 ++++++++++++++++++++ .../Controller/parroquiaController.php | 136 ++++++++++++++++++++ src/UBV/PracticaBundle/Entity/Banco.php | 2 +- src/UBV/PracticaBundle/Entity/estado.php | 16 +++ src/UBV/PracticaBundle/Entity/municipio.php | 42 ++++++ src/UBV/PracticaBundle/Entity/parroquia.php | 36 ++++++ src/UBV/PracticaBundle/Form/BancoType.php | 2 +- src/UBV/PracticaBundle/Form/estadoType.php | 47 +++++++ src/UBV/PracticaBundle/Form/municipioType.php | 36 ++++++ src/UBV/PracticaBundle/Form/parroquiaType.php | 36 ++++++ .../Tests/Controller/estadoControllerTest.php | 55 ++++++++ .../Tests/Controller/municipioControllerTest.php | 55 ++++++++ .../Tests/Controller/parroquiaControllerTest.php | 55 ++++++++ 34 files changed, 1325 insertions(+), 33 deletions(-) create mode 100644 app/Resources/views/estado/edit.html.twig create mode 100644 app/Resources/views/estado/index.html.twig create mode 100644 app/Resources/views/estado/new.html.twig create mode 100644 app/Resources/views/estado/show.html.twig create mode 100644 app/Resources/views/municipio/edit.html.twig create mode 100644 app/Resources/views/municipio/index.html.twig create mode 100644 app/Resources/views/municipio/new.html.twig create mode 100644 app/Resources/views/municipio/show.html.twig create mode 100644 app/Resources/views/parroquia/edit.html.twig create mode 100644 app/Resources/views/parroquia/index.html.twig create mode 100644 app/Resources/views/parroquia/new.html.twig create mode 100644 app/Resources/views/parroquia/show.html.twig create mode 100644 nbproject/project.properties create mode 100644 nbproject/project.xml create mode 100644 src/UBV/PracticaBundle/Controller/estadoController.php create mode 100644 src/UBV/PracticaBundle/Controller/municipioController.php create mode 100644 src/UBV/PracticaBundle/Controller/parroquiaController.php create mode 100644 src/UBV/PracticaBundle/Form/estadoType.php create mode 100644 src/UBV/PracticaBundle/Form/municipioType.php create mode 100644 src/UBV/PracticaBundle/Form/parroquiaType.php create mode 100644 src/UBV/PracticaBundle/Tests/Controller/estadoControllerTest.php create mode 100644 src/UBV/PracticaBundle/Tests/Controller/municipioControllerTest.php create mode 100644 src/UBV/PracticaBundle/Tests/Controller/parroquiaControllerTest.php diff --git a/.gitignore b/.gitignore index 951b549..33a23e7 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ /vendor/ /bin/ /composer.phar +/nbproject/private/ \ No newline at end of file diff --git a/app/Resources/views/banco/edit.html.twig b/app/Resources/views/banco/edit.html.twig index 62e87b3..719c18e 100644 --- a/app/Resources/views/banco/edit.html.twig +++ b/app/Resources/views/banco/edit.html.twig @@ -1,21 +1,74 @@ {% extends 'base.html.twig' %} {% block body %} -

Banco edit

+

Banco editar

- {{ form_start(edit_form) }} + +
+ + + + +
+
+ +
+ + +
+
+ + {{ form_label(edit_form.descripcion) }} +{{ form_widget( edit_form.descripcion ) }} + + + +{% if form.descripcion.vars.errors[0].message is defined %} + +{{ form.descripcion.vars.errors[0].message }} + +
+{% endif %} + +
+
+ +
+ + + + {{ form_label(edit_form.codigo) }} +{{ form_widget(edit_form.codigo) }} + +{% if form.codigo.vars.errors[0].message is defined %} + +{{ form.codigo.vars.errors[0].message }} + +
+{% endif %} + +
+ + {{ form_start(edit_form) }} {{ form_widget(edit_form) }} - +
+ {{ form_end(edit_form) }} +
+ {% endblock %} + + + + \ No newline at end of file diff --git a/app/Resources/views/banco/index.html.twig b/app/Resources/views/banco/index.html.twig index 366e127..616e629 100644 --- a/app/Resources/views/banco/index.html.twig +++ b/app/Resources/views/banco/index.html.twig @@ -1,30 +1,49 @@ {% extends 'base.html.twig' %} {% block body %} +{% for type, flashMessage in app.session.flashbag.all() %} +
+ +{% if flashMessage.title is defined %} +{{ flashMessage.title }} +{{ flashMessage.message }} +{% else %} +{{ type }} +{% endif %} +
+{% endfor %} +

Bancos list

+

Listado Varibles

- + +
- - - - + + + + + - + {% for banco in bancos %} - + @@ -35,7 +54,10 @@ {% endblock %} diff --git a/app/Resources/views/banco/new.html.twig b/app/Resources/views/banco/new.html.twig index 916e5eb..2396955 100644 --- a/app/Resources/views/banco/new.html.twig +++ b/app/Resources/views/banco/new.html.twig @@ -2,15 +2,57 @@ {% block body %}

Banco creation

+ + {# {{ form_start(form) }} + {{ form_widget(form) }}#} + + + +{{ form_start(form, {'attr': {'novalidate': 'novalidate'}, 'action': path('banco_new')}) }} + + +
+
+ + {{ form_label(form.descripcion) }} +{{ form_widget(form.descripcion) }} + +{% if form.descripcion.vars.errors[0].message is defined %} + +{{ form.descripcion.vars.errors[0].message }} + + + +{% endif %} + - {{ form_start(form) }} - {{ form_widget(form) }} - - {{ form_end(form) }} +
+
+ + + {{ form_label(form.codigo) }} +{{ form_widget(form.codigo) }} + +{% if form.codigo.vars.errors[0].message is defined %} + +{{ form.codigo.vars.errors[0].message }} + + + + +{% endif %} + {% endblock %} + \ No newline at end of file diff --git a/app/Resources/views/banco/show.html.twig b/app/Resources/views/banco/show.html.twig index 7905c64..b9d84fb 100644 --- a/app/Resources/views/banco/show.html.twig +++ b/app/Resources/views/banco/show.html.twig @@ -19,18 +19,22 @@
IdDescripcionCodigoActions Id Descripcion Codigo Actions
{{ banco.id }}{{ banco.descripcion }}{{ banco.descripcion | capitalize }} {{ banco.codigo }}
- +
{% endblock %} diff --git a/app/Resources/views/estado/edit.html.twig b/app/Resources/views/estado/edit.html.twig new file mode 100644 index 0000000..b2b16a1 --- /dev/null +++ b/app/Resources/views/estado/edit.html.twig @@ -0,0 +1,23 @@ +{% extends 'base.html.twig' %} + +{% block body %} +

Estado editar

+ + {{ form_start(edit_form) }} + {{ form_widget(edit_form) }} +
+ + {{ form_end(edit_form) }} +
+ +
    +
  • + Volver listado +
  • +
  • + {{ form_start(delete_form) }} + + {{ form_end(delete_form) }} +
  • +
+{% endblock %} diff --git a/app/Resources/views/estado/index.html.twig b/app/Resources/views/estado/index.html.twig new file mode 100644 index 0000000..30ec161 --- /dev/null +++ b/app/Resources/views/estado/index.html.twig @@ -0,0 +1,41 @@ +{% extends 'base.html.twig' %} + +{% block body %} +

Estados list

+ + + + + + + + + + + + {% for estado in estados %} + + + + + + + {% endfor %} + +
IdDescripcionCodigoActions
{{ estado.id }}{{ estado.descripcion | capitalize }}{{ estado.codigo }} + +
+ + +{% endblock %} diff --git a/app/Resources/views/estado/new.html.twig b/app/Resources/views/estado/new.html.twig new file mode 100644 index 0000000..460721b --- /dev/null +++ b/app/Resources/views/estado/new.html.twig @@ -0,0 +1,16 @@ +{% extends 'base.html.twig' %} + +{% block body %} +

Estado creation

+ + {{ form_start(form) }} + {{ form_widget(form) }} + + {{ form_end(form) }} + + +{% endblock %} diff --git a/app/Resources/views/estado/show.html.twig b/app/Resources/views/estado/show.html.twig new file mode 100644 index 0000000..5a1ed7b --- /dev/null +++ b/app/Resources/views/estado/show.html.twig @@ -0,0 +1,36 @@ +{% extends 'base.html.twig' %} + +{% block body %} +

Estado

+ + + + + + + + + + + + + + + + +
Id{{ estado.id }}
Descripcion{{ estado.descripcion }}
Codigo{{ estado.codigo }}
+ + +{% endblock %} diff --git a/app/Resources/views/municipio/edit.html.twig b/app/Resources/views/municipio/edit.html.twig new file mode 100644 index 0000000..37b39d2 --- /dev/null +++ b/app/Resources/views/municipio/edit.html.twig @@ -0,0 +1,24 @@ +{% extends 'base.html.twig' %} + +{% block body %} +

Municipio editar

+ + {{ form_start(edit_form) }} + {{ form_widget(edit_form) }} + +
+ + {{ form_end(edit_form) }} + +
+
    +
  • + Volver listado +
  • +
  • + {{ form_start(delete_form) }} + + {{ form_end(delete_form) }} +
  • +
+{% endblock %} diff --git a/app/Resources/views/municipio/index.html.twig b/app/Resources/views/municipio/index.html.twig new file mode 100644 index 0000000..950ccbd --- /dev/null +++ b/app/Resources/views/municipio/index.html.twig @@ -0,0 +1,43 @@ +{% extends 'base.html.twig' %} + +{% block body %} +

Municipios list

+ + + + + + + + + + + + + {% for municipio in municipios %} + + + + + + + + {% endfor %} + +
IdDescripcionCodigoEstadoActions
{{ municipio.id }}{{ municipio.descripcion | capitalize }}{{ municipio.codigo }}{{ municipio.Estado | capitalize}} + +
+ + +{% endblock %} diff --git a/app/Resources/views/municipio/new.html.twig b/app/Resources/views/municipio/new.html.twig new file mode 100644 index 0000000..1f0cff5 --- /dev/null +++ b/app/Resources/views/municipio/new.html.twig @@ -0,0 +1,16 @@ +{% extends 'base.html.twig' %} + +{% block body %} +

Municipio creation

+ + {{ form_start(form) }} + {{ form_widget(form) }} + + {{ form_end(form) }} + + +{% endblock %} diff --git a/app/Resources/views/municipio/show.html.twig b/app/Resources/views/municipio/show.html.twig new file mode 100644 index 0000000..d701e5a --- /dev/null +++ b/app/Resources/views/municipio/show.html.twig @@ -0,0 +1,38 @@ +{% extends 'base.html.twig' %} + +{% block body %} +

Municipio

+ + + + + + + + + + + + + + + + + + +
Id{{ municipio.id }}
Descripcion{{ municipio.descripcion }}
Codigo{{ municipio.codigo }}
+ + +{% endblock %} diff --git a/app/Resources/views/parroquia/edit.html.twig b/app/Resources/views/parroquia/edit.html.twig new file mode 100644 index 0000000..12b619d --- /dev/null +++ b/app/Resources/views/parroquia/edit.html.twig @@ -0,0 +1,24 @@ +{% extends 'base.html.twig' %} + +{% block body %} +

Parroquia editar

+ + + {{ form_start(edit_form) }} + {{ form_widget(edit_form) }} +
+ + {{ form_end(edit_form) }} + +
+
    +
  • + Volver listado +
  • +
  • + {{ form_start(delete_form) }} + + {{ form_end(delete_form) }} +
  • +
+{% endblock %} diff --git a/app/Resources/views/parroquia/index.html.twig b/app/Resources/views/parroquia/index.html.twig new file mode 100644 index 0000000..5c3bb4c --- /dev/null +++ b/app/Resources/views/parroquia/index.html.twig @@ -0,0 +1,44 @@ +{% extends 'base.html.twig' %} + +{% block body %} +

Parroquias list

+ + + + + + + + + + + + + + {% for parroquia in parroquias %} + + + + + + + + {% endfor %} + +
Id DescripcionCodigoMunicipioActions
{{ parroquia.id }}{{ parroquia.descripcion | capitalize}}{{ parroquia.codigo }}{{ parroquia.Municipio | capitalize }} + +
+ + +{% endblock %} diff --git a/app/Resources/views/parroquia/new.html.twig b/app/Resources/views/parroquia/new.html.twig new file mode 100644 index 0000000..d685604 --- /dev/null +++ b/app/Resources/views/parroquia/new.html.twig @@ -0,0 +1,16 @@ +{% extends 'base.html.twig' %} + +{% block body %} +

Parroquia creation

+ + {{ form_start(form) }} + {{ form_widget(form) }} + + {{ form_end(form) }} + + +{% endblock %} diff --git a/app/Resources/views/parroquia/show.html.twig b/app/Resources/views/parroquia/show.html.twig new file mode 100644 index 0000000..87acc18 --- /dev/null +++ b/app/Resources/views/parroquia/show.html.twig @@ -0,0 +1,36 @@ +{% extends 'base.html.twig' %} + +{% block body %} +

Parroquia

+ + + + + + + + + + + + + + + + +
Id{{ parroquia.id }}
Descripcion{{ parroquia.descripcion }}
Codigo{{ parroquia.codigo }}
+ + +{% endblock %} diff --git a/nbproject/project.properties b/nbproject/project.properties new file mode 100644 index 0000000..76f6f91 --- /dev/null +++ b/nbproject/project.properties @@ -0,0 +1,7 @@ +include.path=${php.global.include.path} +php.version=PHP_56 +source.encoding=UTF-8 +src.dir=. +tags.asp=false +tags.short=false +web.root=. diff --git a/nbproject/project.xml b/nbproject/project.xml new file mode 100644 index 0000000..60d3060 --- /dev/null +++ b/nbproject/project.xml @@ -0,0 +1,9 @@ + + + org.netbeans.modules.php.project + + + PhpProject1 + + + diff --git a/src/UBV/PracticaBundle/Controller/BancoController.php b/src/UBV/PracticaBundle/Controller/BancoController.php index f66c47f..7db53e2 100644 --- a/src/UBV/PracticaBundle/Controller/BancoController.php +++ b/src/UBV/PracticaBundle/Controller/BancoController.php @@ -46,9 +46,11 @@ class BancoController extends Controller if ($form->isSubmitted() && $form->isValid()) { $em = $this->getDoctrine()->getManager(); $em->persist($banco); - $em->flush(); $this->get('session')->getFlashBag()->set( 'success', array( 'title' => 'Guardado!', 'message' => 'Estado creado satisfactoriamente.' ) ); + $em->flush(); + + $this->get('session')->getFlashBag()->set( 'success', array( 'title' => 'Guardado!', 'message' => 'Estado creado satisfactoriamente.' ) ); - return $this->redirectToRoute(' $banco->getId())); + return $this->redirectToRoute('banco_index', array('id' => $banco->getId())); } return $this->render('banco/new.html.twig', array( @@ -88,7 +90,9 @@ class BancoController extends Controller if ($editForm->isSubmitted() && $editForm->isValid()) { $this->getDoctrine()->getManager()->flush(); $this->get('session')->getFlashBag()->set( 'success', array( 'title' => 'Guardado!', 'message' => 'Estado editado satisfactoriamente.' ) ); - return $this->redirectToRoute('banco_edit', array('id' => $banco->getId())); + + + return $this->redirectToRoute('banco_index', array('id' => $banco->getId())); } return $this->render('banco/edit.html.twig', array( diff --git a/src/UBV/PracticaBundle/Controller/estadoController.php b/src/UBV/PracticaBundle/Controller/estadoController.php new file mode 100644 index 0000000..178a18d --- /dev/null +++ b/src/UBV/PracticaBundle/Controller/estadoController.php @@ -0,0 +1,143 @@ +getDoctrine()->getManager(); + + $estados = $em->getRepository('UBVPracticaBundle:estado')->findAll(); + + return $this->render('estado/index.html.twig', array( + 'estados' => $estados, + )); + } + + /** + * Creates a new estado entity. + * + * @Route("/new", name="estado_new") + * @Method({"GET", "POST"}) + */ + public function newAction(Request $request) + { + $estado = new Estado(); + $form = $this->createForm('UBV\PracticaBundle\Form\estadoType', $estado); + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $em = $this->getDoctrine()->getManager(); + $em->persist($estado); + $em->flush(); + + return $this->redirectToRoute('estado_show', array('id' => $estado->getId())); + } + + return $this->render('estado/new.html.twig', array( + 'estado' => $estado, + 'form' => $form->createView(), + )); + } + + /** + * Finds and displays a estado entity. + * + * @Route("/{id}", name="estado_show") + * @Method("GET") + */ + public function showAction(estado $estado) + { + $deleteForm = $this->createDeleteForm($estado); + + return $this->render('estado/show.html.twig', array( + 'estado' => $estado, + 'delete_form' => $deleteForm->createView(), + )); + } + + /** + * Displays a form to edit an existing estado entity. + * + * @Route("/{id}/edit", name="estado_edit") + * @Method({"GET", "POST"}) + */ + public function editAction(Request $request, estado $estado) + { + $deleteForm = $this->createDeleteForm($estado); + $editForm = $this->createForm('UBV\PracticaBundle\Form\estadoType', $estado); + $editForm->handleRequest($request); + + if ($editForm->isSubmitted() && $editForm->isValid()) { + $this->getDoctrine()->getManager()->flush(); + + return $this->redirectToRoute('estado_edit', array('id' => $estado->getId())); + } + + return $this->render('estado/edit.html.twig', array( + 'estado' => $estado, + 'edit_form' => $editForm->createView(), + 'delete_form' => $deleteForm->createView(), + )); + } + + /** + * Deletes a estado entity. + * + * @Route("/{id}", name="estado_delete") + * @Method("DELETE") + */ + public function deleteAction(Request $request, estado $estado) + { + $form = $this->createDeleteForm($estado); + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $em = $this->getDoctrine()->getManager(); + $em->remove($estado); + $em->flush(); + } + + return $this->redirectToRoute('estado_index'); + } + + /** + * Creates a form to delete a estado entity. + * + * @param estado $estado The estado entity + * + * @return \Symfony\Component\Form\Form The form + */ + private function createDeleteForm(estado $estado) + { + return $this->createFormBuilder() + ->setAction($this->generateUrl('estado_delete', array('id' => $estado->getId()))) + ->setMethod('DELETE') + ->getForm() + ; + + } + + + +} diff --git a/src/UBV/PracticaBundle/Controller/municipioController.php b/src/UBV/PracticaBundle/Controller/municipioController.php new file mode 100644 index 0000000..cb324d3 --- /dev/null +++ b/src/UBV/PracticaBundle/Controller/municipioController.php @@ -0,0 +1,136 @@ +getDoctrine()->getManager(); + + $municipios = $em->getRepository('UBVPracticaBundle:municipio')->findAll(); + + return $this->render('municipio/index.html.twig', array( + 'municipios' => $municipios, + )); + } + + /** + * Creates a new municipio entity. + * + * @Route("/new", name="municipio_new") + * @Method({"GET", "POST"}) + */ + public function newAction(Request $request) + { + $municipio = new Municipio(); + $form = $this->createForm('UBV\PracticaBundle\Form\municipioType', $municipio); + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $em = $this->getDoctrine()->getManager(); + $em->persist($municipio); + $em->flush(); + + return $this->redirectToRoute('municipio_show', array('id' => $municipio->getId())); + } + + return $this->render('municipio/new.html.twig', array( + 'municipio' => $municipio, + 'form' => $form->createView(), + )); + } + + /** + * Finds and displays a municipio entity. + * + * @Route("/{id}", name="municipio_show") + * @Method("GET") + */ + public function showAction(municipio $municipio) + { + $deleteForm = $this->createDeleteForm($municipio); + + return $this->render('municipio/show.html.twig', array( + 'municipio' => $municipio, + 'delete_form' => $deleteForm->createView(), + )); + } + + /** + * Displays a form to edit an existing municipio entity. + * + * @Route("/{id}/edit", name="municipio_edit") + * @Method({"GET", "POST"}) + */ + public function editAction(Request $request, municipio $municipio) + { + $deleteForm = $this->createDeleteForm($municipio); + $editForm = $this->createForm('UBV\PracticaBundle\Form\municipioType', $municipio); + $editForm->handleRequest($request); + + if ($editForm->isSubmitted() && $editForm->isValid()) { + $this->getDoctrine()->getManager()->flush(); + + return $this->redirectToRoute('municipio_edit', array('id' => $municipio->getId())); + } + + return $this->render('municipio/edit.html.twig', array( + 'municipio' => $municipio, + 'edit_form' => $editForm->createView(), + 'delete_form' => $deleteForm->createView(), + )); + } + + /** + * Deletes a municipio entity. + * + * @Route("/{id}", name="municipio_delete") + * @Method("DELETE") + */ + public function deleteAction(Request $request, municipio $municipio) + { + $form = $this->createDeleteForm($municipio); + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $em = $this->getDoctrine()->getManager(); + $em->remove($municipio); + $em->flush(); + } + + return $this->redirectToRoute('municipio_index'); + } + + /** + * Creates a form to delete a municipio entity. + * + * @param municipio $municipio The municipio entity + * + * @return \Symfony\Component\Form\Form The form + */ + private function createDeleteForm(municipio $municipio) + { + return $this->createFormBuilder() + ->setAction($this->generateUrl('municipio_delete', array('id' => $municipio->getId()))) + ->setMethod('DELETE') + ->getForm() + ; + } +} diff --git a/src/UBV/PracticaBundle/Controller/parroquiaController.php b/src/UBV/PracticaBundle/Controller/parroquiaController.php new file mode 100644 index 0000000..47a2f06 --- /dev/null +++ b/src/UBV/PracticaBundle/Controller/parroquiaController.php @@ -0,0 +1,136 @@ +getDoctrine()->getManager(); + + $parroquias = $em->getRepository('UBVPracticaBundle:parroquia')->findAll(); + + return $this->render('parroquia/index.html.twig', array( + 'parroquias' => $parroquias, + )); + } + + /** + * Creates a new parroquia entity. + * + * @Route("/new", name="parroquia_new") + * @Method({"GET", "POST"}) + */ + public function newAction(Request $request) + { + $parroquia = new Parroquia(); + $form = $this->createForm('UBV\PracticaBundle\Form\parroquiaType', $parroquia); + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $em = $this->getDoctrine()->getManager(); + $em->persist($parroquia); + $em->flush(); + + return $this->redirectToRoute('parroquia_show', array('id' => $parroquia->getId())); + } + + return $this->render('parroquia/new.html.twig', array( + 'parroquia' => $parroquia, + 'form' => $form->createView(), + )); + } + + /** + * Finds and displays a parroquia entity. + * + * @Route("/{id}", name="parroquia_show") + * @Method("GET") + */ + public function showAction(parroquia $parroquia) + { + $deleteForm = $this->createDeleteForm($parroquia); + + return $this->render('parroquia/show.html.twig', array( + 'parroquia' => $parroquia, + 'delete_form' => $deleteForm->createView(), + )); + } + + /** + * Displays a form to edit an existing parroquia entity. + * + * @Route("/{id}/edit", name="parroquia_edit") + * @Method({"GET", "POST"}) + */ + public function editAction(Request $request, parroquia $parroquia) + { + $deleteForm = $this->createDeleteForm($parroquia); + $editForm = $this->createForm('UBV\PracticaBundle\Form\parroquiaType', $parroquia); + $editForm->handleRequest($request); + + if ($editForm->isSubmitted() && $editForm->isValid()) { + $this->getDoctrine()->getManager()->flush(); + + return $this->redirectToRoute('parroquia_edit', array('id' => $parroquia->getId())); + } + + return $this->render('parroquia/edit.html.twig', array( + 'parroquium' => $parroquia, + 'edit_form' => $editForm->createView(), + 'delete_form' => $deleteForm->createView(), + )); + } + + /** + * Deletes a parroquia entity. + * + * @Route("/{id}", name="parroquia_delete") + * @Method("DELETE") + */ + public function deleteAction(Request $request, parroquia $parroquia) + { + $form = $this->createDeleteForm($parroquia); + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $em = $this->getDoctrine()->getManager(); + $em->remove($parroquia); + $em->flush(); + } + + return $this->redirectToRoute('parroquia_index'); + } + + /** + * Creates a form to delete a parroquia entity. + * + * @param parroquia $parroquium The parroquia entity + * + * @return \Symfony\Component\Form\Form The form + */ + private function createDeleteForm(parroquia $parroquia) + { + return $this->createFormBuilder() + ->setAction($this->generateUrl('parroquia_delete', array('id' => $parroquia->getId()))) + ->setMethod('DELETE') + ->getForm() + ; + } +} diff --git a/src/UBV/PracticaBundle/Entity/Banco.php b/src/UBV/PracticaBundle/Entity/Banco.php index 1654c39..af6a988 100644 --- a/src/UBV/PracticaBundle/Entity/Banco.php +++ b/src/UBV/PracticaBundle/Entity/Banco.php @@ -30,7 +30,7 @@ class Banco * max = 150, * minMessage = "Por favor introduzca un Nombre de Banco más específico. Mínimo {{ limit }} caracteres", * maxMessage = "Por favor introduzca un Nombre de Banco más breve. Máximo {{ limit }} caracteres", -*) +*) * @var string * * @ORM\Column(name="descripcion", type="string", length=255) diff --git a/src/UBV/PracticaBundle/Entity/estado.php b/src/UBV/PracticaBundle/Entity/estado.php index b31d702..3d914d5 100644 --- a/src/UBV/PracticaBundle/Entity/estado.php +++ b/src/UBV/PracticaBundle/Entity/estado.php @@ -4,12 +4,16 @@ namespace UBV\PracticaBundle\Entity; use Doctrine\ORM\Mapping as ORM; + + + /** * estado * * @ORM\Table(name="estado") * @ORM\Entity(repositoryClass="UBV\PracticaBundle\Repository\estadoRepository") */ + class estado { /** @@ -19,6 +23,7 @@ class estado * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ + private $id; /** @@ -36,6 +41,8 @@ class estado private $codigo; + + /** * Get id * @@ -93,5 +100,14 @@ class estado { return $this->codigo; } + + public function __toString () { + + return $this->getDescripcion(); +} + + } + + diff --git a/src/UBV/PracticaBundle/Entity/municipio.php b/src/UBV/PracticaBundle/Entity/municipio.php index a6d49a3..e771724 100644 --- a/src/UBV/PracticaBundle/Entity/municipio.php +++ b/src/UBV/PracticaBundle/Entity/municipio.php @@ -35,6 +35,14 @@ class municipio */ private $codigo; + /** + * @ var\Estado + * + * @ORM\ManyToOne(targetEntity="estado", inversedBy="municipios", cascade={"persist", "remove"}) + * @ORM\JoinColumn(name="estado_id", referencedColumnName="id", nullable=false) + */ + + private $estado; /** * Get id @@ -46,6 +54,8 @@ class municipio return $this->id; } + + /** * Set descripcion * @@ -93,5 +103,37 @@ class municipio { return $this->codigo; } + + /** + * Set estado + * + * @param \UBV\PracticaBundle\Entity\Estado $estado + * + * @return municipio + */ + public function setEstado(\UBV\PracticaBundle\Entity\Estado $estado=null) + { + $this->estado = $estado; + + return $this; + } + + /** + * Get estado + * + * @return \UBV\PracticaBundle\Entity\Estado + */ + public function getEstado() + { + return $this->estado; + } + + public function __toString (){ + + return $this->getDescripcion(); +} + + + } diff --git a/src/UBV/PracticaBundle/Entity/parroquia.php b/src/UBV/PracticaBundle/Entity/parroquia.php index 98cdd94..7c7eb4e 100644 --- a/src/UBV/PracticaBundle/Entity/parroquia.php +++ b/src/UBV/PracticaBundle/Entity/parroquia.php @@ -35,6 +35,14 @@ class parroquia */ private $codigo; + /** + * @ var\Estado + * + * @ORM\ManyToOne(targetEntity="municipio", inversedBy="parroquias", cascade={"persist", "remove"}) + * @ORM\JoinColumn(name="estado_id", referencedColumnName="id", nullable=false) + */ + + private $municipio; /** * Get id @@ -93,5 +101,33 @@ class parroquia { return $this->codigo; } +/** + * Set municipio + * + * @param \UBV\PracticaBundle\Entity\Municipio $municipio + * + * @return parroquia + */ + public function setMunicipio(\UBV\PracticaBundle\Entity\Municipio $municipio=null) + { + $this->municipio = $municipio; + + return $this; + } + + /** + * Get municipio + * + * @return \UBV\PracticaBundle\Entity\Municipio + */ + public function getMunicipio() + { + return $this->municipio; + } + + + } + + diff --git a/src/UBV/PracticaBundle/Form/BancoType.php b/src/UBV/PracticaBundle/Form/BancoType.php index c540052..6ca416b 100644 --- a/src/UBV/PracticaBundle/Form/BancoType.php +++ b/src/UBV/PracticaBundle/Form/BancoType.php @@ -15,8 +15,8 @@ class BancoType extends AbstractType { $builder ->add('descripcion','text', array( 'label'=> 'Descripción del Estado', 'attr' => array('class' => 'form-control','placeholder'=>'Descripcion del Estado'), 'label_attr' => array('class' => 'control-label'), )) - ->add('codigo', 'integer',array( 'attr' => array('class' => 'form-control','placeholder'=>'codigo del Estado'), 'label_attr' => array('class' => 'control-label'), )); + }/** * {@inheritdoc} */ diff --git a/src/UBV/PracticaBundle/Form/estadoType.php b/src/UBV/PracticaBundle/Form/estadoType.php new file mode 100644 index 0000000..dd5836b --- /dev/null +++ b/src/UBV/PracticaBundle/Form/estadoType.php @@ -0,0 +1,47 @@ +add('descripcion') + ->add('codigo', new municipioType()) + ->getForm(); + + }/** + + +* {@inheritdoc} +*/ +public function configureOptions(OptionsResolver $resolver) +{ +$resolver->setDefaults(array( +'data_class' => 'UBV\PracticaBundle\Entity\estado' +)); +} + +/** +* {@inheritdoc} +*/ +public function getBlockPrefix() +{ +return 'ubv_practicabundle_estado'; +} + + + + +} \ No newline at end of file diff --git a/src/UBV/PracticaBundle/Form/municipioType.php b/src/UBV/PracticaBundle/Form/municipioType.php new file mode 100644 index 0000000..2a7200e --- /dev/null +++ b/src/UBV/PracticaBundle/Form/municipioType.php @@ -0,0 +1,36 @@ +add('descripcion')->add('codigo')->add('estado'); + }/** + * {@inheritdoc} + */ + public function configureOptions(OptionsResolver $resolver) + { + $resolver->setDefaults(array( + 'data_class' => 'UBV\PracticaBundle\Entity\municipio' + )); + } + + /** + * {@inheritdoc} + */ + public function getBlockPrefix() + { + return 'ubv_practicabundle_municipio'; + } + + +} diff --git a/src/UBV/PracticaBundle/Form/parroquiaType.php b/src/UBV/PracticaBundle/Form/parroquiaType.php new file mode 100644 index 0000000..dc1f30c --- /dev/null +++ b/src/UBV/PracticaBundle/Form/parroquiaType.php @@ -0,0 +1,36 @@ +add('descripcion')->add('codigo')->add('municipio'); + }/** + * {@inheritdoc} + */ + public function configureOptions(OptionsResolver $resolver) + { + $resolver->setDefaults(array( + 'data_class' => 'UBV\PracticaBundle\Entity\parroquia' + )); + } + + /** + * {@inheritdoc} + */ + public function getBlockPrefix() + { + return 'ubv_practicabundle_parroquia'; + } + + +} diff --git a/src/UBV/PracticaBundle/Tests/Controller/estadoControllerTest.php b/src/UBV/PracticaBundle/Tests/Controller/estadoControllerTest.php new file mode 100644 index 0000000..2167a62 --- /dev/null +++ b/src/UBV/PracticaBundle/Tests/Controller/estadoControllerTest.php @@ -0,0 +1,55 @@ +request('GET', '/estado/'); + $this->assertEquals(200, $client->getResponse()->getStatusCode(), "Unexpected HTTP status code for GET /estado/"); + $crawler = $client->click($crawler->selectLink('Create a new entry')->link()); + + // Fill in the form and submit it + $form = $crawler->selectButton('Create')->form(array( + 'ubv_practicabundle_estado[field_name]' => 'Test', + // ... other fields to fill + )); + + $client->submit($form); + $crawler = $client->followRedirect(); + + // Check data in the show view + $this->assertGreaterThan(0, $crawler->filter('td:contains("Test")')->count(), 'Missing element td:contains("Test")'); + + // Edit the entity + $crawler = $client->click($crawler->selectLink('Edit')->link()); + + $form = $crawler->selectButton('Update')->form(array( + 'ubv_practicabundle_estado[field_name]' => 'Foo', + // ... other fields to fill + )); + + $client->submit($form); + $crawler = $client->followRedirect(); + + // Check the element contains an attribute with value equals "Foo" + $this->assertGreaterThan(0, $crawler->filter('[value="Foo"]')->count(), 'Missing element [value="Foo"]'); + + // Delete the entity + $client->submit($crawler->selectButton('Delete')->form()); + $crawler = $client->followRedirect(); + + // Check the entity has been delete on the list + $this->assertNotRegExp('/Foo/', $client->getResponse()->getContent()); + } + + */ +} diff --git a/src/UBV/PracticaBundle/Tests/Controller/municipioControllerTest.php b/src/UBV/PracticaBundle/Tests/Controller/municipioControllerTest.php new file mode 100644 index 0000000..33aee19 --- /dev/null +++ b/src/UBV/PracticaBundle/Tests/Controller/municipioControllerTest.php @@ -0,0 +1,55 @@ +request('GET', '/municipio/'); + $this->assertEquals(200, $client->getResponse()->getStatusCode(), "Unexpected HTTP status code for GET /municipio/"); + $crawler = $client->click($crawler->selectLink('Create a new entry')->link()); + + // Fill in the form and submit it + $form = $crawler->selectButton('Create')->form(array( + 'ubv_practicabundle_municipio[field_name]' => 'Test', + // ... other fields to fill + )); + + $client->submit($form); + $crawler = $client->followRedirect(); + + // Check data in the show view + $this->assertGreaterThan(0, $crawler->filter('td:contains("Test")')->count(), 'Missing element td:contains("Test")'); + + // Edit the entity + $crawler = $client->click($crawler->selectLink('Edit')->link()); + + $form = $crawler->selectButton('Update')->form(array( + 'ubv_practicabundle_municipio[field_name]' => 'Foo', + // ... other fields to fill + )); + + $client->submit($form); + $crawler = $client->followRedirect(); + + // Check the element contains an attribute with value equals "Foo" + $this->assertGreaterThan(0, $crawler->filter('[value="Foo"]')->count(), 'Missing element [value="Foo"]'); + + // Delete the entity + $client->submit($crawler->selectButton('Delete')->form()); + $crawler = $client->followRedirect(); + + // Check the entity has been delete on the list + $this->assertNotRegExp('/Foo/', $client->getResponse()->getContent()); + } + + */ +} diff --git a/src/UBV/PracticaBundle/Tests/Controller/parroquiaControllerTest.php b/src/UBV/PracticaBundle/Tests/Controller/parroquiaControllerTest.php new file mode 100644 index 0000000..1d6441a --- /dev/null +++ b/src/UBV/PracticaBundle/Tests/Controller/parroquiaControllerTest.php @@ -0,0 +1,55 @@ +request('GET', '/parroquia/'); + $this->assertEquals(200, $client->getResponse()->getStatusCode(), "Unexpected HTTP status code for GET /parroquia/"); + $crawler = $client->click($crawler->selectLink('Create a new entry')->link()); + + // Fill in the form and submit it + $form = $crawler->selectButton('Create')->form(array( + 'ubv_practicabundle_parroquia[field_name]' => 'Test', + // ... other fields to fill + )); + + $client->submit($form); + $crawler = $client->followRedirect(); + + // Check data in the show view + $this->assertGreaterThan(0, $crawler->filter('td:contains("Test")')->count(), 'Missing element td:contains("Test")'); + + // Edit the entity + $crawler = $client->click($crawler->selectLink('Edit')->link()); + + $form = $crawler->selectButton('Update')->form(array( + 'ubv_practicabundle_parroquia[field_name]' => 'Foo', + // ... other fields to fill + )); + + $client->submit($form); + $crawler = $client->followRedirect(); + + // Check the element contains an attribute with value equals "Foo" + $this->assertGreaterThan(0, $crawler->filter('[value="Foo"]')->count(), 'Missing element [value="Foo"]'); + + // Delete the entity + $client->submit($crawler->selectButton('Delete')->form()); + $crawler = $client->followRedirect(); + + // Check the entity has been delete on the list + $this->assertNotRegExp('/Foo/', $client->getResponse()->getContent()); + } + + */ +} -- 2.0.0