<?php
namespace App\Form;
use App\Entity\Employee;
use App\Enum\Employee\Gender;
use App\Enum\Employee\RelationShipStatus;
use App\Form\DataTransformer\FrenchDateToDateTimeTransformer;
use App\Repository\EmployeeRepository;
use Symfony\Component\Form\Extension\Core\Type\EnumType;
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
use Symfony\Component\Form\Extension\Core\Type\TelType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class EmployeeType extends Form
{
/** @var EmployeeRepository */
protected $employeeRepository;
/** @var FrenchDateToDateTimeTransformer */
protected $transformer;
/**
* UserType constructor.
* @param EmployeeRepository $employeeRepository
*/
public function __construct(
EmployeeRepository $employeeRepository,
FrenchDateToDateTimeTransformer $transformer
)
{
$this->employeeRepository = $employeeRepository;
$this->transformer = $transformer;
}
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add(
'gender',
EnumType::class,
[
'class' => Gender::class,
'choice_label' => function (Gender $gender) {
return $gender->title();
},
'label' => 'Civilité',
'disabled' => $options['disabled'],
'attr' => array_merge(
$this->selectAttr,
[
]
),
]
)
->add(
'firstName',
TextType::class,
[
'label' => 'Prénom',
'required' => true,
'attr' => array_merge(
$this->inputAttr,
[
'placeholder' => 'Prénom',
// 'attr' => [
// 'readonly' => true
// ]
]
),
'disabled' => $options['disabled']
]
)
->add(
'lastName',
TextType::class,
[
'label' => 'Nom',
'required' => true,
'attr' => array_merge(
$this->inputAttr,
[
'placeholder' => 'Nom',
]
),
'disabled' => $options['disabled']
],
)
->add(
'phoneNumber',
TelType::class,
[
'label' => 'Téléphone',
'required' => true,
'attr' => array_merge(
$this->inputAttr,
[
'placeholder' => 'Téléphone',
]
),
'disabled' => $options['disabled']
]
)
->add(
'cin',
TextType::class,
[
'label' => 'N° CIN',
'required' => false,
'attr' => array_merge(
$this->inputAttr,
[
'placeholder' => 'N° CIN',
]
),
'disabled' => $options['disabled']
]
)
->add(
'dateOfBirth',
TextType::class,
[
'label' => 'Date de naissance',
'required' => false,
'attr' => array_merge(
$this->dateAttr,
[
'placeholder' => 'Date de naissance',
]
),
'disabled' => $options['disabled']
]
)
->add(
'relationshipStatus',
EnumType::class,
[
'class' => RelationShipStatus::class,
'choice_label' => function (RelationShipStatus $gender) {
return $gender->title();
},
'label' => 'Situation amoureuse',
'disabled' => $options['disabled'],
'attr' => array_merge(
$this->selectAttr,
[
]
),
]
)
->add(
'numberOfChildrens',
IntegerType::class,
[
'label' => 'Nombre d\'enfant',
'required' => true,
'attr' => array_merge(
$this->selectAttr,
[
'placeholder' => 'Nombre d\'enfant',
]
),
'disabled' => $options['disabled']
]
)
// ->add(
// 'address',
// TextType::class,
// [
// 'label' => 'Adresse',
// 'required' => false,
// 'attr' => array_merge(
// $this->inputAttr,
// [
// 'placeholder' => 'Adresse',
// ]
// ),
// ]
// )
->add(
'dateOld',
TextType::class,
[
'label' => 'Date d\'ancienneté',
'required' => false,
'attr' => array_merge(
$this->dateAttr,
[
'placeholder' => 'Date d\'ancienneté',
]
),
'disabled' => $options['disabled']
]
)
->add(
'registrationNumber',
IntegerType::class,
[
'label' => 'Matricule',
'required' => false,
'attr' => array_merge(
$this->inputAttr,
[
'placeholder' => 'Matricule',
// 'attr' => [
// 'readonly' => true
// ]
]
),
'disabled' => $options['disabled']
]
)
->add(
'cnss',
TextType::class,
[
'label' => 'N° CNSS',
'required' => false,
'attr' => array_merge(
$this->inputAttr,
[
'placeholder' => 'N° CNSS',
]
),
'disabled' => $options['disabled']
]
)
->add(
'dateCnss',
TextType::class,
[
'label' => 'Date de déclaration CNSS',
'required' => false,
'attr' => array_merge(
$this->dateAttr,
[
'placeholder' => 'Date de déclaration CNSS',
]
),
'disabled' => $options['disabled']
]
);
$builder->get('dateOfBirth')->addModelTransformer($this->transformer);
$builder->get('dateOld')->addModelTransformer($this->transformer);
$builder->get('dateCnss')->addModelTransformer($this->transformer);
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(
[
'data_class' => Employee::class,
'disabled' => false
]
);
}
}