291 lines
11 KiB
PHP
291 lines
11 KiB
PHP
<?php
|
|
|
|
namespace App\Form;
|
|
|
|
use Doctrine\ORM\EntityRepository;
|
|
use Doctrine\ORM\Query\Expr\Join;
|
|
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\DateTimeType;
|
|
use Symfony\Component\Form\Extension\Core\Type\EmailType;
|
|
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
|
|
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
|
|
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 UserType extends AbstractType
|
|
{
|
|
public function buildForm(FormBuilderInterface $builder, array $options)
|
|
{
|
|
$builder->add('submit',
|
|
SubmitType::class, [
|
|
'label' => 'Valider',
|
|
'attr' => ['class' => 'btn btn-success'],
|
|
]
|
|
);
|
|
|
|
$builder->add('username',
|
|
TextType::class, [
|
|
'label' => 'Login',
|
|
'disabled' => ('submit' != $options['mode']),
|
|
'attr' => ['autocomplete' => 'new-password'],
|
|
]
|
|
);
|
|
|
|
if ('all' != $options['access']) {
|
|
$choices = ['oui' => '1', 'non' => '0'];
|
|
$builder->add('isactive',
|
|
ChoiceType::class, [
|
|
'label' => 'Actif',
|
|
'choices' => $choices,
|
|
]
|
|
);
|
|
}
|
|
|
|
if ('SQL' == $options['appMasteridentity'] || 'submit' == $options['mode']) {
|
|
$builder->add('password',
|
|
RepeatedType::class, [
|
|
'type' => PasswordType::class,
|
|
'required' => ('submit' == $options['mode']),
|
|
'options' => ['always_empty' => true],
|
|
'first_options' => ['label' => 'Mot de Passe', 'attr' => ['autocomplete' => 'new-password']],
|
|
'second_options' => ['label' => 'Confirmer Mot de Passe'],
|
|
'invalid_message' => 'Mot de passe non valide',
|
|
]
|
|
);
|
|
$builder->add('passwordplain', PasswordType::class, ['mapped' => false, 'required' => false]);
|
|
}
|
|
|
|
$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']) || ('admin' != $access && 'modo' != $access && $options['appNiveauupdatable'] > 1)),
|
|
'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,
|
|
'disabled' => ('admin' != $access && 'modo' != $access && $options['appNiveauupdatable'] > 2),
|
|
'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,
|
|
'disabled' => ('admin' != $access && 'modo' != $access && $options['appNiveauupdatable'] > 3),
|
|
'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,
|
|
'disabled' => ('admin' != $access && 'modo' != $access && $options['appNiveauupdatable'] > 4),
|
|
'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'].' ==',
|
|
]
|
|
);
|
|
}
|
|
|
|
$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('visitedate',
|
|
DateTimeType::class, [
|
|
'label' => 'Date de dernière visite',
|
|
'disabled' => true,
|
|
'required' => false,
|
|
'widget' => 'single_text',
|
|
]
|
|
);
|
|
|
|
$builder->add('visitecpt',
|
|
IntegerType::class, [
|
|
'label' => 'Nombre de visites',
|
|
'disabled' => true,
|
|
'required' => false,
|
|
]
|
|
);
|
|
|
|
$builder->add('motivation',
|
|
TextareaType::class, [
|
|
'label' => 'Motivation',
|
|
'required' => false,
|
|
'attr' => ['style' => 'height: 90px'],
|
|
]
|
|
);
|
|
|
|
$builder->add('avatar', HiddenType::class);
|
|
$builder->add('linkgroups', HiddenType::class, ['mapped' => false]);
|
|
$builder->add('linkmodos', HiddenType::class, ['mapped' => false]);
|
|
|
|
if ('admin' == $options['access'] || 'modo' == $options['access']) {
|
|
$choices = ['ROLE_ADMIN' => 'ROLE_ADMIN', 'ROLE_MODO' => 'ROLE_MODO', 'ROLE_MASTER' => 'ROLE_MASTER', 'ROLE_MANAGER' => 'ROLE_MANAGER', 'ROLE_USER' => 'ROLE_USER'];
|
|
$builder->add('roles',
|
|
ChoiceType::class, [
|
|
'label' => 'Rôle',
|
|
'required' => true,
|
|
'multiple' => true,
|
|
'expanded' => true,
|
|
'choices' => $choices,
|
|
]
|
|
);
|
|
|
|
$builder->add('note',
|
|
TextareaType::class, [
|
|
'label' => 'Notes Administrateur',
|
|
'required' => false,
|
|
'attr' => ['style' => 'height: 130px'],
|
|
]
|
|
);
|
|
}
|
|
}
|
|
|
|
public function configureOptions(OptionsResolver $resolver)
|
|
{
|
|
$resolver->setDefaults([
|
|
'data_class' => 'App\Entity\User',
|
|
'mode' => 'string',
|
|
'access' => 'string',
|
|
'userid' => 'string',
|
|
'appMasteridentity' => 'string',
|
|
'appNiveau01label' => 'string',
|
|
'appNiveau02use' => 'string',
|
|
'appNiveau02label' => 'string',
|
|
'appNiveau03use' => 'string',
|
|
'appNiveau03label' => 'string',
|
|
'appNiveau04use' => 'string',
|
|
'appNiveau04label' => 'string',
|
|
'appNiveauupdatable' => 'string',
|
|
]);
|
|
}
|
|
}
|