213 lines
7.7 KiB
PHP
213 lines
7.7 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\SubmitType;
|
|
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
|
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
|
use Gregwar\CaptchaBundle\Type\CaptchaType;
|
|
use Tetranz\Select2EntityBundle\Form\Type\Select2EntityType;
|
|
|
|
use Doctrine\ORM\EntityRepository;
|
|
use Doctrine\ORM\Query\Expr\Join;
|
|
|
|
|
|
class RegistrationType extends AbstractType
|
|
{
|
|
public function buildForm(FormBuilderInterface $builder, array $options)
|
|
{
|
|
$builder->add('submit',
|
|
SubmitType::class,[
|
|
"label" => ($options["mode"]=="submit"?"Confirmer":"Enregistrer et envoyer le mail de confirmation"),
|
|
"attr" => ["class" => "btn btn-success"],
|
|
]
|
|
);
|
|
|
|
if($options["mode"]=="update") {
|
|
$builder->add('save',
|
|
SubmitType::class, array(
|
|
"label" => "Enregistrer sans envoyer le mail de confirmation",
|
|
"attr" => array("class" => "btn btn-success")
|
|
)
|
|
);
|
|
|
|
$builder->add('note',
|
|
TextareaType::class, array(
|
|
"label" => "Notes Administrateur",
|
|
"required" => false,
|
|
"disabled" => ($options["mode"]=="delete"?true:false),
|
|
"attr" => array("class" => "form-control", "style" => "margin-bottom:15px; height: 130px")
|
|
)
|
|
);
|
|
}
|
|
|
|
$builder->add('username',
|
|
TextType::class,[
|
|
"label" =>"Login",
|
|
"disabled" => ($options["mode"]!="submit"),
|
|
"attr" => ["autocomplete" => "new-password"]
|
|
]
|
|
);
|
|
|
|
$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"]." ==",
|
|
]
|
|
);
|
|
|
|
# Password
|
|
if($options["mode"]=="submit") {
|
|
$builder->add('password',
|
|
RepeatedType::class, array(
|
|
"type" => PasswordType::class,
|
|
"required" => ($options["mode"]=="submit"?true:false),
|
|
"first_options" => array("label" => "Mot de Passe","attr" => array("class" => "form-control", "style" => "margin-bottom:15px", "autocomplete" => "new-password")),
|
|
"second_options" => array('label' => 'Confirmer Mot de Passe',"attr" => array("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,array(
|
|
"width" => 200,
|
|
"height" => 50,
|
|
"length" => 6,
|
|
)
|
|
);
|
|
}
|
|
|
|
|
|
$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('motivation',
|
|
TextareaType::class, [
|
|
"label" => "Motivation",
|
|
"required" => false,
|
|
"attr" => ["style" => "height: 90px"],
|
|
]
|
|
);
|
|
}
|
|
|
|
public function configureOptions(OptionsResolver $resolver)
|
|
{
|
|
$resolver->setDefaults(array(
|
|
'data_class' => 'App\Entity\Registration',
|
|
'mode' => "string",
|
|
'access' => "string",
|
|
'userid' => "string",
|
|
'appMasteridentity' => "string",
|
|
'appNiveau01label' => "string",
|
|
'appNiveau02label' => "string",
|
|
));
|
|
}
|
|
}
|