diff --git a/app/Resources/views/persona/edit.html.twig b/app/Resources/views/persona/edit.html.twig new file mode 100644 index 0000000..10d4c38 --- /dev/null +++ b/app/Resources/views/persona/edit.html.twig @@ -0,0 +1,21 @@ +{% extends 'base.html.twig' %} + +{% block body %} +

Persona edit

+ + {{ form_start(edit_form) }} + {{ form_widget(edit_form) }} + + {{ form_end(edit_form) }} + + +{% endblock %} diff --git a/app/Resources/views/persona/index.html.twig b/app/Resources/views/persona/index.html.twig new file mode 100644 index 0000000..941fcf7 --- /dev/null +++ b/app/Resources/views/persona/index.html.twig @@ -0,0 +1,47 @@ +{% extends 'base.html.twig' %} + +{% block body %} +

Personas list

+ + + + + + + + + + + + + + + {% for persona in personas %} + + + + + + + + + + {% endfor %} + +
IdNombreApellidoCedulaGeneroDireccionActions
{{ persona.id }}{{ persona.nombre }}{{ persona.apellido }}{{ persona.cedula }}{{ persona.genero }}{{ persona.direccion }} + +
+ + +{% endblock %} diff --git a/app/Resources/views/persona/new.html.twig b/app/Resources/views/persona/new.html.twig new file mode 100644 index 0000000..4988328 --- /dev/null +++ b/app/Resources/views/persona/new.html.twig @@ -0,0 +1,16 @@ +{% extends 'base.html.twig' %} + +{% block body %} +

Persona creation

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

Persona

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Id{{ persona.id }}
Nombre{{ persona.nombre }}
Apellido{{ persona.apellido }}
Cedula{{ persona.cedula }}
Genero{{ persona.genero }}
Direccion{{ persona.direccion }}
+ + +{% endblock %} diff --git a/src/UBV/PracticaBundle/Controller/personaController.php b/src/UBV/PracticaBundle/Controller/personaController.php new file mode 100644 index 0000000..25dd72f --- /dev/null +++ b/src/UBV/PracticaBundle/Controller/personaController.php @@ -0,0 +1,136 @@ +getDoctrine()->getManager(); + + $personas = $em->getRepository('UBVPracticaBundle:persona')->findAll(); + + return $this->render('persona/index.html.twig', array( + 'personas' => $personas, + )); + } + + /** + * Creates a new persona entity. + * + * @Route("/new", name="persona_new") + * @Method({"GET", "POST"}) + */ + public function newAction(Request $request) + { + $persona = new Persona(); + $form = $this->createForm('UBV\PracticaBundle\Form\personaType', $persona); + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $em = $this->getDoctrine()->getManager(); + $em->persist($persona); + $em->flush(); + + return $this->redirectToRoute('persona_show', array('id' => $persona->getId())); + } + + return $this->render('persona/new.html.twig', array( + 'persona' => $persona, + 'form' => $form->createView(), + )); + } + + /** + * Finds and displays a persona entity. + * + * @Route("/{id}", name="persona_show") + * @Method("GET") + */ + public function showAction(persona $persona) + { + $deleteForm = $this->createDeleteForm($persona); + + return $this->render('persona/show.html.twig', array( + 'persona' => $persona, + 'delete_form' => $deleteForm->createView(), + )); + } + + /** + * Displays a form to edit an existing persona entity. + * + * @Route("/{id}/edit", name="persona_edit") + * @Method({"GET", "POST"}) + */ + public function editAction(Request $request, persona $persona) + { + $deleteForm = $this->createDeleteForm($persona); + $editForm = $this->createForm('UBV\PracticaBundle\Form\personaType', $persona); + $editForm->handleRequest($request); + + if ($editForm->isSubmitted() && $editForm->isValid()) { + $this->getDoctrine()->getManager()->flush(); + + return $this->redirectToRoute('persona_edit', array('id' => $persona->getId())); + } + + return $this->render('persona/edit.html.twig', array( + 'persona' => $persona, + 'edit_form' => $editForm->createView(), + 'delete_form' => $deleteForm->createView(), + )); + } + + /** + * Deletes a persona entity. + * + * @Route("/{id}", name="persona_delete") + * @Method("DELETE") + */ + public function deleteAction(Request $request, persona $persona) + { + $form = $this->createDeleteForm($persona); + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $em = $this->getDoctrine()->getManager(); + $em->remove($persona); + $em->flush(); + } + + return $this->redirectToRoute('persona_index'); + } + + /** + * Creates a form to delete a persona entity. + * + * @param persona $persona The persona entity + * + * @return \Symfony\Component\Form\Form The form + */ + private function createDeleteForm(persona $persona) + { + return $this->createFormBuilder() + ->setAction($this->generateUrl('persona_delete', array('id' => $persona->getId()))) + ->setMethod('DELETE') + ->getForm() + ; + } +} diff --git a/src/UBV/PracticaBundle/Entity/persona.php b/src/UBV/PracticaBundle/Entity/persona.php new file mode 100644 index 0000000..416a93f --- /dev/null +++ b/src/UBV/PracticaBundle/Entity/persona.php @@ -0,0 +1,190 @@ +id; + } + + /** + * Set nombre + * + * @param string $nombre + * + * @return persona + */ + public function setNombre($nombre) + { + $this->nombre = $nombre; + + return $this; + } + + /** + * Get nombre + * + * @return string + */ + public function getNombre() + { + return $this->nombre; + } + + /** + * Set apellido + * + * @param string $apellido + * + * @return persona + */ + public function setApellido($apellido) + { + $this->apellido = $apellido; + + return $this; + } + + /** + * Get apellido + * + * @return string + */ + public function getApellido() + { + return $this->apellido; + } + + /** + * Set cedula + * + * @param integer $cedula + * + * @return persona + */ + public function setCedula($cedula) + { + $this->cedula = $cedula; + + return $this; + } + + /** + * Get cedula + * + * @return int + */ + public function getCedula() + { + return $this->cedula; + } + + /** + * Set genero + * + * @param string $genero + * + * @return persona + */ + public function setGenero($genero) + { + $this->genero = $genero; + + return $this; + } + + /** + * Get genero + * + * @return string + */ + public function getGenero() + { + return $this->genero; + } + + /** + * Set direccion + * + * @param string $direccion + * + * @return persona + */ + public function setDireccion($direccion) + { + $this->direccion = $direccion; + + return $this; + } + + /** + * Get direccion + * + * @return string + */ + public function getDireccion() + { + return $this->direccion; + } +} + diff --git a/src/UBV/PracticaBundle/Form/personaType.php b/src/UBV/PracticaBundle/Form/personaType.php new file mode 100644 index 0000000..b42afb0 --- /dev/null +++ b/src/UBV/PracticaBundle/Form/personaType.php @@ -0,0 +1,36 @@ +add('nombre')->add('apellido')->add('cedula')->add('genero')->add('direccion'); + }/** + * {@inheritdoc} + */ + public function configureOptions(OptionsResolver $resolver) + { + $resolver->setDefaults(array( + 'data_class' => 'UBV\PracticaBundle\Entity\persona' + )); + } + + /** + * {@inheritdoc} + */ + public function getBlockPrefix() + { + return 'ubv_practicabundle_persona'; + } + + +} diff --git a/src/UBV/PracticaBundle/Repository/personaRepository.php b/src/UBV/PracticaBundle/Repository/personaRepository.php new file mode 100644 index 0000000..9939b35 --- /dev/null +++ b/src/UBV/PracticaBundle/Repository/personaRepository.php @@ -0,0 +1,13 @@ +request('GET', '/persona/'); + $this->assertEquals(200, $client->getResponse()->getStatusCode(), "Unexpected HTTP status code for GET /persona/"); + $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_persona[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_persona[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()); + } + + */ +}