233 lines
8.2 KiB
PHP
233 lines
8.2 KiB
PHP
|
<?php
|
||
|
namespace App\Form;
|
||
|
|
||
|
use Symfony\Component\Form\AbstractType;
|
||
|
use Symfony\Component\Form\FormBuilderInterface;
|
||
|
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||
|
|
||
|
use Symfony\Component\Form\Extension\Core\Type\EmailType;
|
||
|
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||
|
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
|
||
|
use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
|
||
|
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
|
||
|
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
|
||
|
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||
|
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||
|
use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
|
||
|
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
|
||
|
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||
|
use Tetranz\Select2EntityBundle\Form\Type\Select2EntityType;
|
||
|
|
||
|
use Doctrine\ORM\EntityRepository;
|
||
|
use Doctrine\ORM\Query\Expr\Join;
|
||
|
|
||
|
|
||
|
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" => ($options["mode"]!="submit"),
|
||
|
"attr" => ["autocomplete" => "new-password"]
|
||
|
]
|
||
|
);
|
||
|
|
||
|
if($options["appMasteridentity"]=="SQL"||$options["mode"]=="submit") {
|
||
|
$builder->add('password',
|
||
|
RepeatedType::class, [
|
||
|
"type" => PasswordType::class,
|
||
|
"required" => ($options["mode"]=="submit"),
|
||
|
"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" => ($options["appMasteridentity"]!="SQL"&&$options["mode"]!="submit"),
|
||
|
]
|
||
|
);
|
||
|
|
||
|
$builder->add('firstname',
|
||
|
TextType::class, [
|
||
|
"label" =>"Prénom",
|
||
|
"disabled" => ($options["appMasteridentity"]!="SQL"&&$options["mode"]!="submit"),
|
||
|
]
|
||
|
);
|
||
|
|
||
|
$builder->add('email',
|
||
|
EmailType::class, array(
|
||
|
"label" =>"Mail",
|
||
|
"disabled" => ($options["appMasteridentity"]!="SQL")&&$options["mode"]!="submit",
|
||
|
)
|
||
|
);
|
||
|
|
||
|
$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" => ($options["appMasteridentity"]!="SQL"&&$options["mode"]!="submit"),
|
||
|
"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;
|
||
|
}
|
||
|
},
|
||
|
]
|
||
|
);
|
||
|
|
||
|
$builder->add('niveau02',
|
||
|
Select2EntityType::class, [
|
||
|
"label" => $options["appNiveau02label"],
|
||
|
"required" => false,
|
||
|
"remote_route" => "app_niveau02_selectlist",
|
||
|
"class" => "App\Entity\Niveau02",
|
||
|
//"req_params" => ["niveau01" => "parent.children[niveau01]"],
|
||
|
"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"]." ==",
|
||
|
]
|
||
|
);
|
||
|
|
||
|
$choices=array("oui" => "1","non" => "0");
|
||
|
$builder->add("isvisible",
|
||
|
ChoiceType::class,array(
|
||
|
"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, array("mapped" => false));
|
||
|
$builder->add('linkmodos',HiddenType::class, array("mapped" => false));
|
||
|
|
||
|
if($options["access"]=="admin" || $options["access"]=="modo") {
|
||
|
$choices=array("ROLE_ADMIN" => "ROLE_ADMIN","ROLE_MODO" => "ROLE_MODO","ROLE_MASTER" => "ROLE_MASTER","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(array(
|
||
|
'data_class' => 'App\Entity\User',
|
||
|
'mode' => "string",
|
||
|
'access' => "string",
|
||
|
'userid' => "string",
|
||
|
'appMasteridentity' => "string",
|
||
|
'appNiveau01label' => "string",
|
||
|
'appNiveau02label' => "string",
|
||
|
));
|
||
|
}
|
||
|
}
|
||
|
|