Commit f038995f583522a465bbeff9855384917ab70201
1 parent
e46fab24a3
Exists in
feature/jacqueline
creacion de crud y modificacion de formularios
Showing
8 changed files
with
361 additions
and
1 deletions
Show diff stats
app/Resources/views/banco/edit.html.twig
... | ... | @@ -0,0 +1,21 @@ |
1 | +{% extends 'base.html.twig' %} | |
2 | + | |
3 | +{% block body %} | |
4 | + <h1>Banco 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('banco_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/banco/index.html.twig
... | ... | @@ -0,0 +1,41 @@ |
1 | +{% extends 'base.html.twig' %} | |
2 | + | |
3 | +{% block body %} | |
4 | + <h1>Bancos list</h1> | |
5 | + | |
6 | + <table> | |
7 | + <thead> | |
8 | + <tr> | |
9 | + <th>Id</th> | |
10 | + <th>Descripcion</th> | |
11 | + <th>Codigo</th> | |
12 | + <th>Actions</th> | |
13 | + </tr> | |
14 | + </thead> | |
15 | + <tbody> | |
16 | + {% for banco in bancos %} | |
17 | + <tr> | |
18 | + <td><a href="{{ path('banco_show', { 'id': banco.id }) }}">{{ banco.id }}</a></td> | |
19 | + <td>{{ banco.descripcion }}</td> | |
20 | + <td>{{ banco.codigo }}</td> | |
21 | + <td> | |
22 | + <ul> | |
23 | + <li> | |
24 | + <a href="{{ path('banco_show', { 'id': banco.id }) }}">show</a> | |
25 | + </li> | |
26 | + <li> | |
27 | + <a href="{{ path('banco_edit', { 'id': banco.id }) }}">edit</a> | |
28 | + </li> | |
29 | + </ul> | |
30 | + </td> | |
31 | + </tr> | |
32 | + {% endfor %} | |
33 | + </tbody> | |
34 | + </table> | |
35 | + | |
36 | + <ul> | |
37 | + <li> | |
38 | + <a href="{{ path('banco_new') }}">Create a new banco</a> | |
39 | + </li> | |
40 | + </ul> | |
41 | +{% endblock %} | ... | ... |
app/Resources/views/banco/new.html.twig
... | ... | @@ -0,0 +1,16 @@ |
1 | +{% extends 'base.html.twig' %} | |
2 | + | |
3 | +{% block body %} | |
4 | + <h1>Banco 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('banco_index') }}">Back to the list</a> | |
14 | + </li> | |
15 | + </ul> | |
16 | +{% endblock %} | ... | ... |
app/Resources/views/banco/show.html.twig
... | ... | @@ -0,0 +1,36 @@ |
1 | +{% extends 'base.html.twig' %} | |
2 | + | |
3 | +{% block body %} | |
4 | + <h1>Banco</h1> | |
5 | + | |
6 | + <table> | |
7 | + <tbody> | |
8 | + <tr> | |
9 | + <th>Id</th> | |
10 | + <td>{{ banco.id }}</td> | |
11 | + </tr> | |
12 | + <tr> | |
13 | + <th>Descripcion</th> | |
14 | + <td>{{ banco.descripcion }}</td> | |
15 | + </tr> | |
16 | + <tr> | |
17 | + <th>Codigo</th> | |
18 | + <td>{{ banco.codigo }}</td> | |
19 | + </tr> | |
20 | + </tbody> | |
21 | + </table> | |
22 | + | |
23 | + <ul> | |
24 | + <li> | |
25 | + <a href="{{ path('banco_index') }}">Back to the list</a> | |
26 | + </li> | |
27 | + <li> | |
28 | + <a href="{{ path('banco_edit', { 'id': banco.id }) }}">Edit</a> | |
29 | + </li> | |
30 | + <li> | |
31 | + {{ form_start(delete_form) }} | |
32 | + <input type="submit" value="Delete"> | |
33 | + {{ form_end(delete_form) }} | |
34 | + </li> | |
35 | + </ul> | |
36 | +{% endblock %} | ... | ... |
src/UBV/PracticaBundle/Controller/BancoController.php
... | ... | @@ -0,0 +1,136 @@ |
1 | +<?php | |
2 | + | |
3 | +namespace UBV\PracticaBundle\Controller; | |
4 | + | |
5 | +use UBV\PracticaBundle\Entity\Banco; | |
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 | + * Banco controller. | |
12 | + * | |
13 | + * @Route("banco") | |
14 | + */ | |
15 | +class BancoController extends Controller | |
16 | +{ | |
17 | + /** | |
18 | + * Lists all banco entities. | |
19 | + * | |
20 | + * @Route("/", name="banco_index") | |
21 | + * @Method("GET") | |
22 | + */ | |
23 | + public function indexAction() | |
24 | + { | |
25 | + $em = $this->getDoctrine()->getManager(); | |
26 | + | |
27 | + $bancos = $em->getRepository('UBVPracticaBundle:Banco')->findAll(); | |
28 | + | |
29 | + return $this->render('banco/index.html.twig', array( | |
30 | + 'bancos' => $bancos, | |
31 | + )); | |
32 | + } | |
33 | + | |
34 | + /** | |
35 | + * Creates a new banco entity. | |
36 | + * | |
37 | + * @Route("/new", name="banco_new") | |
38 | + * @Method({"GET", "POST"}) | |
39 | + */ | |
40 | + public function newAction(Request $request) | |
41 | + { | |
42 | + $banco = new Banco(); | |
43 | + $form = $this->createForm('UBV\PracticaBundle\Form\BancoType', $banco); | |
44 | + $form->handleRequest($request); | |
45 | + | |
46 | + if ($form->isSubmitted() && $form->isValid()) { | |
47 | + $em = $this->getDoctrine()->getManager(); | |
48 | + $em->persist($banco); | |
49 | + $em->flush(); $this->get('session')->getFlashBag()->set( 'success', array( 'title' => 'Guardado!', 'message' => 'Estado creado satisfactoriamente.' ) ); | |
50 | + | |
51 | + return $this->redirectToRoute('<banco_index', array('id' => $banco->getId())); | |
52 | + } | |
53 | + | |
54 | + return $this->render('banco/new.html.twig', array( | |
55 | + 'banco' => $banco, | |
56 | + 'form' => $form->createView(), | |
57 | + )); | |
58 | + } | |
59 | + | |
60 | + /** | |
61 | + * Finds and displays a banco entity. | |
62 | + * | |
63 | + * @Route("/{id}", name="banco_show") | |
64 | + * @Method("GET") | |
65 | + */ | |
66 | + public function showAction(Banco $banco) | |
67 | + { | |
68 | + $deleteForm = $this->createDeleteForm($banco); | |
69 | + | |
70 | + return $this->render('banco/show.html.twig', array( | |
71 | + 'banco' => $banco, | |
72 | + 'delete_form' => $deleteForm->createView(), | |
73 | + )); | |
74 | + } | |
75 | + | |
76 | + /** | |
77 | + * Displays a form to edit an existing banco entity. | |
78 | + * | |
79 | + * @Route("/{id}/edit", name="banco_edit") | |
80 | + * @Method({"GET", "POST"}) | |
81 | + */ | |
82 | + public function editAction(Request $request, Banco $banco) | |
83 | + { | |
84 | + $deleteForm = $this->createDeleteForm($banco); | |
85 | + $editForm = $this->createForm('UBV\PracticaBundle\Form\BancoType', $banco); | |
86 | + $editForm->handleRequest($request); | |
87 | + | |
88 | + if ($editForm->isSubmitted() && $editForm->isValid()) { | |
89 | + $this->getDoctrine()->getManager()->flush(); | |
90 | + $this->get('session')->getFlashBag()->set( 'success', array( 'title' => 'Guardado!', 'message' => 'Estado editado satisfactoriamente.' ) ); | |
91 | + return $this->redirectToRoute('banco_edit', array('id' => $banco->getId())); | |
92 | + } | |
93 | + | |
94 | + return $this->render('banco/edit.html.twig', array( | |
95 | + 'banco' => $banco, | |
96 | + 'edit_form' => $editForm->createView(), | |
97 | + 'delete_form' => $deleteForm->createView(), | |
98 | + )); | |
99 | + } | |
100 | + | |
101 | + /** | |
102 | + * Deletes a banco entity. | |
103 | + * | |
104 | + * @Route("/{id}", name="banco_delete") | |
105 | + * @Method("DELETE") | |
106 | + */ | |
107 | + public function deleteAction(Request $request, Banco $banco) | |
108 | + { | |
109 | + $form = $this->createDeleteForm($banco); | |
110 | + $form->handleRequest($request); | |
111 | + | |
112 | + if ($form->isSubmitted() && $form->isValid()) { | |
113 | + $em = $this->getDoctrine()->getManager(); | |
114 | + $em->remove($banco); | |
115 | + $em->flush(); | |
116 | + } | |
117 | + | |
118 | + return $this->redirectToRoute('banco_index'); | |
119 | + } | |
120 | + | |
121 | + /** | |
122 | + * Creates a form to delete a banco entity. | |
123 | + * | |
124 | + * @param Banco $banco The banco entity | |
125 | + * | |
126 | + * @return \Symfony\Component\Form\Form The form | |
127 | + */ | |
128 | + private function createDeleteForm(Banco $banco) | |
129 | + { | |
130 | + return $this->createFormBuilder() | |
131 | + ->setAction($this->generateUrl('banco_delete', array('id' => $banco->getId()))) | |
132 | + ->setMethod('DELETE') | |
133 | + ->getForm() | |
134 | + ; | |
135 | + } | |
136 | +} | ... | ... |
src/UBV/PracticaBundle/Entity/Banco.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 | * Banco |
... | ... | @@ -22,6 +23,14 @@ class Banco |
22 | 23 | private $id; |
23 | 24 | |
24 | 25 | /** |
26 | + *@Assert\NotBlank( message= "Por favor introduzca la Descripciรณn del Banco") | |
27 | + *@Assert\NotNull(message= "Por favor introduzca la Descripciรณn del Banco", groups={"Default"}) | |
28 | +*@Assert\Length( | |
29 | + * min = 5, | |
30 | + * max = 150, | |
31 | + * minMessage = "Por favor introduzca un Nombre de Banco mรกs especรญfico. Mรญnimo {{ limit }} caracteres", | |
32 | + * maxMessage = "Por favor introduzca un Nombre de Banco mรกs breve. Mรกximo {{ limit }} caracteres", | |
33 | +*) | |
25 | 34 | * @var string |
26 | 35 | * |
27 | 36 | * @ORM\Column(name="descripcion", type="string", length=255) |
... | ... | @@ -29,8 +38,15 @@ class Banco |
29 | 38 | private $descripcion; |
30 | 39 | |
31 | 40 | /** |
41 | + *@Assert\NotBlank( message= "Por favor introduzca la Descripciรณn del Banco") | |
42 | + *@Assert\NotNull(message= "Por favor introduzca la Descripciรณn del Banco", groups={"Default"}) | |
43 | +*@Assert\Length( | |
44 | + * min = 5, | |
45 | + * max = 150, | |
46 | + * minMessage = "Por favor introduzca un Nombre de Banco mรกs especรญfico. Mรญnimo {{ limit }} caracteres", | |
47 | + * maxMessage = "Por favor introduzca un Nombre de Banco mรกs breve. Mรกximo {{ limit }} caracteres", | |
48 | +*) | |
32 | 49 | * @var int |
33 | - * | |
34 | 50 | * @ORM\Column(name="codigo", type="integer") |
35 | 51 | */ |
36 | 52 | private $codigo; | ... | ... |
src/UBV/PracticaBundle/Form/BancoType.php
... | ... | @@ -0,0 +1,39 @@ |
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 BancoType extends AbstractType | |
10 | +{ | |
11 | + /** | |
12 | + * {@inheritdoc} | |
13 | + */ | |
14 | + public function buildForm(FormBuilderInterface $builder, array $options) | |
15 | + { | |
16 | + $builder | |
17 | + ->add('descripcion','text', array( 'label'=> 'Descripciรณn del Estado', 'attr' => array('class' => 'form-control','placeholder'=>'Descripcion del Estado'), 'label_attr' => array('class' => 'control-label'), )) | |
18 | + | |
19 | + ->add('codigo', 'integer',array( 'attr' => array('class' => 'form-control','placeholder'=>'codigo del Estado'), 'label_attr' => array('class' => 'control-label'), )); | |
20 | + }/** | |
21 | + * {@inheritdoc} | |
22 | + */ | |
23 | + public function configureOptions(OptionsResolver $resolver) | |
24 | + { | |
25 | + $resolver->setDefaults(array( | |
26 | + 'data_class' => 'UBV\PracticaBundle\Entity\Banco' | |
27 | + )); | |
28 | + } | |
29 | + | |
30 | + /** | |
31 | + * {@inheritdoc} | |
32 | + */ | |
33 | + public function getBlockPrefix() | |
34 | + { | |
35 | + return 'ubv_practicabundle_banco'; | |
36 | + } | |
37 | + | |
38 | + | |
39 | +} | ... | ... |
src/UBV/PracticaBundle/Tests/Controller/BancoControllerTest.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 BancoControllerTest 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', '/banco/'); | |
17 | + $this->assertEquals(200, $client->getResponse()->getStatusCode(), "Unexpected HTTP status code for GET /banco/"); | |
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_banco[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_banco[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 | +} | ... | ... |