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

Usuario edit

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

Usuarios list

+ + + + + + + + + + + + + + {% for usuario in usuarios %} + + + + + + + + + {% endfor %} + +
IdNombreApellidoCedulaFechanacimientoActions
{{ usuario.id }}{{ usuario.nombre }}{{ usuario.apellido }}{{ usuario.cedula }}{% if usuario.fechaNacimiento %}{{ usuario.fechaNacimiento|date('Y-m-d') }}{% endif %} + +
+ + +{% endblock %} diff --git a/app/Resources/views/usuario/new.html.twig b/app/Resources/views/usuario/new.html.twig new file mode 100644 index 0000000..5d2dbaa --- /dev/null +++ b/app/Resources/views/usuario/new.html.twig @@ -0,0 +1,26 @@ +{% extends 'base.html.twig' %} + +{% block body %} +

Usuario creation

+ +{{ form_start(form) }} +{{ form_row(form.nombre) }} +{{ form_row(form.apellido) }} +{{ form_row(form.cedula) }} +{{ form_row(form.edad) }} +{{ form_widget(form) }} + +{{ form_end(form) }} +{% block form_row %} +
+ + +{{ form_widget(form) }} +
+{% endblock form_row %} + +{% endblock %} diff --git a/app/Resources/views/usuario/show.html.twig b/app/Resources/views/usuario/show.html.twig new file mode 100644 index 0000000..2ee90b2 --- /dev/null +++ b/app/Resources/views/usuario/show.html.twig @@ -0,0 +1,44 @@ +{% extends 'base.html.twig' %} + +{% block body %} +

Usuario

+ + + + + + + + + + + + + + + + + + + + + + + + +
Id{{ usuario.id }}
Nombre{{ usuario.nombre }}
Apellido{{ usuario.apellido }}
Cedula{{ usuario.cedula }}
Fechanacimiento{% if usuario.fechaNacimiento %}{{ usuario.fechaNacimiento|date('Y-m-d') }}{% endif %}
+ + +{% endblock %} diff --git a/src/UBV/PracticaBundle/Controller/usuarioController.php b/src/UBV/PracticaBundle/Controller/usuarioController.php new file mode 100644 index 0000000..633024c --- /dev/null +++ b/src/UBV/PracticaBundle/Controller/usuarioController.php @@ -0,0 +1,136 @@ +getDoctrine()->getManager(); + + $usuarios = $em->getRepository('UBVPracticaBundle:usuario')->findAll(); + + return $this->render('usuario/index.html.twig', array( + 'usuarios' => $usuarios, + )); + } + + /** + * Creates a new usuario entity. + * + * @Route("/new", name="usuario_new") + * @Method({"GET", "POST"}) + */ + public function newAction(Request $request) + { + $usuario = new Usuario(); + $form = $this->createForm('UBV\PracticaBundle\Form\usuarioType', $usuario); + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $em = $this->getDoctrine()->getManager(); + $em->persist($usuario); + $em->flush(); + + return $this->redirectToRoute('usuario_show', array('id' => $usuario->getId())); + } + + return $this->render('usuario/new.html.twig', array( + 'usuario' => $usuario, + 'form' => $form->createView(), + )); + } + + /** + * Finds and displays a usuario entity. + * + * @Route("/{id}", name="usuario_show") + * @Method("GET") + */ + public function showAction(usuario $usuario) + { + $deleteForm = $this->createDeleteForm($usuario); + + return $this->render('usuario/show.html.twig', array( + 'usuario' => $usuario, + 'delete_form' => $deleteForm->createView(), + )); + } + + /** + * Displays a form to edit an existing usuario entity. + * + * @Route("/{id}/edit", name="usuario_edit") + * @Method({"GET", "POST"}) + */ + public function editAction(Request $request, usuario $usuario) + { + $deleteForm = $this->createDeleteForm($usuario); + $editForm = $this->createForm('UBV\PracticaBundle\Form\usuarioType', $usuario); + $editForm->handleRequest($request); + + if ($editForm->isSubmitted() && $editForm->isValid()) { + $this->getDoctrine()->getManager()->flush(); + + return $this->redirectToRoute('usuario_edit', array('id' => $usuario->getId())); + } + + return $this->render('usuario/edit.html.twig', array( + 'usuario' => $usuario, + 'edit_form' => $editForm->createView(), + 'delete_form' => $deleteForm->createView(), + )); + } + + /** + * Deletes a usuario entity. + * + * @Route("/{id}", name="usuario_delete") + * @Method("DELETE") + */ + public function deleteAction(Request $request, usuario $usuario) + { + $form = $this->createDeleteForm($usuario); + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $em = $this->getDoctrine()->getManager(); + $em->remove($usuario); + $em->flush(); + } + + return $this->redirectToRoute('usuario_index'); + } + + /** + * Creates a form to delete a usuario entity. + * + * @param usuario $usuario The usuario entity + * + * @return \Symfony\Component\Form\Form The form + */ + private function createDeleteForm(usuario $usuario) + { + return $this->createFormBuilder() + ->setAction($this->generateUrl('usuario_delete', array('id' => $usuario->getId()))) + ->setMethod('DELETE') + ->getForm() + ; + } +} diff --git a/src/UBV/PracticaBundle/Entity/usuario.php b/src/UBV/PracticaBundle/Entity/usuario.php new file mode 100644 index 0000000..fa4520b --- /dev/null +++ b/src/UBV/PracticaBundle/Entity/usuario.php @@ -0,0 +1,159 @@ +id; + } + + /** + * Set nombre + * + * @param string $nombre + * + * @return usuario + */ + 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 usuario + */ + 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 usuario + */ + public function setCedula($cedula) + { + $this->cedula = $cedula; + + return $this; + } + + /** + * Get cedula + * + * @return int + */ + public function getCedula() + { + return $this->cedula; + } + + /** + * Set fechaNacimiento + * + * @param \DateTime $fechaNacimiento + * + * @return usuario + */ + public function setFechaNacimiento($fechaNacimiento) + { + $this->fechaNacimiento = $fechaNacimiento; + + return $this; + } + + /** + * Get fechaNacimiento + * + * @return \DateTime + */ + public function getFechaNacimiento() + { + return $this->fechaNacimiento; + } +} + diff --git a/src/UBV/PracticaBundle/Form/usuarioType.php b/src/UBV/PracticaBundle/Form/usuarioType.php new file mode 100644 index 0000000..25a8d99 --- /dev/null +++ b/src/UBV/PracticaBundle/Form/usuarioType.php @@ -0,0 +1,36 @@ +add('nombre')->add('apellido')->add('cedula')->add('fechaNacimiento'); + }/** + * {@inheritdoc} + */ + public function configureOptions(OptionsResolver $resolver) + { + $resolver->setDefaults(array( + 'data_class' => 'UBV\PracticaBundle\Entity\usuario' + )); + } + + /** + * {@inheritdoc} + */ + public function getBlockPrefix() + { + return 'ubv_practicabundle_usuario'; + } + + +} diff --git a/src/UBV/PracticaBundle/Repository/usuarioRepository.php b/src/UBV/PracticaBundle/Repository/usuarioRepository.php new file mode 100644 index 0000000..dd8f37c --- /dev/null +++ b/src/UBV/PracticaBundle/Repository/usuarioRepository.php @@ -0,0 +1,13 @@ +request('GET', '/usuario/'); + $this->assertEquals(200, $client->getResponse()->getStatusCode(), "Unexpected HTTP status code for GET /usuario/"); + $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_usuario[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_usuario[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()); + } + + */ +}