From 49a509d1d6f22350ecf57b7f7adf7e0053eea3f3 Mon Sep 17 00:00:00 2001 From: Hector Hernandez Date: Fri, 26 Jan 2018 10:41:56 -0400 Subject: [PATCH] Creacion de la entidad educacion --- app/Resources/views/educacion/edit.html.twig | 21 ++++ app/Resources/views/educacion/index.html.twig | 43 +++++++ app/Resources/views/educacion/new.html.twig | 16 +++ app/Resources/views/educacion/show.html.twig | 40 ++++++ .../Controller/educacionController.php | 136 +++++++++++++++++++++ src/UBV/PracticaBundle/Entity/educacion.php | 128 +++++++++++++++++++ src/UBV/PracticaBundle/Form/educacionType.php | 36 ++++++ .../Repository/educacionRepository.php | 13 ++ .../Tests/Controller/educacionControllerTest.php | 55 +++++++++ 9 files changed, 488 insertions(+) create mode 100644 app/Resources/views/educacion/edit.html.twig create mode 100644 app/Resources/views/educacion/index.html.twig create mode 100644 app/Resources/views/educacion/new.html.twig create mode 100644 app/Resources/views/educacion/show.html.twig create mode 100644 src/UBV/PracticaBundle/Controller/educacionController.php create mode 100644 src/UBV/PracticaBundle/Entity/educacion.php create mode 100644 src/UBV/PracticaBundle/Form/educacionType.php create mode 100644 src/UBV/PracticaBundle/Repository/educacionRepository.php create mode 100644 src/UBV/PracticaBundle/Tests/Controller/educacionControllerTest.php diff --git a/app/Resources/views/educacion/edit.html.twig b/app/Resources/views/educacion/edit.html.twig new file mode 100644 index 0000000..a69a383 --- /dev/null +++ b/app/Resources/views/educacion/edit.html.twig @@ -0,0 +1,21 @@ +{% extends 'base.html.twig' %} + +{% block body %} +

Educacion edit

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

Educacions list

+ + + + + + + + + + + + + {% for educacion in educacions %} + + + + + + + + {% endfor %} + +
IdUniversidadTituloFegresoActions
{{ educacion.id }}{{ educacion.universidad }}{{ educacion.titulo }}{% if educacion.fegreso %}{{ educacion.fegreso|date('Y-m-d') }}{% endif %} + +
+ + +{% endblock %} diff --git a/app/Resources/views/educacion/new.html.twig b/app/Resources/views/educacion/new.html.twig new file mode 100644 index 0000000..9aa41ab --- /dev/null +++ b/app/Resources/views/educacion/new.html.twig @@ -0,0 +1,16 @@ +{% extends 'base.html.twig' %} + +{% block body %} +

Educacion creation

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

Educacion

+ + + + + + + + + + + + + + + + + + + + +
Id{{ educacion.id }}
Universidad{{ educacion.universidad }}
Titulo{{ educacion.titulo }}
Fegreso{% if educacion.fegreso %}{{ educacion.fegreso|date('Y-m-d') }}{% endif %}
+ + +{% endblock %} diff --git a/src/UBV/PracticaBundle/Controller/educacionController.php b/src/UBV/PracticaBundle/Controller/educacionController.php new file mode 100644 index 0000000..48c1698 --- /dev/null +++ b/src/UBV/PracticaBundle/Controller/educacionController.php @@ -0,0 +1,136 @@ +getDoctrine()->getManager(); + + $educacions = $em->getRepository('UBVPracticaBundle:educacion')->findAll(); + + return $this->render('educacion/index.html.twig', array( + 'educacions' => $educacions, + )); + } + + /** + * Creates a new educacion entity. + * + * @Route("/new", name="educacion_new") + * @Method({"GET", "POST"}) + */ + public function newAction(Request $request) + { + $educacion = new Educacion(); + $form = $this->createForm('UBV\PracticaBundle\Form\educacionType', $educacion); + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $em = $this->getDoctrine()->getManager(); + $em->persist($educacion); + $em->flush(); + + return $this->redirectToRoute('educacion_show', array('id' => $educacion->getId())); + } + + return $this->render('educacion/new.html.twig', array( + 'educacion' => $educacion, + 'form' => $form->createView(), + )); + } + + /** + * Finds and displays a educacion entity. + * + * @Route("/{id}", name="educacion_show") + * @Method("GET") + */ + public function showAction(educacion $educacion) + { + $deleteForm = $this->createDeleteForm($educacion); + + return $this->render('educacion/show.html.twig', array( + 'educacion' => $educacion, + 'delete_form' => $deleteForm->createView(), + )); + } + + /** + * Displays a form to edit an existing educacion entity. + * + * @Route("/{id}/edit", name="educacion_edit") + * @Method({"GET", "POST"}) + */ + public function editAction(Request $request, educacion $educacion) + { + $deleteForm = $this->createDeleteForm($educacion); + $editForm = $this->createForm('UBV\PracticaBundle\Form\educacionType', $educacion); + $editForm->handleRequest($request); + + if ($editForm->isSubmitted() && $editForm->isValid()) { + $this->getDoctrine()->getManager()->flush(); + + return $this->redirectToRoute('educacion_edit', array('id' => $educacion->getId())); + } + + return $this->render('educacion/edit.html.twig', array( + 'educacion' => $educacion, + 'edit_form' => $editForm->createView(), + 'delete_form' => $deleteForm->createView(), + )); + } + + /** + * Deletes a educacion entity. + * + * @Route("/{id}", name="educacion_delete") + * @Method("DELETE") + */ + public function deleteAction(Request $request, educacion $educacion) + { + $form = $this->createDeleteForm($educacion); + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $em = $this->getDoctrine()->getManager(); + $em->remove($educacion); + $em->flush(); + } + + return $this->redirectToRoute('educacion_index'); + } + + /** + * Creates a form to delete a educacion entity. + * + * @param educacion $educacion The educacion entity + * + * @return \Symfony\Component\Form\Form The form + */ + private function createDeleteForm(educacion $educacion) + { + return $this->createFormBuilder() + ->setAction($this->generateUrl('educacion_delete', array('id' => $educacion->getId()))) + ->setMethod('DELETE') + ->getForm() + ; + } +} diff --git a/src/UBV/PracticaBundle/Entity/educacion.php b/src/UBV/PracticaBundle/Entity/educacion.php new file mode 100644 index 0000000..d7cd063 --- /dev/null +++ b/src/UBV/PracticaBundle/Entity/educacion.php @@ -0,0 +1,128 @@ +id; + } + + /** + * Set universidad + * + * @param string $universidad + * + * @return educacion + */ + public function setUniversidad($universidad) + { + $this->universidad = $universidad; + + return $this; + } + + /** + * Get universidad + * + * @return string + */ + public function getUniversidad() + { + return $this->universidad; + } + + /** + * Set titulo + * + * @param string $titulo + * + * @return educacion + */ + public function setTitulo($titulo) + { + $this->titulo = $titulo; + + return $this; + } + + /** + * Get titulo + * + * @return string + */ + public function getTitulo() + { + return $this->titulo; + } + + /** + * Set fegreso + * + * @param \DateTime $fegreso + * + * @return educacion + */ + public function setFegreso($fegreso) + { + $this->fegreso = $fegreso; + + return $this; + } + + /** + * Get fegreso + * + * @return \DateTime + */ + public function getFegreso() + { + return $this->fegreso; + } +} + diff --git a/src/UBV/PracticaBundle/Form/educacionType.php b/src/UBV/PracticaBundle/Form/educacionType.php new file mode 100644 index 0000000..bc9f77b --- /dev/null +++ b/src/UBV/PracticaBundle/Form/educacionType.php @@ -0,0 +1,36 @@ +add('universidad')->add('titulo')->add('fegreso'); + }/** + * {@inheritdoc} + */ + public function configureOptions(OptionsResolver $resolver) + { + $resolver->setDefaults(array( + 'data_class' => 'UBV\PracticaBundle\Entity\educacion' + )); + } + + /** + * {@inheritdoc} + */ + public function getBlockPrefix() + { + return 'ubv_practicabundle_educacion'; + } + + +} diff --git a/src/UBV/PracticaBundle/Repository/educacionRepository.php b/src/UBV/PracticaBundle/Repository/educacionRepository.php new file mode 100644 index 0000000..706b935 --- /dev/null +++ b/src/UBV/PracticaBundle/Repository/educacionRepository.php @@ -0,0 +1,13 @@ +request('GET', '/educacion/'); + $this->assertEquals(200, $client->getResponse()->getStatusCode(), "Unexpected HTTP status code for GET /educacion/"); + $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_educacion[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_educacion[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