From 0a5420d06e3940de669e1b458231fbca17270737 Mon Sep 17 00:00:00 2001 From: ubv Date: Mon, 5 Feb 2018 14:30:58 -0400 Subject: [PATCH] practica para no perder nada --- app/Resources/views/candidato/index.html.twig | 4 + app/Resources/views/candidato/new.html.twig | 96 ++++++++--- app/Resources/views/estado/index.html.twig | 2 +- .../PracticaBundle/Controller/estadoController.php | 5 +- .../Controller/municipioController.php | 3 +- src/UBV/PracticaBundle/Entity/candidato.php | 176 +++++++++++++++++++++ src/UBV/PracticaBundle/Entity/estado.php | 11 +- src/UBV/PracticaBundle/Entity/municipio.php | 11 ++ src/UBV/PracticaBundle/Form/candidatoType.php | 78 +++++++-- src/UBV/PracticaBundle/Form/estadoType.php | 8 +- src/UBV/PracticaBundle/Form/municipioType.php | 5 +- 11 files changed, 360 insertions(+), 39 deletions(-) diff --git a/app/Resources/views/candidato/index.html.twig b/app/Resources/views/candidato/index.html.twig index a00eddb..62155eb 100644 --- a/app/Resources/views/candidato/index.html.twig +++ b/app/Resources/views/candidato/index.html.twig @@ -33,6 +33,8 @@ Estado Municipio Direccion + Descripcion Aldea + Descripcion Estado Civil Actions @@ -51,6 +53,8 @@ {{ candidato.estado }} {{ candidato.municipio }} {{ candidato.direccion }} + {{ candidato.aldea }} + {{ candidato.estadoCivil }} diff --git a/app/Resources/views/candidato/new.html.twig b/app/Resources/views/candidato/new.html.twig index ef84385..94035c4 100644 --- a/app/Resources/views/candidato/new.html.twig +++ b/app/Resources/views/candidato/new.html.twig @@ -1,10 +1,20 @@ {% extends 'base.html.twig' %} - + {% block body %}

Creacion de Candidato

+ {{ form_start(form, {'attr': {'novalidate': 'novalidate'}, 'action': path('candidato_new')}) }}
-

Datos Personales

-
+
+
+ +
+
+
{{ form_label(form.nombre) }} {{ form_widget(form.nombre) }} @@ -35,6 +45,15 @@ {% endif %}
+
+ {{ form_label(form.estadoCivil) }} + {{ form_widget(form.estadoCivil) }} + {% if form.estadoCivil.vars.errors[0].message is defined %} + + {{ form.estadoCivil.vars.errors[0].message }} + + {% endif %} +
@@ -47,8 +66,22 @@ {% endif %}
-
-

Datos Academicos

+
+
+
+
+
+ +
+
+ +
+
@@ -93,10 +126,34 @@ {% endif %}
+
+ + {{ form_label(form.aldea) }} + {{ form_widget(form.aldea) }} + {% if form.aldea.vars.errors[0].message is defined %} + + {{ form.aldea.vars.errors[0].message }} + + {% endif %} +
-
-
-

Ubicacion Geografica

+
+
+
+
+
+ +
+
+ +
+
+
{{ form_label(form.pais) }} @@ -108,21 +165,13 @@ {% endif %}
-
- - - {% if form.estado.vars.errors[0].message is defined %} - - {{ form.estado.vars.errors[0].message }} - + {{ form_label(form.estado) }} + {{ form_widget(form.estado) }} + {% if form.pais.vars.errors[0].message is defined %} + + {{ form.estado.vars.errors[0].message }} + {% endif %} -
@@ -145,6 +194,9 @@ {% endif %}
+
+
+
diff --git a/app/Resources/views/estado/index.html.twig b/app/Resources/views/estado/index.html.twig index 48391f4..eb8c306 100644 --- a/app/Resources/views/estado/index.html.twig +++ b/app/Resources/views/estado/index.html.twig @@ -3,7 +3,7 @@ {% block body %}

Estados list

- +
diff --git a/src/UBV/PracticaBundle/Controller/estadoController.php b/src/UBV/PracticaBundle/Controller/estadoController.php index 9777484..e0b63a3 100644 --- a/src/UBV/PracticaBundle/Controller/estadoController.php +++ b/src/UBV/PracticaBundle/Controller/estadoController.php @@ -5,7 +5,9 @@ namespace UBV\PracticaBundle\Controller; use UBV\PracticaBundle\Entity\estado; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; -use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;use Symfony\Component\HttpFoundation\Request; +use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; +use Symfony\Component\HttpFoundation\Request; +use UBV\PracticaBundle\Form\MunicipioType; /** * Estado controller. @@ -57,6 +59,7 @@ class estadoController extends Controller )); } + /** * Finds and displays a estado entity. * diff --git a/src/UBV/PracticaBundle/Controller/municipioController.php b/src/UBV/PracticaBundle/Controller/municipioController.php index cb324d3..a8aa180 100644 --- a/src/UBV/PracticaBundle/Controller/municipioController.php +++ b/src/UBV/PracticaBundle/Controller/municipioController.php @@ -5,7 +5,8 @@ namespace UBV\PracticaBundle\Controller; use UBV\PracticaBundle\Entity\municipio; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; -use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;use Symfony\Component\HttpFoundation\Request; +use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; +use Symfony\Component\HttpFoundation\Request; /** * Municipio controller. diff --git a/src/UBV/PracticaBundle/Entity/candidato.php b/src/UBV/PracticaBundle/Entity/candidato.php index e3f9073..72c95e5 100644 --- a/src/UBV/PracticaBundle/Entity/candidato.php +++ b/src/UBV/PracticaBundle/Entity/candidato.php @@ -4,6 +4,10 @@ namespace UBV\PracticaBundle\Entity; use Doctrine\ORM\Mapping as ORM; +use Symfony\Component\Validator\Constraints as Assert; +use Symfony\Component\Validator\Constraints\NotBlank; +use Symfony\Component\Validator\Constraints\Length; + /** * candidato * @@ -22,6 +26,21 @@ class candidato private $id; /** + * + * @Assert\NotNull(message= "Por favor introduzca su Nombre", groups={"Default"}) + * @Assert\NotBlank( message= "Por favor introduzca un Nombre valido", groups={"Default"}) + * @Assert\Length( + * min = 2, + * max = 45, + * minMessage = "Tu Nombre debe tener como minimo {{ limit }} letras", + * maxMessage = "Tu Nombre no debe exceder de {{ limit }} letras" + * ) + * @Assert\Regex( + * pattern="/\d/", + * match=false, + * message="Tu Nombre no debe contener numeros" + *) + * * @var string * * @ORM\Column(name="nombre", type="string", length=255) @@ -29,6 +48,21 @@ class candidato private $nombre; /** + * + * @Assert\NotNull(message= "Por favor introduzca su Nombre", groups={"Default"}) + * @Assert\NotBlank( message= "Por favor introduzca un Nombre valido", groups={"Default"}) + * @Assert\Length( + * min = 2, + * max = 45, + * minMessage = "Tu Nombre debe tener como minimo {{ limit }} letras", + * maxMessage = "Tu Nombre no debe exceder de {{ limit }} letras" + * ) + * @Assert\Regex( + * pattern="/\d/", + * match=false, + * message="Tu Nombre no debe contener numeros" + *) + * * @var string * * @ORM\Column(name="apellido", type="string", length=255) @@ -36,6 +70,17 @@ class candidato private $apellido; /** + * + * @Assert\NotNull(message= "Por favor introduzca su Cedula", groups={"Default"}) + * @Assert\NotBlank( message= "Por favor introduzca una Cedula valida", groups={"Default"}) + * @Assert\Length( + * min = 2, + * max = 45, + * minMessage = "Tu Cedula debe tener como minimo {{ limit }} numeros", + * maxMessage = "Tu Cedula no debe exceder de {{ limit }} numeros" + * ) + * + * * @var int * * @ORM\Column(name="cedula", type="integer", unique=true) @@ -50,6 +95,16 @@ class candidato private $activo; /** + * + * @Assert\NotNull(message= "Por favor introduzca su Direccion", groups={"Default"}) + * @Assert\NotBlank( message= "Por favor introduzca una Direccion correcta", groups={"Default"}) + * @Assert\Length( + * min = 2, + * max = 150, + * minMessage = "Tu Direccion debe tener como minimo {{ limit }} numeros", + * maxMessage = "Tu Direccion no debe exceder de {{ limit }} numeros" + * ) + * * @var string * * @ORM\Column(name="instruccion", type="string", length=255) @@ -57,6 +112,16 @@ class candidato private $instruccion; /** + * + * @Assert\NotNull(message= "Por favor introduzca su Direccion", groups={"Default"}) + * @Assert\NotBlank( message= "Por favor introduzca una Direccion correcta", groups={"Default"}) + * @Assert\Length( + * min = 2, + * max = 150, + * minMessage = "Tu Direccion debe tener como minimo {{ limit }} numeros", + * maxMessage = "Tu Direccion no debe exceder de {{ limit }} numeros" + * ) + * * @var string * * @ORM\Column(name="ocupacion", type="string", length=255) @@ -71,6 +136,16 @@ class candidato private $promedio; /** + * + * @Assert\NotNull(message= "Por favor introduzca su Direccion", groups={"Default"}) + * @Assert\NotBlank( message= "Por favor introduzca una Direccion correcta", groups={"Default"}) + * @Assert\Length( + * min = 2, + * max = 150, + * minMessage = "Tu Direccion debe tener como minimo {{ limit }} numeros", + * maxMessage = "Tu Direccion no debe exceder de {{ limit }} numeros" + * ) + * * @var string * * @ORM\Column(name="institucion", type="string", length=255) @@ -78,6 +153,16 @@ class candidato private $institucion; /** + * + * @Assert\NotNull(message= "Por favor introduzca su Nombre", groups={"Default"}) + * @Assert\NotBlank( message= "Por favor introduzca un Nombre valido", groups={"Default"}) + * @Assert\Length( + * min = 2, + * max = 45, + * minMessage = "Tu Nombre debe tener como minimo {{ limit }} letras", + * maxMessage = "Tu Nombre no debe exceder de {{ limit }} letras" + * ) + * * @var string * * @ORM\Column(name="pais", type="string", length=255) @@ -92,6 +177,16 @@ class candidato private $estado; /** + * + * @Assert\NotNull(message= "Por favor introduzca su Nombre", groups={"Default"}) + * @Assert\NotBlank( message= "Por favor introduzca un Nombre valido", groups={"Default"}) + * @Assert\Length( + * min = 2, + * max = 45, + * minMessage = "Tu Nombre debe tener como minimo {{ limit }} letras", + * maxMessage = "Tu Nombre no debe exceder de {{ limit }} letras" + * ) + * * @var string * * @ORM\Column(name="municipio", type="string", length=255) @@ -99,12 +194,43 @@ class candidato private $municipio; /** + * + * @Assert\NotNull(message= "Por favor introduzca su Nombre", groups={"Default"}) + * @Assert\NotBlank( message= "Por favor introduzca un Nombre valido", groups={"Default"}) + * @Assert\Length( + * min = 2, + * max = 45, + * minMessage = "Tu Nombre debe tener como minimo {{ limit }} letras", + * maxMessage = "Tu Nombre no debe exceder de {{ limit }} letras" + * ) + * * @var string * * @ORM\Column(name="direccion", type="string", length=255) */ private $direccion; + /** + * @var + * + * @ORM\ManyToOne(targetEntity="aldea", inversedBy="candidatos", cascade={"persist", "remove"}) + * @ORM\JoinColumn(name="aldea_id", referencedColumnName="id", nullable=true) + * + * + */ + private $aldea; + + /** + * @var + * + * @ORM\ManyToOne(targetEntity="estadoCivil", inversedBy="candidatos", cascade={"persist", "remove"}) + * @ORM\JoinColumn(name="estadoCivil_id", referencedColumnName="id", nullable=true) + * + * + */ + private $estadoCivil; + + /** * Get id @@ -403,5 +529,55 @@ class candidato { return $this->direccion; } + + /** + * Set Aldea + * + * @param \UBV\PracticaBundle\Entity\Aldea $aldea + * + * @return candidato + */ + public function setAldea(\UBV\PracticaBundle\Entity\Aldea $aldea) + { + $this->aldea = $aldea; + + return $this; + } + + /** + * Get Aldea + * + * @return \UBV\PracticaBundle\Entity\Aldea + */ + public function getAldea() + { + return $this->aldea; + } + + + + /** + * Set estadoCivil + * + * @param \UBV\PracticaBundle\Entity\estadoCivil $estadoCivil + * + * @return candidato + */ + public function setestadoCivil(\UBV\PracticaBundle\Entity\estadoCivil $estadoCivil=null) + { + $this->estadoCivil = $estadoCivil; + + return $this; + } + + /** + * Get estadoCivil + * + * @return \UBV\PracticaBundle\Entity\estadoCivil + */ + public function getestadoCivil() + { + return $this->estadoCivil; + } } diff --git a/src/UBV/PracticaBundle/Entity/estado.php b/src/UBV/PracticaBundle/Entity/estado.php index 163e70f..abff212 100644 --- a/src/UBV/PracticaBundle/Entity/estado.php +++ b/src/UBV/PracticaBundle/Entity/estado.php @@ -25,16 +25,24 @@ class estado * @var string * * @ORM\Column(name="descripcion", type="string", length=255) - */ + * + * + */ private $descripcion; + /** * @var int * * @ORM\Column(name="codigo", type="integer") + * + * + * */ private $codigo; + + /** * Get id @@ -93,6 +101,7 @@ class estado { return $this->codigo; } + public function __toString(){ return $this->getDescripcion(); diff --git a/src/UBV/PracticaBundle/Entity/municipio.php b/src/UBV/PracticaBundle/Entity/municipio.php index 189942b..39b4bd6 100644 --- a/src/UBV/PracticaBundle/Entity/municipio.php +++ b/src/UBV/PracticaBundle/Entity/municipio.php @@ -4,6 +4,8 @@ namespace UBV\PracticaBundle\Entity; use Doctrine\ORM\Mapping as ORM; +use Symfony\Component\Validator\Constraints as Assert; + /** * municipio * @@ -18,6 +20,9 @@ class municipio * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") + * + * + * */ private $id; @@ -25,6 +30,9 @@ class municipio * @var string * * @ORM\Column(name="descripcion", type="string", length=255) + * + * + * */ private $descripcion; @@ -32,6 +40,8 @@ class municipio * @var string * * @ORM\Column(name="codigo", type="string", length=255) + * + * */ private $codigo; @@ -42,6 +52,7 @@ class municipio * @ORM\JoinColumn(name="estado_id", referencedColumnName="id", nullable=false) * * + * */ private $estado; diff --git a/src/UBV/PracticaBundle/Form/candidatoType.php b/src/UBV/PracticaBundle/Form/candidatoType.php index 05e547c..81b5037 100644 --- a/src/UBV/PracticaBundle/Form/candidatoType.php +++ b/src/UBV/PracticaBundle/Form/candidatoType.php @@ -5,6 +5,8 @@ namespace UBV\PracticaBundle\Form; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; +use Symfony\Bridge\Doctrine\Form\Type\EntityType; +use Symfony\Component\Form\Extension\Core\Type\ChoiceType; class candidatoType extends AbstractType { @@ -14,18 +16,72 @@ class candidatoType extends AbstractType public function buildForm(FormBuilderInterface $builder, array $options) { $builder - ->add('nombre','text', array( 'label'=> 'Nombre', 'attr' => array('class' => 'form-control','placeholder'=>'Introduzca Nombre'), 'label_attr' => array('class' => 'control-label'),)) - ->add('apellido','text', array( 'label'=> 'Apellido', 'attr' => array('class' => 'form-control','placeholder'=>'Introduzca Apellido'), 'label_attr' => array('class' => 'control-label'),)) - ->add('cedula','integer', array( 'label'=> 'Cedula', 'attr' => array('class' => 'form-control','placeholder'=>'Ej.12345678'), 'label_attr' => array('class' => 'control-label'),)) + ->add('nombre','text', array( + 'label'=> 'Nombre', 'attr' => array( + 'class' => 'form-control','placeholder'=>'Introduzca Nombre'), 'label_attr' => array( + 'class' => 'control-label'),)) + ->add('apellido','text', array( + 'label'=> 'Apellido', 'attr' => array( + 'class' => 'form-control','placeholder'=>'Introduzca Apellido'), 'label_attr' => array( + 'class' => 'control-label'),)) + ->add('cedula','integer', array( + 'label'=> 'Cedula', 'attr' => array( + 'class' => 'form-control','placeholder'=>'Ej.12345678'), 'label_attr' => array( + 'class' => 'control-label'),)) ->add('activo') - ->add('instruccion','text', array( 'label'=> 'Instruccion Academica', 'attr' => array('class' => 'form-control','placeholder'=>'Nivel Academico'), 'label_attr' => array('class' => 'control-label'),)) - ->add('ocupacion','text', array( 'label'=> 'Ocupacion/Profesion', 'attr' => array('class' => 'form-control','placeholder'=>'Ej. Carpintero'), 'label_attr' => array('class' => 'control-label'),)) - ->add('promedio','number', array( 'label'=> 'Promedio', 'attr' => array('class' => 'form-control','step'=>'0.01','placeholder'=>'Introduzca Promedio'), 'label_attr' => array('class' => 'control-label'),)) - ->add('institucion','text', array( 'label'=> 'Institucion', 'attr' => array('class' => 'form-control','placeholder'=>'Institucion/Universidad/Empresa'), 'label_attr' => array('class' => 'control-label'),)) - ->add('pais','text', array( 'label'=> 'Pais', 'attr' => array('class' => 'form-control','placeholder'=>'Seleccione'), 'label_attr' => array('class' => 'control-label'),)) - ->add('estado','text', array( 'label'=> 'Estado', 'attr' => array('class' => 'form-control','placeholder'=>'Estado'), 'label_attr' => array('class' => 'control-label'),)) - ->add('municipio','text', array( 'label'=> 'Municipio', 'attr' => array('class' => 'form-control','placeholder'=>'Municipio'), 'label_attr' => array('class' => 'control-label'),)) - ->add('direccion','text', array( 'label'=> 'Direccion', 'attr' => array('class' => 'form-control','placeholder'=>'Direccion de Domicilio'), 'label_attr' => array('class' => 'control-label'),)); + ->add('instruccion','text', array( + 'label'=> 'Instruccion Academica', 'attr' => array( + 'class' => 'form-control','placeholder'=>'Nivel Academico'), 'label_attr' => array( + 'class' => 'control-label'),)) + ->add('ocupacion','text', array( + 'label'=> 'Ocupacion/Profesion', 'attr' => array( + 'class' => 'form-control','placeholder'=>'Ej. Carpintero'), 'label_attr' => array( + 'class' => 'control-label'),)) + ->add('promedio','number', array( + 'label'=> 'Promedio', 'attr' => array( + 'class' => 'form-control','step'=>'0.01','placeholder'=>'Introduzca Promedio'), 'label_attr' => array( + 'class' => 'control-label'),)) + ->add('institucion','text', array( + 'label'=> 'Institucion', 'attr' => array( + 'class' => 'form-control','placeholder'=>'Institucion/Universidad/Empresa'), 'label_attr' => array( + 'class' => 'control-label'),)) + ->add('pais','text', array( + 'label'=> 'Pais', 'attr' => array( + 'class' => 'form-control','placeholder'=>'Ej. Venezuela'), 'label_attr' => array( + 'class' => 'control-label'),)) + ->add('estado', 'choice', array( + 'choices' => array( + 'DC' => 'Distrito Capital', + 'M' => 'Miranda', + 'T' => 'Tachira', + 'A' => 'Aragua', + ), + 'required' => false, + 'empty_value' => 'Seleccione...', + 'empty_data' => null + )) + ->add('municipio','text', array( + 'label'=> 'Municipio', 'attr' => array( + 'class' => 'form-control','placeholder'=>'Municipio'), 'label_attr' => array( + 'class' => 'control-label'),)) + ->add('direccion','text', array( + 'label'=> 'Direccion', 'attr' => array( + 'class' => 'form-control','placeholder'=>'Direccion de Domicilio'), 'label_attr' => array( + 'class' => 'control-label'),)) + ->add('aldea','text', array( + 'label'=> 'Aldea', 'attr' => array( + 'class' => 'form-control','placeholder'=>'Direccion de Aldea'), 'label_attr' => array( + 'class' => 'control-label'),)) + ->add('estadoCivil', EntityType::class, array( + 'disabled'=>false, + 'class' => 'UBVPracticaBundle:EstadoCivil', + 'label' =>"Estado Civil", + 'empty_data' => "0", + 'placeholder'=>"Seleccione...", + 'attr' => array('class' => 'form-control form-control-choice','placeholder'=>''), + 'label_attr' => array('class' => 'control-label'), + )); + }/** * {@inheritdoc} */ diff --git a/src/UBV/PracticaBundle/Form/estadoType.php b/src/UBV/PracticaBundle/Form/estadoType.php index 6d394c6..0b61d22 100644 --- a/src/UBV/PracticaBundle/Form/estadoType.php +++ b/src/UBV/PracticaBundle/Form/estadoType.php @@ -5,6 +5,8 @@ namespace UBV\PracticaBundle\Form; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; +use UBV\PracticaBundle\Entity\Estado; +use UBV\PracticaBundle\Entity\Municipio; class estadoType extends AbstractType { @@ -13,7 +15,11 @@ class estadoType extends AbstractType */ public function buildForm(FormBuilderInterface $builder, array $options) { - $builder->add('descripcion')->add('codigo'); + $builder + ->add('descripcion') + ->add('codigo',new municipioType()) + ->getForm(); + }/** * {@inheritdoc} */ diff --git a/src/UBV/PracticaBundle/Form/municipioType.php b/src/UBV/PracticaBundle/Form/municipioType.php index 2a7200e..ca234e3 100644 --- a/src/UBV/PracticaBundle/Form/municipioType.php +++ b/src/UBV/PracticaBundle/Form/municipioType.php @@ -13,7 +13,10 @@ class municipioType extends AbstractType */ public function buildForm(FormBuilderInterface $builder, array $options) { - $builder->add('descripcion')->add('codigo')->add('estado'); + $builder + ->add('descripcion') + ->add('codigo') + ->add('estado'); }/** * {@inheritdoc} */ -- 2.0.0
Id