328 lines
14 KiB
PHP
328 lines
14 KiB
PHP
<?php
|
|
namespace Cadoles\CoreBundle\Form;
|
|
|
|
use Symfony\Component\Form\AbstractType;
|
|
use Symfony\Component\Form\FormBuilderInterface;
|
|
use Symfony\Component\OptionsResolver\OptionsResolver;
|
|
use Symfony\Component\HttpFoundation\Session\Session;
|
|
|
|
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\ButtonType;
|
|
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
|
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
|
use Symfony\Component\Form\Extension\Core\Type\DateType;
|
|
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)
|
|
{
|
|
$session = new Session();
|
|
|
|
$builder->add('submit',
|
|
SubmitType::class, array(
|
|
"label" => ($options["mode"]=="delete"?"Confirmer la Suppression":"Valider"),
|
|
"attr" => ($options["mode"]=="delete"?array("class" => "btn btn-danger"):array("class" => "btn btn-success"))
|
|
)
|
|
);
|
|
|
|
# Obligatoire
|
|
$builder->add('username',
|
|
TextType::class, array(
|
|
"label" =>"Login",
|
|
"disabled" => ($options["mode"]=="submit"?false:true),
|
|
"attr" => array("class" => "form-control", "style" => "margin-bottom:15px")
|
|
)
|
|
);
|
|
|
|
$builder->add('firstname',
|
|
TextType::class, array(
|
|
"label" =>"Prénom",
|
|
"disabled" => ($options["mode"]=="delete"||$options["masteridentity"]!="SQL"?true:false),
|
|
"attr" => array("class" => "form-control", "style" => "margin-bottom:15px")
|
|
)
|
|
);
|
|
|
|
$builder->add('lastname',
|
|
TextType::class, array(
|
|
"label" =>"Nom",
|
|
"disabled" => ($options["mode"]=="delete"||$options["masteridentity"]!="SQL"?true:false),
|
|
"attr" => array("class" => "form-control", "style" => "margin-bottom:15px")
|
|
)
|
|
);
|
|
|
|
$builder->add('email',
|
|
EmailType::class, array(
|
|
"label" =>"Mail",
|
|
"disabled" => ($options["mode"]=="delete"||$options["mode"]=="send"||$options["masteridentity"]!="SQL"?true:false),
|
|
"attr" => array("class" => "form-control", "style" => "margin-bottom:15px")
|
|
)
|
|
);
|
|
|
|
if($options["access"]=="config") {
|
|
$choices=array("Utilisateur" => "ROLE_USER","Modérateur" => "ROLE_MODO","Administrateur" => "ROLE_ADMIN");
|
|
$onfocus=($options["perm"]?"":"this.defaultIndex=this.selectedIndex;");
|
|
$onchange=($options["perm"]?"":"this.selectedIndex=this.defaultIndex;");
|
|
$readonly=($options["perm"]?"":" background-color: #eee;");
|
|
$builder->add("role",
|
|
ChoiceType::class,array(
|
|
"label" =>"Rôle",
|
|
"attr" => array("class" => "form-control", "style" => "margin-bottom:15px;$readonly","onfocus" => $onfocus, "onchange" => $onchange),
|
|
"required" => true,
|
|
"choices" => $choices));
|
|
}
|
|
|
|
$choices=array("oui" => "1","non" => "0");
|
|
$builder->add("visible",
|
|
ChoiceType::class,array(
|
|
"label" =>"Visible",
|
|
'disabled' => ($options["mode"]=="delete"?true:false),
|
|
"attr" => array("class" => "form-control", "style" => "margin-bottom:15px"),
|
|
"choices" => $choices
|
|
)
|
|
);
|
|
|
|
$perm=$options["perm"];
|
|
$userid=$options["userid"];
|
|
$access=$options["access"];
|
|
$builder->add('niveau01',
|
|
EntityType::class,
|
|
array("class" => "CadolesCoreBundle:Niveau01",
|
|
"label" => $session->get('labelniveau01'),
|
|
"choice_label" => "label",
|
|
"query_builder"=> function (EntityRepository $er) use($access,$perm,$userid) {
|
|
if($access=="config") {
|
|
if($perm)
|
|
return $er->createQueryBuilder('niveau01');
|
|
else {
|
|
$result=$er->createQueryBuilder("table")->innerJoin("CadolesCoreBundle:UserModo", "usermodo", Join::WITH, "table.id = usermodo.niveau01");
|
|
$result->andWhere("usermodo.user = :userid");
|
|
$result->setParameter('userid', $userid);
|
|
return $result;
|
|
}
|
|
}
|
|
else {
|
|
return $er->createQueryBuilder('niveau01');
|
|
}
|
|
},
|
|
"disabled" => ($options["mode"]=="delete"||$options["masteridentity"]!="SQL"?true:false),
|
|
"attr" => array("class" => "form-control", "style" => "margin-bottom:15px","readonly" => ($options["mode"]=="delete"?true:false))));
|
|
|
|
|
|
# Password
|
|
if($options["mode"]!="delete"&&$options["masteridentity"]=="SQL") {
|
|
$builder->add('password',
|
|
RepeatedType::class, array(
|
|
"type" => PasswordType::class,
|
|
"required" => ($options["mode"]=="submit"?true:false),
|
|
"options" => array("always_empty" => true),
|
|
"first_options" => array("label" => "Mot de Passe","attr" => array("class" => "form-control", "style" => "margin-bottom:15px")),
|
|
"second_options" => array('label' => 'Confirmer Mot de Passe',"attr" => array("class" => "form-control", "style" => "margin-bottom:15px"))
|
|
)
|
|
);
|
|
}
|
|
|
|
# Optionnel
|
|
$builder->add('usualname',
|
|
TextType::class, array(
|
|
"label" => "Nom d'Usage",
|
|
"required" => false,
|
|
"disabled" => ($options["mode"]=="delete"?true:false),
|
|
"attr" => array("class" => "form-control", "style" => "margin-bottom:15px")
|
|
)
|
|
);
|
|
|
|
$builder->add('givensname',
|
|
TextType::class, array(
|
|
"label" => "Autre Prénom",
|
|
"required" => false,
|
|
"disabled" => ($options["mode"]=="delete"?true:false),
|
|
"attr" => array("class" => "form-control", "style" => "margin-bottom:15px")
|
|
)
|
|
);
|
|
|
|
$builder->add('telephonenumber',
|
|
TextType::class, array(
|
|
"label" => "Téléphone",
|
|
"required" => false,
|
|
"disabled" => ($options["mode"]=="delete"?true:false),
|
|
"attr" => array("class" => "form-control", "style" => "margin-bottom:15px")
|
|
)
|
|
);
|
|
|
|
$builder->add('postaladress',
|
|
TextareaType::class, array(
|
|
"label" => "Adresse",
|
|
"required" => false,
|
|
"disabled" => ($options["mode"]=="delete"?true:false),
|
|
"attr" => array("class" => "form-control", "style" => "margin-bottom:15px; height:90px")
|
|
)
|
|
);
|
|
|
|
$builder->add('birthdate',
|
|
DateType::class, array(
|
|
"label" => "Date de Naissance",
|
|
"required" => false,
|
|
"disabled" => ($options["mode"]=="delete"?true:false),
|
|
"widget" => 'single_text',
|
|
"format" => "dd/MM/yyyy",
|
|
"html5" => false,
|
|
"attr" => array("class" => "form-control js-datepicker", "style" => "margin-bottom:15px","readonly" => ($options["mode"]=="delete"?true:false)
|
|
)
|
|
)
|
|
);
|
|
|
|
$choices=array("" => "", "homme" => "male","femme" => "female");
|
|
$builder->add("gender",
|
|
ChoiceType::class,array(
|
|
"label" =>"Sexe",
|
|
"required" => false,
|
|
'disabled' => ($options["mode"]=="delete"?true:false),
|
|
"attr" => array("class" => "form-control", "style" => "margin-bottom:15px"),
|
|
"choices" => $choices
|
|
)
|
|
);
|
|
|
|
$builder->add('job',
|
|
TextType::class, array(
|
|
"label" => "Métier",
|
|
"required" => false,
|
|
"disabled" => ($options["mode"]=="delete"?true:false),
|
|
"attr" => array("class" => "form-control", "style" => "margin-bottom:15px")
|
|
)
|
|
);
|
|
|
|
$builder->add('position',
|
|
TextType::class, array(
|
|
"label" => "Fonction",
|
|
"required" => false,
|
|
"disabled" => ($options["mode"]=="delete"?true:false),
|
|
"attr" => array("class" => "form-control", "style" => "margin-bottom:15px")
|
|
)
|
|
);
|
|
|
|
|
|
$builder->add('birthcountry',
|
|
Select2EntityType::class, array(
|
|
'label' => "Pays de Naissance",
|
|
'disabled' => ($options["mode"]=="delete"?true:false),
|
|
'multiple' => false,
|
|
'remote_route' => 'cadoles_core_ajax_country_list',
|
|
'class' => 'Cadoles\coreBundle\Entity\Country',
|
|
'primary_key' => 'id',
|
|
'text_property' => 'label',
|
|
'minimum_input_length' => 2,
|
|
'page_limit' => 10,
|
|
'allow_clear' => true,
|
|
'delay' => 250,
|
|
'cache' => false,
|
|
'cache_timeout' => 60000, // if 'cache' is true
|
|
'language' => 'fr',
|
|
'placeholder' => 'Selectionner un pays',
|
|
'attr' => array("class" => "form-control", "style" => "margin-bottom:15px")
|
|
)
|
|
);
|
|
|
|
$builder->add('birthplace',
|
|
Select2EntityType::class, array(
|
|
'label' => "Ville de Naissance",
|
|
'disabled' => ($options["mode"]=="delete"?true:false),
|
|
'multiple' => false,
|
|
'remote_route' => 'cadoles_core_ajax_city_list',
|
|
'class' => 'Cadoles\coreBundle\Entity\City',
|
|
'primary_key' => 'id',
|
|
'text_property' => 'label',
|
|
'minimum_input_length' => 2,
|
|
'page_limit' => 10,
|
|
'allow_clear' => true,
|
|
'delay' => 250,
|
|
'cache' => false,
|
|
'cache_timeout' => 60000, // if 'cache' is true
|
|
'language' => 'fr',
|
|
'placeholder' => 'Selectionner une ville',
|
|
'attr' => array("class" => "form-control", "style" => "margin-bottom:15px")
|
|
)
|
|
);
|
|
|
|
if($session->get('viewniveau02')) {
|
|
$builder->add('niveau02',
|
|
Select2EntityType::class, array(
|
|
'label' => $session->get('labelniveau02'),
|
|
'disabled' => ($options["mode"]=="delete"?true:false),
|
|
'multiple' => false,
|
|
'remote_route' => 'cadoles_core_ajax_niveau02_list',
|
|
'class' => 'Cadoles\coreBundle\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, // if 'cache' is true
|
|
'language' => 'fr',
|
|
'placeholder' => 'Selectionner '.$session->get('labelniveau02'),
|
|
'attr' => array("class" => "form-control", "style" => "margin-bottom:15px")
|
|
)
|
|
);
|
|
}
|
|
|
|
if($options["access"]=="config") {
|
|
$choices=array("simple" => "simple","substantiel" => "substantiel","fort" => "fort");
|
|
$builder->add("authlevel",
|
|
ChoiceType::class,array(
|
|
"label" =>"Niveau d'authentification",
|
|
"required" => true,
|
|
'disabled' => ($options["mode"]=="delete"?true:false),
|
|
"attr" => array("class" => "form-control", "style" => "margin-bottom:15px"),
|
|
"choices" => $choices
|
|
)
|
|
);
|
|
|
|
$choices=array("agent" => "agent","prestataire" => "prestataire","partenaire" => "partenaire","stagiaire" => "stagiare");
|
|
$builder->add("belongingpopulation",
|
|
ChoiceType::class,array(
|
|
"label" =>"Population d'appartenance",
|
|
"required" => true,
|
|
'disabled' => ($options["mode"]=="delete"?true:false),
|
|
"attr" => array("class" => "form-control", "style" => "margin-bottom:15px"),
|
|
"choices" => $choices
|
|
)
|
|
);
|
|
}
|
|
|
|
# Avatar
|
|
$builder->add('avatar',HiddenType::class, array("empty_data" => "noavatar.png"));
|
|
|
|
# Groupes de l'utilisateur
|
|
$builder->add('linkgroups',HiddenType::class, array("mapped" => false));
|
|
|
|
# Modération
|
|
$builder->add('linkmodos',HiddenType::class, array("mapped" => false));
|
|
|
|
}
|
|
|
|
public function configureOptions(OptionsResolver $resolver)
|
|
{
|
|
$resolver->setDefaults(array(
|
|
'data_class' => 'Cadoles\CoreBundle\Entity\User',
|
|
'mode' => "string",
|
|
'access' => "string",
|
|
'perm' => "boolean",
|
|
'userid' => "integer",
|
|
'masteridentity' => "string"
|
|
));
|
|
}
|
|
}
|
|
|