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