258 lines
9.5 KiB
PHP
Executable File
258 lines
9.5 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Form;
|
|
|
|
use Doctrine\ORM\EntityRepository;
|
|
use Doctrine\ORM\Query\Expr\Join;
|
|
use Gregwar\CaptchaBundle\Type\CaptchaType;
|
|
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
|
use Symfony\Component\Form\AbstractType;
|
|
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
|
use Symfony\Component\Form\Extension\Core\Type\EmailType;
|
|
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
|
|
use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
|
|
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
|
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
|
|
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
|
use Symfony\Component\Form\FormBuilderInterface;
|
|
use Symfony\Component\OptionsResolver\OptionsResolver;
|
|
use Tetranz\Select2EntityBundle\Form\Type\Select2EntityType;
|
|
|
|
class RegistrationType extends AbstractType
|
|
{
|
|
public function buildForm(FormBuilderInterface $builder, array $options)
|
|
{
|
|
$builder->add('submit',
|
|
SubmitType::class, [
|
|
'label' => ('submit' == $options['mode'] ? 'Confirmer' : 'Enregistrer et envoyer le mail de confirmation'),
|
|
'attr' => ['class' => 'btn btn-success'],
|
|
]
|
|
);
|
|
|
|
if ('update' == $options['mode']) {
|
|
$builder->add('save',
|
|
SubmitType::class, [
|
|
'label' => 'Enregistrer sans envoyer le mail de confirmation',
|
|
'attr' => ['class' => 'btn btn-success'],
|
|
]
|
|
);
|
|
|
|
$builder->add('note',
|
|
TextareaType::class, [
|
|
'label' => 'Notes Administrateur',
|
|
'required' => false,
|
|
'disabled' => ('delete' == $options['mode'] ? true : false),
|
|
'attr' => ['class' => 'form-control', 'style' => 'margin-bottom:15px; height: 130px'],
|
|
]
|
|
);
|
|
}
|
|
|
|
$builder->add('username',
|
|
TextType::class, [
|
|
'label' => 'Login',
|
|
'disabled' => ('submit' != $options['mode']),
|
|
'attr' => ['autocomplete' => 'new-password'],
|
|
]
|
|
);
|
|
|
|
$builder->add('lastname',
|
|
TextType::class, [
|
|
'label' => 'Nom',
|
|
'disabled' => ('SQL' != $options['appMasteridentity'] && 'submit' != $options['mode']),
|
|
]
|
|
);
|
|
|
|
$builder->add('firstname',
|
|
TextType::class, [
|
|
'label' => 'Prénom',
|
|
'disabled' => ('SQL' != $options['appMasteridentity'] && 'submit' != $options['mode']),
|
|
]
|
|
);
|
|
|
|
$builder->add('email',
|
|
EmailType::class, [
|
|
'label' => 'Mail',
|
|
'disabled' => ('SQL' != $options['appMasteridentity']) && 'submit' != $options['mode'],
|
|
]
|
|
);
|
|
|
|
$access = $options['access'];
|
|
$userid = $options['userid'];
|
|
$builder->add('niveau01',
|
|
EntityType::class, [
|
|
'class' => "App\Entity\Niveau01",
|
|
'label' => $options['appNiveau01label'],
|
|
'placeholder' => '== Choisir '.$options['appNiveau01label'].' ==',
|
|
'choice_label' => 'label',
|
|
'disabled' => ('SQL' != $options['appMasteridentity'] && 'submit' != $options['mode']),
|
|
'query_builder' => function (EntityRepository $er) use ($access, $userid) {
|
|
switch ($access) {
|
|
case 'admin':
|
|
return $er->createQueryBuilder('niveau01')->orderBy('niveau01.label', 'ASC');
|
|
break;
|
|
|
|
case 'modo':
|
|
$result = $er->createQueryBuilder('table')->innerJoin('App:UserModo', 'usermodo', Join::WITH, 'table.id = usermodo.niveau01')->orderBy('table.label', 'ASC');
|
|
$result->andWhere('usermodo.user = :user');
|
|
$result->setParameter('user', $userid);
|
|
|
|
return $result;
|
|
break;
|
|
|
|
default:
|
|
return $er->createQueryBuilder('niveau01')->orderBy('niveau01.label', 'ASC');
|
|
break;
|
|
}
|
|
},
|
|
]
|
|
);
|
|
if ($options['appNiveau02use']) {
|
|
$builder->add('niveau02',
|
|
Select2EntityType::class, [
|
|
'label' => $options['appNiveau02label'],
|
|
'required' => false,
|
|
'remote_route' => 'app_niveau02_selectlist',
|
|
'class' => "App\Entity\Niveau02",
|
|
'primary_key' => 'id',
|
|
'text_property' => 'label',
|
|
'minimum_input_length' => 0,
|
|
'page_limit' => 10,
|
|
'allow_clear' => true,
|
|
'delay' => 250,
|
|
'cache' => false,
|
|
'cache_timeout' => 60000,
|
|
'language' => 'fr',
|
|
'placeholder' => '== Choisir '.$options['appNiveau02label'].' ==',
|
|
]
|
|
);
|
|
}
|
|
|
|
if ($options['appNiveau03use']) {
|
|
$builder->add('niveau03',
|
|
Select2EntityType::class, [
|
|
'label' => $options['appNiveau03label'],
|
|
'required' => false,
|
|
'remote_route' => 'app_niveau03_selectlist',
|
|
'class' => "App\Entity\Niveau03",
|
|
'primary_key' => 'id',
|
|
'text_property' => 'label',
|
|
'minimum_input_length' => 0,
|
|
'page_limit' => 10,
|
|
'allow_clear' => true,
|
|
'delay' => 250,
|
|
'cache' => false,
|
|
'cache_timeout' => 60000,
|
|
'language' => 'fr',
|
|
'placeholder' => '== Choisir '.$options['appNiveau03label'].' ==',
|
|
]
|
|
);
|
|
}
|
|
|
|
if ($options['appNiveau04use']) {
|
|
$builder->add('niveau04',
|
|
Select2EntityType::class, [
|
|
'label' => $options['appNiveau04label'],
|
|
'required' => false,
|
|
'remote_route' => 'app_niveau04_selectlist',
|
|
'class' => "App\Entity\Niveau04",
|
|
'primary_key' => 'id',
|
|
'text_property' => 'label',
|
|
'minimum_input_length' => 0,
|
|
'page_limit' => 10,
|
|
'allow_clear' => true,
|
|
'delay' => 250,
|
|
'cache' => false,
|
|
'cache_timeout' => 60000,
|
|
'language' => 'fr',
|
|
'placeholder' => '== Choisir '.$options['appNiveau04label'].' ==',
|
|
]
|
|
);
|
|
}
|
|
|
|
// Password
|
|
if ('submit' == $options['mode']) {
|
|
$builder->add('password',
|
|
RepeatedType::class, [
|
|
'type' => PasswordType::class,
|
|
'required' => ('submit' == $options['mode'] ? true : false),
|
|
'first_options' => ['label' => 'Mot de Passe', 'attr' => ['class' => 'form-control', 'style' => 'margin-bottom:15px', 'autocomplete' => 'new-password']],
|
|
'second_options' => ['label' => 'Confirmer Mot de Passe', 'attr' => ['class' => 'form-control', 'style' => 'margin-bottom:15px']],
|
|
'invalid_message' => 'Mot de passe non valide',
|
|
]
|
|
);
|
|
$builder->add('passwordplain', PasswordType::class, ['mapped' => false, 'required' => false]);
|
|
|
|
$builder->add('captcha',
|
|
CaptchaType::class, [
|
|
'width' => 200,
|
|
'height' => 50,
|
|
'length' => 6,
|
|
]
|
|
);
|
|
}
|
|
|
|
$choices = ['oui' => '1', 'non' => '0'];
|
|
$builder->add('isvisible',
|
|
ChoiceType::class, [
|
|
'label' => 'Visible',
|
|
'choices' => $choices,
|
|
]
|
|
);
|
|
|
|
$builder->add('postaladress',
|
|
TextareaType::class, [
|
|
'label' => 'Adresse',
|
|
'required' => false,
|
|
'attr' => ['style' => 'height:90px'],
|
|
]
|
|
);
|
|
|
|
$builder->add('telephonenumber',
|
|
TextType::class, [
|
|
'label' => 'Téléphone',
|
|
'required' => false,
|
|
]
|
|
);
|
|
|
|
$builder->add('job',
|
|
TextType::class, [
|
|
'label' => 'Métier',
|
|
'required' => false,
|
|
]
|
|
);
|
|
|
|
$builder->add('position',
|
|
TextType::class, [
|
|
'label' => 'Fonction',
|
|
'required' => false,
|
|
]
|
|
);
|
|
|
|
$builder->add('motivation',
|
|
TextareaType::class, [
|
|
'label' => 'Motivation',
|
|
'required' => false,
|
|
'attr' => ['style' => 'height: 90px'],
|
|
]
|
|
);
|
|
}
|
|
|
|
public function configureOptions(OptionsResolver $resolver)
|
|
{
|
|
$resolver->setDefaults([
|
|
'data_class' => 'App\Entity\Registration',
|
|
'mode' => 'string',
|
|
'access' => 'string',
|
|
'userid' => 'string',
|
|
'appMasteridentity' => 'string',
|
|
'appNiveau01label' => 'string',
|
|
'appNiveau02use' => 'string',
|
|
'appNiveau02label' => 'string',
|
|
'appNiveau03use' => 'string',
|
|
'appNiveau03label' => 'string',
|
|
'appNiveau04use' => 'string',
|
|
'appNiveau04label' => 'string',
|
|
]);
|
|
}
|
|
}
|