<?php
namespace App\Form;
use App\Entity\Role;
use App\Entity\Unidad;
use App\Entity\Usuario;
use Doctrine\ORM\EntityRepository;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints\IsTrue;
use Symfony\Component\Validator\Constraints\Length;
use Symfony\Component\Validator\Constraints\NotBlank;
use function Symfony\Component\DependencyInjection\Loader\Configurator\param;
class SolicitudAccesoType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('nombre', null, [
'label' => '* Nombre(s)',
'attr' => ['class' => 'form-control'],
'constraints' => [
new NotBlank([
'message' => 'El campo no debe estar vacío',
])
],
'required' => true
])
->add('papellido', null, [
'label' => '* Primer apellido',
'attr' => ['class' => 'form-control'],
'constraints' => [
new NotBlank([
'message' => 'El campo no debe estar vacío',
])
],
'required' => true
])
->add('sapellido', null, [
'label' => 'Segundo apellido',
'attr' => ['class' => 'form-control']
])
->add('correo', RepeatedType::class, [
'type' => TextType::class,
'first_options' => [
'label' => '* Correo',
'attr' => ['class' => 'form-control'],
'constraints' => [
new NotBlank([
'message' => 'Ingrese su correo por favor',
])
],
],
'second_options' => [
'label' => '* Repetir correo',
'attr' => ['class' => 'form-control', 'autocomplete' => 'off']
],
'invalid_message' => 'Los correos deben coincidir.',
// Instead of being set onto the object directly,
// this is read and encoded in the controller
'mapped' => true,
])
->add('contrasena', null, [
'label' => "Contraseña",
'attr' => ['class' => 'form-control'],
'constraints' => [
new NotBlank([
'message' => 'Este campo no debe estar vacío',
]),
],
'required' => true
])
->add('unidad', EntityType::class, [
'label' => '* Unidad administrativa',
'class' => Unidad::class,
'required' => true,
'attr' => [
'class' => 'form-control'
],
'query_builder' => function (EntityRepository $er) {
return $er->createQueryBuilder('u')
->orderBy('u.nombre', 'ASC');
}
])
/*->add('rol', null, [
'class' => Role::class,
'label' => '* Rol',
'required' => true,
'placeholder' => 'Seleccione el rol',
'attr' => ['class' => 'form-control'],
'query_builder' => function (EntityRepository $er) use ($options){
$query = $er->createQueryBuilder('r');
if($options['data_info'] == 2 || $options['data_info'] == 3){
$query->where('r.idRol != :rol_a');
$query->andWhere('r.idRol != :rol_b');
$query->setParameter('rol_a', 1);
$query->setParameter('rol_b', 2);
}
$query->orderBy('r.idRol', 'ASC');
return $query;
}
])*/
->add('rol', null, [
'class' => Role::class,
'label' => '* Rol',
'required' => true,
'placeholder' => 'Seleccione el rol',
'attr' => ['class' => 'form-control'],
'query_builder' => function (EntityRepository $er) use ($options){
$query = $er->createQueryBuilder('r');
$rolesToShow = [3, 4]; // IDs de los roles a mostrar
$query->where('r.idRol IN (:roles)');
$query->setParameter('roles', $rolesToShow);
$query->orderBy('r.idRol', 'ASC');
return $query;
}
])
->add('estatus', ChoiceType::class, [
'choices' => [
'Pendiente' => 'Pendiente',
'Rechazado' => 'Rechazado',
'Aceptado' => 'Aceptado',
'Activo' => 'Activo',
'Suspendido' => 'Suspendido'
],
'attr' => ['class' => 'form-control']
])
;
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => Usuario::class,
'data_info' => array()
]);
}
//Para subir formulario
}