Commit eac6c16ba7a5778890fbdaf50afb983083f06451
1 parent
cd6846b368
Exists in
feature/juan
creacion de crud y modificacion de los mismos
Showing
8 changed files
with
420 additions
and
4 deletions
Show diff stats
app/Resources/views/ambiente/edit.html.twig
| ... | ... | @@ -0,0 +1,21 @@ |
| 1 | +{% extends 'base.html.twig' %} | |
| 2 | + | |
| 3 | +{% block body %} | |
| 4 | + <h1>Ambiente edit</h1> | |
| 5 | + | |
| 6 | + {{ form_start(edit_form) }} | |
| 7 | + {{ form_widget(edit_form) }} | |
| 8 | + <input type="submit" value="Edit" /> | |
| 9 | + {{ form_end(edit_form) }} | |
| 10 | + | |
| 11 | + <ul> | |
| 12 | + <li> | |
| 13 | + <a href="{{ path('ambiente_index') }}">Back to the list</a> | |
| 14 | + </li> | |
| 15 | + <li> | |
| 16 | + {{ form_start(delete_form) }} | |
| 17 | + <input type="submit" value="Delete"> | |
| 18 | + {{ form_end(delete_form) }} | |
| 19 | + </li> | |
| 20 | + </ul> | |
| 21 | +{% endblock %} | ... | ... |
app/Resources/views/ambiente/index.html.twig
| ... | ... | @@ -0,0 +1,47 @@ |
| 1 | +{% extends 'base.html.twig' %} | |
| 2 | + | |
| 3 | +{% block body %} | |
| 4 | + <h1>Ambientes list</h1> | |
| 5 | + | |
| 6 | + <table> | |
| 7 | + <thead> | |
| 8 | + <tr> | |
| 9 | + <th>Id</th> | |
| 10 | + <th>Descripcion</th> | |
| 11 | + <th>Codigo</th> | |
| 12 | + <th>Direccion</th> | |
| 13 | + <th>Coordenadautmnorte</th> | |
| 14 | + <th>Coordenadautmoeste</th> | |
| 15 | + <th>Actions</th> | |
| 16 | + </tr> | |
| 17 | + </thead> | |
| 18 | + <tbody> | |
| 19 | + {% for ambiente in ambientes %} | |
| 20 | + <tr> | |
| 21 | + <td><a href="{{ path('ambiente_show', { 'id': ambiente.id }) }}">{{ ambiente.id }}</a></td> | |
| 22 | + <td>{{ ambiente.descripcion }}</td> | |
| 23 | + <td>{{ ambiente.codigo }}</td> | |
| 24 | + <td>{{ ambiente.direccion }}</td> | |
| 25 | + <td>{{ ambiente.coordenadaUtmNorte }}</td> | |
| 26 | + <td>{{ ambiente.coordenadaUtmOeste }}</td> | |
| 27 | + <td> | |
| 28 | + <ul> | |
| 29 | + <li> | |
| 30 | + <a href="{{ path('ambiente_show', { 'id': ambiente.id }) }}">show</a> | |
| 31 | + </li> | |
| 32 | + <li> | |
| 33 | + <a href="{{ path('ambiente_edit', { 'id': ambiente.id }) }}">edit</a> | |
| 34 | + </li> | |
| 35 | + </ul> | |
| 36 | + </td> | |
| 37 | + </tr> | |
| 38 | + {% endfor %} | |
| 39 | + </tbody> | |
| 40 | + </table> | |
| 41 | + | |
| 42 | + <ul> | |
| 43 | + <li> | |
| 44 | + <a href="{{ path('ambiente_new') }}">Create a new ambiente</a> | |
| 45 | + </li> | |
| 46 | + </ul> | |
| 47 | +{% endblock %} | ... | ... |
app/Resources/views/ambiente/new.html.twig
| ... | ... | @@ -0,0 +1,16 @@ |
| 1 | +{% extends 'base.html.twig' %} | |
| 2 | + | |
| 3 | +{% block body %} | |
| 4 | + <h1>Ambiente creation</h1> | |
| 5 | + | |
| 6 | + {{ form_start(form) }} | |
| 7 | + {{ form_widget(form) }} | |
| 8 | + <input type="submit" value="Create" /> | |
| 9 | + {{ form_end(form) }} | |
| 10 | + | |
| 11 | + <ul> | |
| 12 | + <li> | |
| 13 | + <a href="{{ path('ambiente_index') }}">Back to the list</a> | |
| 14 | + </li> | |
| 15 | + </ul> | |
| 16 | +{% endblock %} | ... | ... |
app/Resources/views/ambiente/show.html.twig
| ... | ... | @@ -0,0 +1,48 @@ |
| 1 | +{% extends 'base.html.twig' %} | |
| 2 | + | |
| 3 | +{% block body %} | |
| 4 | + <h1>Ambiente</h1> | |
| 5 | + | |
| 6 | + <table> | |
| 7 | + <tbody> | |
| 8 | + <tr> | |
| 9 | + <th>Id</th> | |
| 10 | + <td>{{ ambiente.id }}</td> | |
| 11 | + </tr> | |
| 12 | + <tr> | |
| 13 | + <th>Descripcion</th> | |
| 14 | + <td>{{ ambiente.descripcion }}</td> | |
| 15 | + </tr> | |
| 16 | + <tr> | |
| 17 | + <th>Codigo</th> | |
| 18 | + <td>{{ ambiente.codigo }}</td> | |
| 19 | + </tr> | |
| 20 | + <tr> | |
| 21 | + <th>Direccion</th> | |
| 22 | + <td>{{ ambiente.direccion }}</td> | |
| 23 | + </tr> | |
| 24 | + <tr> | |
| 25 | + <th>Coordenadautmnorte</th> | |
| 26 | + <td>{{ ambiente.coordenadaUtmNorte }}</td> | |
| 27 | + </tr> | |
| 28 | + <tr> | |
| 29 | + <th>Coordenadautmoeste</th> | |
| 30 | + <td>{{ ambiente.coordenadaUtmOeste }}</td> | |
| 31 | + </tr> | |
| 32 | + </tbody> | |
| 33 | + </table> | |
| 34 | + | |
| 35 | + <ul> | |
| 36 | + <li> | |
| 37 | + <a href="{{ path('ambiente_index') }}">Back to the list</a> | |
| 38 | + </li> | |
| 39 | + <li> | |
| 40 | + <a href="{{ path('ambiente_edit', { 'id': ambiente.id }) }}">Edit</a> | |
| 41 | + </li> | |
| 42 | + <li> | |
| 43 | + {{ form_start(delete_form) }} | |
| 44 | + <input type="submit" value="Delete"> | |
| 45 | + {{ form_end(delete_form) }} | |
| 46 | + </li> | |
| 47 | + </ul> | |
| 48 | +{% endblock %} | ... | ... |
src/UBV/PracticaBundle/Controller/ambienteController.php
| ... | ... | @@ -0,0 +1,138 @@ |
| 1 | +<?php | |
| 2 | + | |
| 3 | +namespace UBV\PracticaBundle\Controller; | |
| 4 | + | |
| 5 | +use UBV\PracticaBundle\Entity\ambiente; | |
| 6 | +use Symfony\Bundle\FrameworkBundle\Controller\Controller; | |
| 7 | +use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; | |
| 8 | +use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;use Symfony\Component\HttpFoundation\Request; | |
| 9 | + | |
| 10 | +/** | |
| 11 | + * Ambiente controller. | |
| 12 | + * | |
| 13 | + * @Route("ambiente") | |
| 14 | + */ | |
| 15 | +class ambienteController extends Controller | |
| 16 | +{ | |
| 17 | + /** | |
| 18 | + * Lists all ambiente entities. | |
| 19 | + * | |
| 20 | + * @Route("/", name="ambiente_index") | |
| 21 | + * @Method("GET") | |
| 22 | + */ | |
| 23 | + public function indexAction() | |
| 24 | + { | |
| 25 | + $em = $this->getDoctrine()->getManager(); | |
| 26 | + | |
| 27 | + $ambientes = $em->getRepository('UBVPracticaBundle:ambiente')->findAll(); | |
| 28 | + | |
| 29 | + return $this->render('ambiente/index.html.twig', array( | |
| 30 | + 'ambientes' => $ambientes, | |
| 31 | + )); | |
| 32 | + } | |
| 33 | + | |
| 34 | + /** | |
| 35 | + * Creates a new ambiente entity. | |
| 36 | + * | |
| 37 | + * @Route("/new", name="ambiente_new") | |
| 38 | + * @Method({"GET", "POST"}) | |
| 39 | + */ | |
| 40 | + public function newAction(Request $request) | |
| 41 | + { | |
| 42 | + $ambiente = new Ambiente(); | |
| 43 | + $form = $this->createForm('UBV\PracticaBundle\Form\ambienteType', $ambiente); | |
| 44 | + $form->handleRequest($request); | |
| 45 | + | |
| 46 | + if ($form->isSubmitted() && $form->isValid()) { | |
| 47 | + $em = $this->getDoctrine()->getManager(); | |
| 48 | + $em->persist($ambiente); | |
| 49 | + $em->flush(); | |
| 50 | + $this->get('session')->getFlashBag()->set( 'success', array( 'title' => 'Guardado!', 'message' => 'Estado creado satisfactoriamente.' ) ); | |
| 51 | + | |
| 52 | + return $this->redirectToRoute('ambiente_index', array('id' => $ambiente->getId())); | |
| 53 | + } | |
| 54 | + | |
| 55 | + return $this->render('ambiente/new.html.twig', array( | |
| 56 | + 'ambiente' => $ambiente, | |
| 57 | + 'form' => $form->createView(), | |
| 58 | + )); | |
| 59 | + } | |
| 60 | + | |
| 61 | + /** | |
| 62 | + * Finds and displays a ambiente entity. | |
| 63 | + * | |
| 64 | + * @Route("/{id}", name="ambiente_show") | |
| 65 | + * @Method("GET") | |
| 66 | + */ | |
| 67 | + public function showAction(ambiente $ambiente) | |
| 68 | + { | |
| 69 | + $deleteForm = $this->createDeleteForm($ambiente); | |
| 70 | + | |
| 71 | + return $this->render('ambiente/show.html.twig', array( | |
| 72 | + 'ambiente' => $ambiente, | |
| 73 | + 'delete_form' => $deleteForm->createView(), | |
| 74 | + )); | |
| 75 | + } | |
| 76 | + | |
| 77 | + /** | |
| 78 | + * Displays a form to edit an existing ambiente entity. | |
| 79 | + * | |
| 80 | + * @Route("/{id}/edit", name="ambiente_edit") | |
| 81 | + * @Method({"GET", "POST"}) | |
| 82 | + */ | |
| 83 | + public function editAction(Request $request, ambiente $ambiente) | |
| 84 | + { | |
| 85 | + $deleteForm = $this->createDeleteForm($ambiente); | |
| 86 | + $editForm = $this->createForm('UBV\PracticaBundle\Form\ambienteType', $ambiente); | |
| 87 | + $editForm->handleRequest($request); | |
| 88 | + | |
| 89 | + if ($editForm->isSubmitted() && $editForm->isValid()) { | |
| 90 | + $this->getDoctrine()->getManager()->flush(); | |
| 91 | + $this->get('session')->getFlashBag()->set( 'success', array( 'title' => 'Guardado!', 'message' => 'Estado editado satisfactoriamente.' ) ); | |
| 92 | + return $this->redirectToRoute('ambiente_edit', array('id' => $ambiente->getId())); | |
| 93 | + } | |
| 94 | + | |
| 95 | + return $this->render('ambiente/edit.html.twig', array( | |
| 96 | + 'ambiente' => $ambiente, | |
| 97 | + 'edit_form' => $editForm->createView(), | |
| 98 | + 'delete_form' => $deleteForm->createView(), | |
| 99 | + )); | |
| 100 | + } | |
| 101 | + | |
| 102 | + /** | |
| 103 | + * Deletes a ambiente entity. | |
| 104 | + * | |
| 105 | + * @Route("/{id}", name="ambiente_delete") | |
| 106 | + * @Method("DELETE") | |
| 107 | + */ | |
| 108 | + public function deleteAction(Request $request, ambiente $ambiente) | |
| 109 | + { | |
| 110 | + $form = $this->createDeleteForm($ambiente); | |
| 111 | + $form->handleRequest($request); | |
| 112 | + | |
| 113 | + if ($form->isSubmitted() && $form->isValid()) { | |
| 114 | + $em = $this->getDoctrine()->getManager(); | |
| 115 | + $em->remove($ambiente); | |
| 116 | + $em->flush(); | |
| 117 | + | |
| 118 | + } | |
| 119 | + | |
| 120 | + return $this->redirectToRoute('ambiente_index'); | |
| 121 | + } | |
| 122 | + | |
| 123 | + /** | |
| 124 | + * Creates a form to delete a ambiente entity. | |
| 125 | + * | |
| 126 | + * @param ambiente $ambiente The ambiente entity | |
| 127 | + * | |
| 128 | + * @return \Symfony\Component\Form\Form The form | |
| 129 | + */ | |
| 130 | + private function createDeleteForm(ambiente $ambiente) | |
| 131 | + { | |
| 132 | + return $this->createFormBuilder() | |
| 133 | + ->setAction($this->generateUrl('ambiente_delete', array('id' => $ambiente->getId()))) | |
| 134 | + ->setMethod('DELETE') | |
| 135 | + ->getForm() | |
| 136 | + ; | |
| 137 | + } | |
| 138 | +} | ... | ... |
src/UBV/PracticaBundle/Entity/ambiente.php
| ... | ... | @@ -3,6 +3,7 @@ |
| 3 | 3 | namespace UBV\PracticaBundle\Entity; |
| 4 | 4 | |
| 5 | 5 | use Doctrine\ORM\Mapping as ORM; |
| 6 | +use Symfony\Component\Validator\Constraints as Assert; | |
| 6 | 7 | |
| 7 | 8 | /** |
| 8 | 9 | * ambiente |
| ... | ... | @@ -20,20 +21,35 @@ class ambiente |
| 20 | 21 | * @ORM\GeneratedValue(strategy="AUTO") |
| 21 | 22 | */ |
| 22 | 23 | private $id; |
| 23 | - | |
| 24 | 24 | /** |
| 25 | + * @Assert\NotBlank( message= "Por favor introduzca la Descripciรณn del ambiente") | |
| 26 | + * @Assert\NotNull(message= "Por favor introduzca la Descripciรณn del ambiente", groups={"Default"}) | |
| 27 | + *@Assert\Length( | |
| 28 | + * min = 5, | |
| 29 | + * max = 100, | |
| 30 | + * minMessage = "Por favor introduzca una descripcion del ambiente mรกs especรญfico. Mรญnimo {{ limit }} caracteres", | |
| 31 | + * maxMessage = "Por favor introduzca un Nombre del ambiente mรกs breve. Mรกximo {{ limit }} caracteres", | |
| 32 | + *) | |
| 25 | 33 | * @var string |
| 26 | - * | |
| 27 | - * @ORM\Column(name="descripcion", type="string", length=255) | |
| 34 | + * | |
| 35 | + * @ORM\Column(name="descripcion", type="string", length=50) | |
| 28 | 36 | */ |
| 29 | 37 | private $descripcion; |
| 30 | 38 | |
| 31 | 39 | /** |
| 40 | + * @Assert\NotBlank( message= "Por favor introduzca un codigo del ambiente") | |
| 41 | + * @Assert\NotNull(message= "Por favor introduzca un codigo del ambiente", groups={"Default"}) | |
| 42 | + *@Assert\Length( | |
| 43 | + * min = 5, | |
| 44 | + * max = 30, | |
| 45 | + * minMessage = "Por favor introduzca una descripcion del ambiente mรกs especรญfico. Mรญnimo {{ limit }} caracteres", | |
| 46 | + * maxMessage = "Por favor introduzca un Nombre del ambiente mรกs breve. Mรกximo {{ limit }} caracteres", | |
| 47 | + *) | |
| 32 | 48 | * @var int |
| 33 | 49 | * |
| 34 | 50 | * @ORM\Column(name="codigo", type="integer") |
| 35 | 51 | */ |
| 36 | - private $codigo; | |
| 52 | + private $codigo; | |
| 37 | 53 | |
| 38 | 54 | /** |
| 39 | 55 | * @var string | ... | ... |
src/UBV/PracticaBundle/Form/ambienteType.php
| ... | ... | @@ -0,0 +1,75 @@ |
| 1 | +<?php | |
| 2 | + | |
| 3 | +namespace UBV\PracticaBundle\Form; | |
| 4 | + | |
| 5 | +use Symfony\Component\Form\AbstractType; | |
| 6 | +use Symfony\Component\Form\FormBuilderInterface; | |
| 7 | +use Symfony\Component\OptionsResolver\OptionsResolver; | |
| 8 | + | |
| 9 | +class ambienteType extends AbstractType | |
| 10 | +{ | |
| 11 | + /** | |
| 12 | + * {@inheritdoc} | |
| 13 | + */ | |
| 14 | + public function buildForm(FormBuilderInterface $builder, array $options) | |
| 15 | + { | |
| 16 | + $builder | |
| 17 | + ->add('descripcion','text', array('label' | |
| 18 | + => 'Descripciรณn del Estado', 'attr' | |
| 19 | + => array('class' | |
| 20 | + => 'form-control','placeholder' | |
| 21 | + =>'Descripcion del Estado'), 'label_attr' | |
| 22 | + => array('class' | |
| 23 | + => 'control-label'), )) | |
| 24 | + | |
| 25 | + ->add('codigo','integer', array('label' | |
| 26 | + => 'codigo', 'attr' | |
| 27 | + => array('class' | |
| 28 | + => 'form-control','placeholder' | |
| 29 | + =>'Descripcion del Estado'), 'label_attr' | |
| 30 | + => array('class' | |
| 31 | + => 'control-label'), )) | |
| 32 | + | |
| 33 | + ->add('direccion','text', array('label' | |
| 34 | + => 'Direccion del ambiente', 'attr' | |
| 35 | + => array('class' | |
| 36 | + => 'form-control','placeholder' | |
| 37 | + =>'Descripcion del Estado'), 'label_attr' | |
| 38 | + => array('class' | |
| 39 | + => 'control-label'), )) | |
| 40 | + | |
| 41 | + ->add('coordenadaUtmNorte','text', array('label' | |
| 42 | + => 'coordenadas norte', 'attr' | |
| 43 | + => array('class' | |
| 44 | + => 'form-control','placeholder' | |
| 45 | + =>'Descripcion del Estado'), 'label_attr' | |
| 46 | + => array('class' | |
| 47 | + => 'control-label'), )) | |
| 48 | + | |
| 49 | + ->add('coordenadaUtmOeste','text', array('label' | |
| 50 | + => 'cordenadas este', 'attr' | |
| 51 | + => array('class' | |
| 52 | + => 'form-control','placeholder' | |
| 53 | + =>'Descripcion del Estado'), 'label_attr' | |
| 54 | + => array('class' | |
| 55 | + => 'control-label'), )); | |
| 56 | + }/** | |
| 57 | + * {@inheritdoc} | |
| 58 | + */ | |
| 59 | + public function configureOptions(OptionsResolver $resolver) | |
| 60 | + { | |
| 61 | + $resolver->setDefaults(array( | |
| 62 | + 'data_class' => 'UBV\PracticaBundle\Entity\ambiente' | |
| 63 | + )); | |
| 64 | + } | |
| 65 | + | |
| 66 | + /** | |
| 67 | + * {@inheritdoc} | |
| 68 | + */ | |
| 69 | + public function getBlockPrefix() | |
| 70 | + { | |
| 71 | + return 'ubv_practicabundle_ambiente'; | |
| 72 | + } | |
| 73 | + | |
| 74 | + | |
| 75 | +} | ... | ... |
src/UBV/PracticaBundle/Tests/Controller/ambienteControllerTest.php
| ... | ... | @@ -0,0 +1,55 @@ |
| 1 | +<?php | |
| 2 | + | |
| 3 | +namespace UBV\PracticaBundle\Tests\Controller; | |
| 4 | + | |
| 5 | +use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; | |
| 6 | + | |
| 7 | +class ambienteControllerTest extends WebTestCase | |
| 8 | +{ | |
| 9 | + /* | |
| 10 | + public function testCompleteScenario() | |
| 11 | + { | |
| 12 | + // Create a new client to browse the application | |
| 13 | + $client = static::createClient(); | |
| 14 | + | |
| 15 | + // Create a new entry in the database | |
| 16 | + $crawler = $client->request('GET', '/ambiente/'); | |
| 17 | + $this->assertEquals(200, $client->getResponse()->getStatusCode(), "Unexpected HTTP status code for GET /ambiente/"); | |
| 18 | + $crawler = $client->click($crawler->selectLink('Create a new entry')->link()); | |
| 19 | + | |
| 20 | + // Fill in the form and submit it | |
| 21 | + $form = $crawler->selectButton('Create')->form(array( | |
| 22 | + 'ubv_practicabundle_ambiente[field_name]' => 'Test', | |
| 23 | + // ... other fields to fill | |
| 24 | + )); | |
| 25 | + | |
| 26 | + $client->submit($form); | |
| 27 | + $crawler = $client->followRedirect(); | |
| 28 | + | |
| 29 | + // Check data in the show view | |
| 30 | + $this->assertGreaterThan(0, $crawler->filter('td:contains("Test")')->count(), 'Missing element td:contains("Test")'); | |
| 31 | + | |
| 32 | + // Edit the entity | |
| 33 | + $crawler = $client->click($crawler->selectLink('Edit')->link()); | |
| 34 | + | |
| 35 | + $form = $crawler->selectButton('Update')->form(array( | |
| 36 | + 'ubv_practicabundle_ambiente[field_name]' => 'Foo', | |
| 37 | + // ... other fields to fill | |
| 38 | + )); | |
| 39 | + | |
| 40 | + $client->submit($form); | |
| 41 | + $crawler = $client->followRedirect(); | |
| 42 | + | |
| 43 | + // Check the element contains an attribute with value equals "Foo" | |
| 44 | + $this->assertGreaterThan(0, $crawler->filter('[value="Foo"]')->count(), 'Missing element [value="Foo"]'); | |
| 45 | + | |
| 46 | + // Delete the entity | |
| 47 | + $client->submit($crawler->selectButton('Delete')->form()); | |
| 48 | + $crawler = $client->followRedirect(); | |
| 49 | + | |
| 50 | + // Check the entity has been delete on the list | |
| 51 | + $this->assertNotRegExp('/Foo/', $client->getResponse()->getContent()); | |
| 52 | + } | |
| 53 | + | |
| 54 | + */ | |
| 55 | +} | ... | ... |