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

Aldea edit

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

Aldeas list

+ + + + + + + + + + + + + + {% for aldea in aldeas %} + + + + + + + + + {% endfor %} + +
IdDescripcionCodigosucreCodigoaldeaEstatusActions
{{ aldea.id }}{{ aldea.descripcion }}{{ aldea.codigoSucre }}{{ aldea.codigoAldea }}{% if aldea.estatus %}Yes{% else %}No{% endif %} + +
+ + +{% endblock %} diff --git a/app/Resources/views/aldea/new.html.twig b/app/Resources/views/aldea/new.html.twig new file mode 100644 index 0000000..8e666d7 --- /dev/null +++ b/app/Resources/views/aldea/new.html.twig @@ -0,0 +1,16 @@ +{% extends 'base.html.twig' %} + +{% block body %} +

Aldea creation

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

Aldea

+ + + + + + + + + + + + + + + + + + + + + + + + +
Id{{ aldea.id }}
Descripcion{{ aldea.descripcion }}
Codigosucre{{ aldea.codigoSucre }}
Codigoaldea{{ aldea.codigoAldea }}
Estatus{% if aldea.estatus %}Yes{% else %}No{% endif %}
+ + +{% endblock %} diff --git a/src/UBV/PracticaBundle/Controller/aldeaController.php b/src/UBV/PracticaBundle/Controller/aldeaController.php new file mode 100644 index 0000000..5ba1221 --- /dev/null +++ b/src/UBV/PracticaBundle/Controller/aldeaController.php @@ -0,0 +1,137 @@ +getDoctrine()->getManager(); + + $aldeas = $em->getRepository('UBVPracticaBundle:aldea')->findAll(); + + return $this->render('aldea/index.html.twig', array( + 'aldeas' => $aldeas, + )); + } + + /** + * Creates a new aldea entity. + * + * @Route("/new", name="aldea_new") + * @Method({"GET", "POST"}) + */ + public function newAction(Request $request) + { + $aldea = new Aldea(); + $form = $this->createForm('UBV\PracticaBundle\Form\aldeaType', $aldea); + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $em = $this->getDoctrine()->getManager(); + $em->persist($aldea); + $em->flush(); + + return $this->redirectToRoute('aldea_index', array('id' => $aldea->getId())); + } + + return $this->render('aldea/new.html.twig', array( + 'aldea' => $aldea, + 'form' => $form->createView(), + )); + } + + /** + * Finds and displays a aldea entity. + * + * @Route("/{id}", name="aldea_show") + * @Method("GET") + */ + public function showAction(aldea $aldea) + { + $deleteForm = $this->createDeleteForm($aldea); + + return $this->render('aldea/show.html.twig', array( + 'aldea' => $aldea, + 'delete_form' => $deleteForm->createView(), + )); + } + + /** + * Displays a form to edit an existing aldea entity. + * + * @Route("/{id}/edit", name="aldea_edit") + * @Method({"GET", "POST"}) + */ + public function editAction(Request $request, aldea $aldea) + { + $deleteForm = $this->createDeleteForm($aldea); + $editForm = $this->createForm('UBV\PracticaBundle\Form\aldeaType', $aldea); + $editForm->handleRequest($request); + + if ($editForm->isSubmitted() && $editForm->isValid()) { + $this->getDoctrine()->getManager()->flush(); + + return $this->redirectToRoute('aldea_edit', array('id' => $aldea->getId())); + } + + return $this->render('aldea/edit.html.twig', array( + 'aldea' => $aldea, + 'edit_form' => $editForm->createView(), + 'delete_form' => $deleteForm->createView(), + )); + } + + /** + * Deletes a aldea entity. + * + * @Route("/{id}", name="aldea_delete") + * @Method("DELETE") + */ + public function deleteAction(Request $request, aldea $aldea) + { + $form = $this->createDeleteForm($aldea); + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $em = $this->getDoctrine()->getManager(); + $em->remove($aldea); + $em->flush(); + } + + return $this->redirectToRoute('aldea_index'); + } + + /** + * Creates a form to delete a aldea entity. + * + * @param aldea $aldea The aldea entity + * + * @return \Symfony\Component\Form\Form The form + */ + private function createDeleteForm(aldea $aldea) + { + return $this->createFormBuilder() + ->setAction($this->generateUrl('aldea_delete', array('id' => $aldea->getId()))) + ->setMethod('DELETE') + ->getForm() + ; + } +} diff --git a/src/UBV/PracticaBundle/Entity/aldea.php b/src/UBV/PracticaBundle/Entity/aldea.php index a7b3a08..d1be8d5 100644 --- a/src/UBV/PracticaBundle/Entity/aldea.php +++ b/src/UBV/PracticaBundle/Entity/aldea.php @@ -3,6 +3,7 @@ namespace UBV\PracticaBundle\Entity; use Doctrine\ORM\Mapping as ORM; +use Symfony\Component\Validator\Constraints as Assert; /** * aldea @@ -22,6 +23,13 @@ class aldea private $id; /** + *@Assert\NotBlank( message= "Por favor introduzca la Descripción de la Aldea") + *@Assert\NotNull(message= "Por favor introduzca la Descripción de la Aldea", groups={"Default"}) + *@Assert\Length( + * min = 5, + * max = 100, + * minMessage = "Por favor introduzca un Nombre de la Aldea más específico. Mínimo {{ limit }} caracteres", + * maxMessage = "Por favor introduzca un Nombre de la Aldea más breve. Máximo {{ limit }} caracteres", * @var string * * @ORM\Column(name="descripcion", type="string", length=255) @@ -29,6 +37,13 @@ class aldea private $descripcion; /** + *@Assert\NotBlank( message= "Por favor introduzca el codigo de la Aldea") + *@Assert\NotNull(message= "Por favor introduzca el codigo de la Aldea", groups={"Default"}) + *@Assert\Length( + * min = 5, + * max = 30, + * minMessage = "Por favor introduzca el codigo de la Aldea más específico. Mínimo {{ limit }} caracteres", + * maxMessage = "Por favor introduzca el codigo de la Aldea más breve. Máximo {{ limit }} caracteres", * @var int * * @ORM\Column(name="codigo_sucre", type="integer") diff --git a/src/UBV/PracticaBundle/Form/aldeaType.php b/src/UBV/PracticaBundle/Form/aldeaType.php new file mode 100644 index 0000000..a91f60f --- /dev/null +++ b/src/UBV/PracticaBundle/Form/aldeaType.php @@ -0,0 +1,48 @@ +add('descripcion','text', array( 'label' + => 'Descripción de la aldea', 'attr' + => array('class' + => 'form-control','placeholder'=>'Descripcion de la aldea'), 'label_attr' + => array('class' => 'control-label'), )) + ->add('codigoSucre','integer', array( 'label' + => 'codigo Sucre', 'attr' + => array('class' + => 'form-control','placeholder'=>'codigo sucre'), 'label_attr' + => array('class' => 'control-label'), )) + ->add('codigoAldea') + ->add('estatus'); + }/** + * {@inheritdoc} + */ + public function configureOptions(OptionsResolver $resolver) + { + $resolver->setDefaults(array( + 'data_class' => 'UBV\PracticaBundle\Entity\aldea' + )); + } + + /** + * {@inheritdoc} + */ + public function getBlockPrefix() + { + return 'ubv_practicabundle_aldea'; + } + + +} diff --git a/src/UBV/PracticaBundle/Tests/Controller/aldeaControllerTest.php b/src/UBV/PracticaBundle/Tests/Controller/aldeaControllerTest.php new file mode 100644 index 0000000..84ebcb6 --- /dev/null +++ b/src/UBV/PracticaBundle/Tests/Controller/aldeaControllerTest.php @@ -0,0 +1,55 @@ +request('GET', '/aldea/'); + $this->assertEquals(200, $client->getResponse()->getStatusCode(), "Unexpected HTTP status code for GET /aldea/"); + $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_aldea[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_aldea[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()); + } + + */ +}