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

Seccion edit

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

Seccions list

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

Seccion creation

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

Seccion

+ + + + + + + + + + + + + + + + +
Id{{ seccion.id }}
Descripcion{{ seccion.descripcion }}
Codigo{{ seccion.codigo }}
+ + +{% endblock %} diff --git a/src/UBV/PracticaBundle/Controller/seccionController.php b/src/UBV/PracticaBundle/Controller/seccionController.php new file mode 100644 index 0000000..f5c0e04 --- /dev/null +++ b/src/UBV/PracticaBundle/Controller/seccionController.php @@ -0,0 +1,136 @@ +getDoctrine()->getManager(); + + $seccions = $em->getRepository('UBVPracticaBundle:seccion')->findAll(); + + return $this->render('seccion/index.html.twig', array( + 'seccions' => $seccions, + )); + } + + /** + * Creates a new seccion entity. + * + * @Route("/new", name="seccion_new") + * @Method({"GET", "POST"}) + */ + public function newAction(Request $request) + { + $seccion = new Seccion(); + $form = $this->createForm('UBV\PracticaBundle\Form\seccionType', $seccion); + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $em = $this->getDoctrine()->getManager(); + $em->persist($seccion); + $em->flush(); + + return $this->redirectToRoute('seccion_index', array('id' => $seccion->getId())); + } + + return $this->render('seccion/new.html.twig', array( + 'seccion' => $seccion, + 'form' => $form->createView(), + )); + } + + /** + * Finds and displays a seccion entity. + * + * @Route("/{id}", name="seccion_show") + * @Method("GET") + */ + public function showAction(seccion $seccion) + { + $deleteForm = $this->createDeleteForm($seccion); + + return $this->render('seccion/show.html.twig', array( + 'seccion' => $seccion, + 'delete_form' => $deleteForm->createView(), + )); + } + + /** + * Displays a form to edit an existing seccion entity. + * + * @Route("/{id}/edit", name="seccion_edit") + * @Method({"GET", "POST"}) + */ + public function editAction(Request $request, seccion $seccion) + { + $deleteForm = $this->createDeleteForm($seccion); + $editForm = $this->createForm('UBV\PracticaBundle\Form\seccionType', $seccion); + $editForm->handleRequest($request); + + if ($editForm->isSubmitted() && $editForm->isValid()) { + $this->getDoctrine()->getManager()->flush(); + + return $this->redirectToRoute('seccion_index', array('id' => $seccion->getId())); + } + + return $this->render('seccion/edit.html.twig', array( + 'seccion' => $seccion, + 'edit_form' => $editForm->createView(), + 'delete_form' => $deleteForm->createView(), + )); + } + + /** + * Deletes a seccion entity. + * + * @Route("/{id}", name="seccion_delete") + * @Method("DELETE") + */ + public function deleteAction(Request $request, seccion $seccion) + { + $form = $this->createDeleteForm($seccion); + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $em = $this->getDoctrine()->getManager(); + $em->remove($seccion); + $em->flush(); + } + + return $this->redirectToRoute('seccion_index'); + } + + /** + * Creates a form to delete a seccion entity. + * + * @param seccion $seccion The seccion entity + * + * @return \Symfony\Component\Form\Form The form + */ + private function createDeleteForm(seccion $seccion) + { + return $this->createFormBuilder() + ->setAction($this->generateUrl('seccion_delete', array('id' => $seccion->getId()))) + ->setMethod('DELETE') + ->getForm() + ; + } +} diff --git a/src/UBV/PracticaBundle/Entity/seccion.php b/src/UBV/PracticaBundle/Entity/seccion.php index 8f2fd92..493fc72 100644 --- a/src/UBV/PracticaBundle/Entity/seccion.php +++ b/src/UBV/PracticaBundle/Entity/seccion.php @@ -3,6 +3,7 @@ namespace UBV\PracticaBundle\Entity; use Doctrine\ORM\Mapping as ORM; +use Symfony\Component\Validator\Constraints as Assert; /** * seccion @@ -22,6 +23,14 @@ class seccion private $id; /** + * @Assert\NotBlank( message= "Por favor introduzca la Descripción de la Seccion") + * @Assert\NotNull(message= "Por favor introduzca la Descripción del Seccion", groups={"Default"}) + * @Assert\Length( + * min = 7, + * max = 8, + * 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) @@ -29,6 +38,14 @@ class seccion private $descripcion; /** + * @Assert\NotBlank( message= "Por favor introduzca el Codigo de la Seccion") + * @Assert\NotNull(message= "Por favor introduzca el Codigo del Seccion", groups={"Default"}) + * @Assert\Length( + * min = 7, + * max = 8, + * minMessage = "Por favor introduzca un nombre de seccion más específico. Mínimo {{ limit }} caracteres", + * maxMessage = "Por favor introduzca un nombre de seccion más breve. Máximo {{ limit }} caracteres", + * ) * @var int * * @ORM\Column(name="codigo", type="integer") diff --git a/src/UBV/PracticaBundle/Form/seccionType.php b/src/UBV/PracticaBundle/Form/seccionType.php new file mode 100644 index 0000000..19f2927 --- /dev/null +++ b/src/UBV/PracticaBundle/Form/seccionType.php @@ -0,0 +1,36 @@ +add('descripcion')->add('codigo'); + }/** + * {@inheritdoc} + */ + public function configureOptions(OptionsResolver $resolver) + { + $resolver->setDefaults(array( + 'data_class' => 'UBV\PracticaBundle\Entity\seccion' + )); + } + + /** + * {@inheritdoc} + */ + public function getBlockPrefix() + { + return 'ubv_practicabundle_seccion'; + } + + +} diff --git a/src/UBV/PracticaBundle/Tests/Controller/seccionControllerTest.php b/src/UBV/PracticaBundle/Tests/Controller/seccionControllerTest.php new file mode 100644 index 0000000..a66184f --- /dev/null +++ b/src/UBV/PracticaBundle/Tests/Controller/seccionControllerTest.php @@ -0,0 +1,55 @@ +request('GET', '/seccion/'); + $this->assertEquals(200, $client->getResponse()->getStatusCode(), "Unexpected HTTP status code for GET /seccion/"); + $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_seccion[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_seccion[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()); + } + + */ +}