<?php
namespace App\Model\Form;
use App\Constants\UserExtension;
use App\Entity\BillingPoint;
use App\Entity\PointConversionRate;
use App\Entity\PointOfSale;
use App\Entity\Programme;
use App\Entity\Regate;
use App\Entity\SaleOrderValidation;
use App\Entity\Univers;
use App\Entity\User;
use App\Form\Type\Back\CoverageAreaDepartmentType;
use App\Form\Type\Back\User\UserSubscriptionType;
use App\Form\Type\Custom\RegateChoiceType;
use App\Model\Form\Type\FormField;
use App\Model\Form\Type\FormFieldEntity;
use App\Model\Form\Type\FormFieldEntityParent;
use App\Model\Form\Type\FormFieldEntityRegate;
use App\Model\Form\Type\FormFieldRegateChoice;
use App\Services\Common\CommunityService;
use App\Services\DTV\YamlConfig\YamlReader;
use DateTime;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
use Exception;
use Karser\Recaptcha3Bundle\Form\Recaptcha3Type;
use Karser\Recaptcha3Bundle\Validator\Constraints\Recaptcha3;
use Presta\ImageBundle\Form\Type\ImageType;
use Psr\Log\LoggerInterface;
use Symfony\Bridge\Doctrine\Form\ChoiceList\DoctrineChoiceLoader;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\NumberType;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\Validator\Constraints\IsTrue;
use Symfony\Contracts\Translation\TranslatorInterface;
/**
* Permet de générer les formType des User (Back, register, etc en passant une configuration dans le yaml
* global.form_type.user
*/
class UserField extends Field
{
private CommunityService $communityService;
private EntityManagerInterface $em;
/**
* @param LoggerInterface $logger
* @param Security $security
* @param CommunityService $communityService
* @param EntityManagerInterface $em
* @param TranslatorInterface $translator
*/
public function __construct(
LoggerInterface $logger,
Security $security,
CommunityService $communityService,
EntityManagerInterface $em,
YamlReader $yamlReader,
TranslatorInterface $translator
)
{
parent::__construct( $logger, $security, $yamlReader);
$this->communityService = $communityService;
$this->em = $em;
$this->translator = $translator;
}
/**
* Permet de configurer dans quelle catégorie de configuration les champs sont accessibles
*
* @param $formType
*
* @return string[][]
*/
public static function getAllFieldByFormType( $formType ): array
{
$fields = [
'email' => [ 'back_office', 'register', 'profile', 'membership_security' ],
'transactionalEmail' => [ 'back_office' ],
'civility' => [
'back_office',
'register',
'profile',
'membership_security',
'accept_cgu_first',
],
'firstName' => [
'back_office',
'register',
'profile',
'membership_security',
'accept_cgu_first',
],
'lastName' => [
'back_office',
'register',
'profile',
'membership_security',
'accept_cgu_first',
],
'phone' => [
'back_office',
'register',
'profile',
'membership_security',
'accept_cgu_first',
],
'avatarFile' => [
'back_office',
'profile',
],
'logoFile' => [
'back_office',
'profile',
],
'mobile' => [
'back_office',
'register',
'profile',
'membership_security',
'accept_cgu_first',
],
'canOrder' => [ 'back_office' ],
'roles' => [ 'back_office' ],
'createdAt' => [ 'back_office' ],
'regate' => [ 'back_office', 'register', 'profile' ],
'responsableRegate' => [ 'back_office' ],
'job' => [ 'back_office', 'register', 'accept_cgu_first' ],
'sapAccount' => [ 'back_office', 'register' ],
'company' => [
'back_office',
'register',
'profile',
'membership_security',
'accept_cgu_first',
],
'companySiret' => [
'back_office',
'register',
'profile',
'membership_security',
'accept_cgu_first',
],
'address1' => [
'back_office',
'register',
'profile',
'membership_security',
'accept_cgu_first',
],
'address2' => [
'back_office',
'register',
'profile',
'membership_security',
'accept_cgu_first',
],
'postcode' => [
'back_office',
'register',
'profile',
'membership_security',
'accept_cgu_first',
],
'city' => [
'back_office',
'register',
'profile',
'membership_security',
'accept_cgu_first',
],
'commercial' => [ 'back_office' ],
'coverageArea' => [ 'back_office' ],
'agency' => [ 'back_office', 'register' ],
'rrdiCode' => [ 'back_office', 'register' ],
'sellerCode' => [ 'back_office', 'register' ],
'customerId' => [ 'back_office', 'register' ],
'groupement' => [ 'back_office', 'register', 'accept_cgu_first' ],
'birthDate' => [ 'back_office', 'register', 'profile' ],
'birthPlace' => [ 'back_office', 'register', 'profile' ],
'programme' => [ 'back_office' ],
'password' => [ 'register' ],
'newsletter' => [ 'register' ],
'cguAt' => [ 'back_office', 'register', 'membership_security' ],
'companyIsOk' => [ 'register' ],
'message' => [ 'membership_security' ],
'saleOrderValidation' => [ 'back_office' ],
'universes' => [ 'back_office' ],
'billingPoint' => [ 'back_office' ],
'parents' => [ 'back_office' ],
'subscription' => [ 'back_office' ],
'pointExpirationDate' => [ 'back_office' ],
'pointSystem' => [ 'back_office' ],
'pointConversionRate' => [ 'back_office' ],
'pointOfSale' => [ 'back_office' ],
'internalIdentification1' => [ 'back_office' ],
'internalCode' => [ 'back_office, register' ],
'commitmentLevel' => [ 'back_office' ],
'potentialPoints' => [ 'back_office' ],
'status' => [ 'back_office' ],
'accountId' => [ 'back_office' ],
];
return array_filter( $fields, static function ( $value ) use ( $formType ) {
return in_array( $formType, $value, TRUE );
} );
}
/**
* Génère l'objet qui sera ensuite utilisé pour ajouter le formType avec sa configuration
*
* @param string $fieldName
* @param array $fieldConfig
* @param User|null $entity
* @param string $roleContext
*
* @return FormField
*
* @throws Exception
*/
public function getField( string $fieldName, array $fieldConfig = [], $entity = NULL, string $roleContext = 'ROLE_USER' ): FormField
{
/** @var User $currentUser */
$currentUser = $this->security->getUser();
$config = $this->getConfig( $fieldName, $fieldConfig, $entity, $roleContext );
// on récupère l'instance du field
$fieldType = $this->getFieldType( $config );
// En fonction du formType, on utilise Formfield ou un enfant pour le configurer.
// C'est ici qu'on peut override les actions en interceptant le type avant d'aller chercher la fonction par défaut
switch ( $fieldType ) {
case EntityType::class :
// surcharge pour le champ Parents
if ( $fieldName === 'parents' ) {
$field = new FormFieldEntityParent( $this->communityService, $config[ 'entity_parents_options' ], $currentUser );
} elseif ( $fieldName === 'regate' && isset( $config[ 'entity_regate_options' ] ) ) {
$field = new FormFieldEntityRegate( $this->communityService, $config[ 'entity_regate_options' ], $currentUser );
} else {
$field = new FormFieldEntity();
}
break;
case RegateChoiceType::class :
$config[ 'choice_loader' ] = new DoctrineChoiceLoader(
$this->em,
Regate::class,
$config[ 'query_builder' ],
NULL // Group by
);
unset(
$config[ 'query_builder' ],
);
$field = new FormFieldRegateChoice();
break;
default:
$field = $this->createDefaultFormField( $fieldType, $config );
}
if ( isset( $config[ 'override_data' ] ) ) {
$field->createProperty( 'data', $config[ 'override_data' ] );
}
if ( isset( $config[ 'readonly' ] ) ) {
$field->createProperty( 'disabled', $config[ 'readonly' ] );
}
// On set les options sur l'objet FormField
$this->setFormFieldOptions( $config, $fieldType, $field );
return $field;
}
/**
* @param string $fieldName
* @param array $fieldConfig
* @param $entity
* @param string $roleContext
*
* @return array
*
* @throws Exception
*/
protected function getConfig( string $fieldName, array $fieldConfig = [], $entity = NULL, string $roleContext = 'ROLE_USER' ): array
{
// Merge des configs par défaut et de ce qui se trouve dans le yaml
return FormField::getFieldConfig( $this->defaultValue( $fieldName, $entity, $roleContext ), $fieldConfig );
}
/**
* Tableau des valeurs par défaut de tous les champs configurable dans le yaml
*
* @param $field
* @param User|null $entity Utilisateur
* @param string $roleContext
*
* @return array|mixed
*
* @throws Exception
*/
public function defaultValue( $field, $entity = NULL, string $roleContext = 'ROLE_USER' )
{
/** @var User $currentUser */
$currentUser = $this->security->getUser();
$defaultJobs = [
'Pas de fonction' => NULL,
];
$roles = ( $entity === NULL || $entity->getId() === NULL ) ? [ $roleContext ] : $entity->getRoles();
$jobs = array_merge(
$defaultJobs,
$this->communityService->getJobSlugAllowedToRoles( $roles )
);
// fin de modif
// Hack pour filter les jobs quand un CDEF edit un user
if ( $currentUser !== NULL && $currentUser->getJob() === 'CDEV' ) {
$jobs = [];
$jobSlugs = $this->communityService->getInferiorJobsOf( 'CDEV' );
foreach ( $jobSlugs as $slug ) {
$jobs[ $this->communityService->getJob( $slug )[ 'label' ] ] = $slug;
}
}
$defaultData = [
'pointExpirationDate' => NULL,
'pointExpirationDateRelative' => 0,
'pointSystem' => NULL,
'internalIdentification1' => NULL,
'internalIdentification2' => NULL,
'internalIdentification3' => NULL,
'potentialPoints' => 0,
'socialSecurityNbr' => NULL,
'closeDateContract' => NULL
];
if ( $entity instanceof User ) {
if ( $entity->getExtensionBySlug( UserExtension::POINT_DATE_EXPIRATION ) ) {
$defaultData[ 'pointExpirationDate' ] = new DateTime(
$entity->getExtensionBySlug( UserExtension::POINT_DATE_EXPIRATION )
);
$defaultData[ 'pointExpirationDateRelative' ] = $entity->getExtensionBySlug( UserExtension::POINT_DATE_EXPIRATION );
}
if ( $entity->getExtensionBySlug( UserExtension::POINT_SYSTEM ) ) {
$defaultData[ 'pointSystem' ] = $entity->getExtensionBySlug( UserExtension::POINT_SYSTEM );
}
if ( $entity->getExtensionBySlug( UserExtension::INTERNAL_IDENTIFICATION_1 ) ) {
$defaultData[ 'internalIdentification1' ] = $entity->getExtensionBySlug(
UserExtension::INTERNAL_IDENTIFICATION_1
);
}
if ( $entity->getExtensionBySlug( UserExtension::INTERNAL_IDENTIFICATION_2 ) ) {
$defaultData[ 'internalIdentification2' ] = $entity->getExtensionBySlug(
UserExtension::INTERNAL_IDENTIFICATION_2
);
}
if ( $entity->getExtensionBySlug( UserExtension::INTERNAL_IDENTIFICATION_3 ) ) {
$defaultData[ 'internalIdentification3' ] = $entity->getExtensionBySlug(
UserExtension::INTERNAL_IDENTIFICATION_3
);
}
if ( $entity->getExtensionBySlug( UserExtension::POTENTIAL_POINTS ) ) {
$defaultData[ 'potentialPoints' ] = $entity->getExtensionBySlug(
UserExtension::POTENTIAL_POINTS
);
}
if ( $entity->getExtensionBySlug( UserExtension::SOCIAL_SECURITY_NUMBER ) ) {
$defaultData[ 'socialSecurityNbr' ] = $entity->getExtensionBySlug(
UserExtension::SOCIAL_SECURITY_NUMBER
);
}
if ( $entity->getExtensionBySlug( UserExtension::CLOSE_DATE_CONTRACT ) ) {
$defaultData[ 'closeDateContract' ] = new DateTime($entity->getExtensionBySlug(
UserExtension::CLOSE_DATE_CONTRACT
));
}
// @TODO : le test ci-dessous ne semble plus utilisé, à vérifier
// if ($entity->getExtensionBySlug(UserExtension::QUOTAS_ORDERS)) {
// $defaultData[ 'quotasOrders' ] = $entity->getExtensionBySlug(
// UserExtension::QUOTAS_ORDERS
// );
// }
}
$fields = [
'avatarFile' => [
'formType' => ImageType::class,
'label' => $this->translator->trans('avatar'),
'help' => 'Dimensions minimales recommandées : 400px / 400px',
'required' => TRUE,
'enable_remote' => FALSE,
'upload_button_class' => 'btn btn-sm btn-primary',
'preview_width' => '100%',
'preview_height' => '100%',
'max_width' => 800,
'max_height' => 800,
'upload_quality' => 1,
'upload_mimetype' => 'image/jpg',
'aspect_ratios' => [
[
'value' => 1,
'label' => '800/800',
'checked' => TRUE,
],
],
'description' => "Import d'une image pour un avatar si prévu",
],
'logoFile' => [
'formType' => ImageType::class,
'label' => $this->translator->trans('company_logo'),
'help' => 'Dimensions minimales recommandées : 400px / 400px',
'required' => TRUE,
'enable_remote' => FALSE,
'upload_button_class' => 'btn btn-sm btn-primary',
'preview_width' => '100%',
'preview_height' => '100%',
'max_width' => 400,
'max_height' => 400,
'upload_quality' => 1,
'upload_mimetype' => 'image/jpg',
'aspect_ratios' => [
[
'value' => 1,
'label' => '400/400',
'checked' => TRUE,
],
],
'description' => "Import d'une image pour un logo si prévu",
],
'transactionalEmail' => [
'formType' => EmailType::class,
'label' => $this->translator->trans('secondary_email'),
'help' => 'Adresse email renseignée par l\'utilisateur en cas de pare-feu d\'enteprise. Cette adresse est utilisée pour les envois d\'email uniquement',
'required' => TRUE,
'attr' => [
'data-parsley-type' => 'email',
],
'description' => "Affiche le champ de l'email secondaire si actif sur la plateforme",
],
'civility' => [
'formType' => ChoiceType::class,
'label' => 'Civilité',
'choices' => [
"Monsieur" => "M",
"Madame" => "Mme",
],
],
'canOrder' => [
'formType' => CheckboxType::class,
'label' => 'Utilisateur peut commander',
'required' => FALSE,
],
'roles' => [
'formType' => ChoiceType::class,
'label' => $this->translator->trans('role'),
// 'data' => ['Utilisateur' => 'ROLE_USER'],
'empty_data' => 'ROLE_USER',
'choices' => [
'Utilisateur' => 'ROLE_USER',
'Administrateur' => 'ROLE_ADMIN',
],
'multiple' => TRUE,
'required' => TRUE,
],
'regate' => [
'formType' => EntityType::class,
'label' => 'Régate',
'class' => Regate::class,
'placeholder' => "Choisir une régate",
'by_reference' => TRUE,
'multiple' => FALSE,
'attr' => [
'class' => '',
],
'entity_regate_options' => [
'method' => NULL,
],
'query_builder' => NULL,
'choice_label' => function ( Regate $regate ) {
return $regate->getAffectation() . ' | ' . $regate->getName() . ' | ' . $regate->getLevel();
},
'description' => "Lien avec une régate déjà existante dans la BDD, si des filtrages doivent s'appliquer, prévenir les dev",
],
'responsableRegate' => [
'formType' => EntityType::class,
'by_reference' => TRUE,
'label' => 'Responsable de la régate',
'class' => Regate::class,
'placeholder' => "Choisir une régate",
'choice_label' => function ( $regate ) {
return $regate->getAffectation() . ' | ' . $regate->getName() . ' | ' . $regate->getLevel();
},
'description' => "Défini la régate dont l'utilisateur est responsable. 1 utilisateur n'est responsable que d'une régate, une régate n'a qu'un seul responsable ",
],
'job' => [
'formType' => ChoiceType::class,
'label' => 'Fonction',
'placeholder' => 'Choisir',
'choices' => $jobs,
'description' => "Attribuer une fonction a un utilisateur d'après une liste déjà définie, compte pour les ACL",
],
'sapAccount' => [
'formType' => TextType::class,
'label' => 'Compte SAP',
'attr' => [
'data-parsley-type' => "digits",
'data-parsley-pattern-message' => "Doit contenir 6 ou 7 chiffres",
'minlength' => 6,
'maxlength' => 7,
],
],
'company' => [
'formType' => TextType::class,
'label' => 'Entreprise',
],
'companySiret' => [
'formType' => TextType::class,
'label' => 'N° Siret ou Siren',
'attr' => [
'data-parsley-type' => "digits",
'data-parsley-pattern-message' => "Doit contenir entre 9 et 14 chiffres",
'minlength' => 9,
'maxlength' => 14,
],
'description' => "de 9 à 14 chiffres",
],
'address1' => [
'formType' => TextareaType::class,
'label' => 'Adresse',
'description' => "Textarea par défaut",
],
'address2' => [
'formType' => TextareaType::class,
'label' => "Complément d'adresse",
'description' => "Textarea par défaut",
],
'postcode' => [
'formType' => TextType::class,
'label' => 'Code postal',
'attr' => [
'data-parsley-length' => '[4,5]',
'data-parsley-type' => 'number',
'maxlength' => '5',
],
'description' => "5 chiffres",
],
'city' => [
'formType' => TextType::class,
'label' => 'Ville',
],
'commercial' => [
'formType' => EntityType::class,
'by_reference' => TRUE,
'choice_label' => 'email',
'label' => 'Commercial',
'class' => User::class,
'query_builder' => function ( EntityRepository $er ) {
return $er->createQueryBuilder( 'u' )
->where( '(u.roles LIKE \'%ROLE_COMMERCIAL%\' or u.job LIKE \'%commercial%\' or u.job LIKE \'%commercial_agent%\')' )
->orderBy( 'u.username', 'ASC' )
;
},
'description' => "Relation avec un utilisateur existant portant le role de commercial (REHAU et DAIKIN uniquement)",
],
'coverageArea' => [
'formType' => CoverageAreaDepartmentType::class,
'label' => 'Zone de couverture',
'options' => [
'type' => [
'required' => TRUE,
'multiple' => TRUE,
'expanded' => TRUE,
'attr' => [
'class' => 'd-column',
'data-select-all' => TRUE,
],
],
],
'description' => "Choix d'une zone de couverture en selectionnant des départements uniquement",
],
'pointOfSale' => [
'formType' => EntityType::class,
'label' => 'Point de vente',
"choice_label" => "name",
'by_reference' => TRUE,
"class" => PointOfSale::class,
'query_builder' => function ( EntityRepository $er ) use ( $currentUser ) {
$qb = $er->createQueryBuilder( 'pos' );
if ( $currentUser->getJob() !== NULL ) {
$qb->andWhere( 'pos.createdBy = :id' )
->setParameter( 'id', $currentUser->getId() )
;
}
$qb->orderBy( 'pos.name', 'ASC' );
return $qb;
},
'description' => "Attribut un point de vente existant dans la BDD",
],
'rrdiCode' => [
'formType' => TextType::class,
'label' => 'Code Rrdi',
],
'sellerCode' => [
'formType' => TextType::class,
'label' => 'Code vendeur',
],
'customerId' => [
'formType' => TextType::class,
'label' => 'Id Client',
],
'groupement' => [
'formType' => TextType::class,
'label' => 'Groupement',
],
'birthDate' => [
'formType' => DateType::class,
'label' => "Date de naissance",
'widget' => 'single_text',
'html5' => TRUE,
'attr' => [
'placeholder' => 'jj/mm/aaaa',
'autocomplete' => 'none',
],
],
'birthPlace' => [
'formType' => TextType::class,
'label' => 'Lieux de naissance',
],
'programme' => [
'formType' => EntityType::class,
'by_reference' => TRUE,
'label' => 'Programme',
'class' => Programme::class,
'placeholder' => "Choisir un programme",
'choice_label' => 'name',
'description' => "Attribut un programme existant dans la BDD",
],
'password' => [
'formType' => RepeatedType::class,
'type' => PasswordType::class,
'first_options' => [
'label' => 'Créer mon mot de passe',
'label_attr' => [
'class' => 'custom-account-label',
],
'attr' => [
'autocomplete' => 'new-password',
'data-parsley-error-message' => 'Le mot de passe doit contenir au moins 8 caractères, 1 majuscule, 1 minuscule, 1 chiffre et un caractère spécial @ $ ! % * ? &',
'data-parsley-pattern' => "^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*[^A-Za-z0-9]).{8,}$",
'class' => 'custom-account-input',
],
],
'second_options' => [
'label' => 'Confirmer mon mot de passe',
'label_attr' => [
'class' => 'custom-account-label',
],
'attr' => [
'class' => 'custom-account-input',
],
],
'invalid_message' => 'Les champs de mot de passe doivent correspondre.',
// instead of being set onto the object directly,
// this is read and encoded in the controller
'mapped' => FALSE,
'required' => TRUE,
'description' => "Affiche la modification du mot de passe",
],
'newsletter' => [
'formType' => CheckboxType::class,
'label' => 'Je souhaite recevoir la Newsletter',
'required' => FALSE,
],
'cguAt' => [
'formType' => CheckboxType::class,
'label' => "J'ai lu et j'accepte le <a href='/document/reglement' target='blank'>règlement de la plateforme</a> ",
'label_html' => TRUE,
'mapped' => FALSE,
'constraints' => [
new IsTrue( [
'message' => 'Vous devez accepter le règlement de la plateforme continuer votre inscription',
] ),
],
],
'companyIsOk' => [
'formType' => CheckboxType::class,
'label' => "J'atteste être le dirigeant de l’entreprise, ou à défaut avoir informé le dirigeant de mon inscription au Club REHAU expert fenêtre",
'mapped' => FALSE,
'constraints' => [
new IsTrue( [
'message' => 'Vous devez accepter pour continuer votre inscription',
] ),
],
],
'message' => [
'formType' => TextareaType::class,
'label' => 'Votre message',
],
'parents' => [
'formType' => EntityType::class,
'label' => 'Parents',
'class' => User::class,
'placeholder' => 'Choisir',
'by_reference' => FALSE,
'multiple' => TRUE,
'attr' => [
'class' => '',
],
'entity_parents_options' => [
'byRoles' => NULL,
'byJobsParentOf' => NULL,
'byJobs' => NULL,
],
'query_builder' => NULL,
'choice_label' => function ( User $user ) use ( $jobs ) {
$job = array_search( $user->getJob(), $jobs, TRUE );
if ( $job ) {
return $user->getFullName() . " ($job)";
}
return $user->getFullName();
},
'description' => "Défini une liste d'utilisateur existant comme parents",
],
'saleOrderValidation' => [
'formType' => EntityType::class,
'by_reference' => TRUE,
'label' => 'Seuil de validation',
'required' => FALSE,
'class' => SaleOrderValidation::class,
'choice_label' => function ( $saleOrderValidation ) {
return $saleOrderValidation->getLevel() . ' | >= ' . $saleOrderValidation->getAmount();
},
'description' => "Attribut un seuil de validation existant dans la BDD si la plateforme le demande",
],
'universes' => [
'formType' => EntityType::class,
'by_reference' => TRUE,
'label' => 'Univers',
'required' => FALSE,
'class' => Univers::class,
'multiple' => TRUE,
'expanded' => TRUE,
'choice_label' => function ( $univers ) {
return $univers->getSlug() . ' | ' . $univers->getDescription();
},
'description' => "Attribut un univers existant dans la BDD",
],
'billingPoint' => [
'formType' => EntityType::class,
'by_reference' => TRUE,
'label' => "Point de facturation",
'required' => TRUE,
'class' => BillingPoint::class,
'multiple' => FALSE,
'choice_label' => function ( $entity ) {
return $entity->getName() . ' | ' . $entity->getCompany();
},
'description' => "Attribut un point de facturation existant dans la BDD",
],
'subscription' => [
'formType' => UserSubscriptionType::class,
'label' => "Adhésion",
'description' => "Attribut une adhésion existante dans la BDD + date",
],
'pointExpirationDate' => [
'formType' => DateType::class,
'label' => "Date d'expiration des points",
'widget' => 'single_text',
'html5' => TRUE,
'attr' => [
'placeholder' => 'jj/mm/aaaa',
'autocomplete' => 'none',
'relative_data' => $defaultData[ 'pointExpirationDateRelative' ],
],
'override_data' => $defaultData[ 'pointExpirationDate' ],
'mapped' => FALSE,
'description' => "Défini une date d'expiration spécifique pour l'utilisateur (ALGOREL)",
],
'pointSystem' => [
'formType' => ChoiceType::class,
'label' => 'Type de système',
'choices' => [
"Conversion du CA en points" => "ca",
"Import de points simple" => "point",
],
'override_data' => $defaultData[ 'pointSystem' ],
'mapped' => FALSE,
'description' => "Défini un système de point spécifique pour l'utilisateur (ALGOREL)",
],
'internalIdentification1' => [
'formType' => TextType::class,
'label' => 'Code Identification',
'override_data' => $defaultData[ 'internalIdentification1' ],
'mapped' => FALSE,
'description' => "Défini un code spécifique au user, sans relation, (userExtension)",
],
'internalIdentification2' => [
'formType' => TextType::class,
'label' => 'Code Identification N°2',
'override_data' => $defaultData[ 'internalIdentification2' ],
'mapped' => FALSE,
'description' => "Défini un code spécifique au user, sans relation, (userExtension)",
],
'internalIdentification3' => [
'formType' => TextType::class,
'label' => 'Code Identification N°3',
'override_data' => $defaultData[ 'internalIdentification3' ],
'mapped' => FALSE,
'description' => "Défini un code spécifique au user, sans relation, (userExtension)",
],
'pointConversionRate' => [
'formType' => EntityType::class,
'label' => "Taux de conversion",
'by_reference' => TRUE,
'class' => PointConversionRate::class,
'placeholder' => 'Veuillez choisir une catégorie',
'required' => TRUE,
'query_builder' => function ( EntityRepository $er ) use ( $currentUser ) {
return $er->createQueryBuilder( 'pcr' )
->andWhere( 'pcr.owner = :userId' )
->addOrderBy( 'pcr.label', 'ASC' )
->setParameter( 'userId', $currentUser->getId() )
;
},
'choice_label' => function ( PointConversionRate $pcr ) {
return $pcr->getLabel() . ' - ' . $pcr->getRate() . '€ = 1 point';
},
'description' => "Attribut un taux de conversion existant dans la BDD (ALGOREL)",
],
'internalCode' => [
'formType' => TextType::class,
'label' => 'Code interne',
],
'captcha' => [
'formType' => Recaptcha3Type::class,
'mapped' => false,
'label' => false,
'required' => false
],
'commitmentLevel' => [
'formType' => ChoiceType::class,
'label' => "Niveaux d'engagement",
],
'potentialPoints' => [
'formType' => NumberType::class,
'label' => "Points potentiels",
'override_data' => $defaultData[ 'potentialPoints' ],
'mapped' => FALSE,
'description' => "Défini un montant de point potentiel, sans relation, informatif uniquement, (userExtension)",
],
'socialSecurityNbr' => [
'formType' => TextType::class,
'label' => 'N° de Sécurité sociale',
'override_data' => $defaultData[ 'socialSecurityNbr' ],
'mapped' => FALSE,
'description' => "Défini le numéro de sécu, (userExtension)",
],
'createdAt' => [
'formType' => DateType::class,
'label' => 'Date de création',
'widget' => 'single_text',
'html5' => TRUE,
],
'status' => [
'formType' => ChoiceType::class,
'mapped' => FALSE,
'label' => 'Status',
'multiple' => FALSE,
'override_data' => $entity !== NULL ? $entity->getStatus() : NULL,
'choices' => $entity instanceof User ? $this->getUserStatusChoices( $entity ) : [],
'description' => "Permet de modifier le statut du user en fonction du workflow",
],
'accountId' => [
'formType' => TextType::class,
'label' => 'Identifiant unique',
],
/// MGL
'codePartenaire' => [
'formType' => TextType::class,
'label' => 'Code partenaire',
],
/// myrcmreward
'closeDateContract' => [
'formType' => DateType::class,
'label' => 'Date de fin de mission',
'widget' => 'single_text',
'html5' => true,
'mapped' => false,
'override_data' => $defaultData[ 'closeDateContract' ]
],
'sendCguBySms' => [
'formType' => CheckboxType::class,
'label' => 'Recevoir le mail de bienvenue par sms ?',
'required' => FALSE,
'mapped' => false,
],
];
if ( !isset( $fields[ $field ] ) && parent::defaultValue( $field ) !== [] ) {
return parent::defaultValue( $field, $entity );
}
// retourne le tableau entier ou juste le champ demandé.
try {
$fields[ $field ] = $this->addLabelHtml( $fields[ $field ] );
return $field === 'all' ? $fields : $fields[ $field ];
}
catch ( Exception $e ) {
$this->logger->error( $e->getMessage() . ' : ' . $e->getTraceAsString() );
throw new Exception( 'Le champ "' . $field . '" n\'existe pas dans UserField.php' );
}
}
/**
* @param User $user
*
* @return array
*/
private function getUserStatusChoices( User $user ): array
{
$defaultStatus = [
'register_pending' => 'Attente d\'inscription',
'admin_pending' => 'Attente validation par admin',
'cgu_pending' => 'En attente validation CGU',
'cgu_declined' => 'CGU refusées',
'enabled' => 'Actif',
'disabled' => 'Désactivé',
'archived' => 'Archivé',
'deleted' => 'Supprimer définitivement !',
];
$status = [];
// user pas encore créé
if ( $user->getId() === NULL ) {
$status = [ 'admin_pending', 'cgu_pending', 'disabled' ];
} else {
switch ( $user->getStatus() ) {
case 'register_pending' :
$status = [ 'register_pending', 'admin_pending', 'cgu_pending' ];
break;
case 'admin_pending' :
$status = [ 'admin_pending', 'cgu_pending', 'deleted' ];
$defaultStatus[ 'cgu_pending' ] = 'Accepter Inscription';
$defaultStatus[ 'deleted' ] = 'Refuser Inscription';
break;
case 'cgu_pending' :
$status = [ 'admin_pending', 'cgu_pending', 'disabled' ];
break;
case 'cgu_declined' :
$status = [ 'cgu_declined', 'cgu_pending', 'deleted' ];
break;
case 'enabled' :
$status = [ 'archived', 'disabled', 'enabled' ];
break;
case 'disabled' :
$status = [ 'disabled', 'enabled', 'cgu_pending', 'archived' ];
break;
case 'archived' :
$status = [ 'archived', 'cgu_pending', 'deleted' ];
break;
case 'deleted' :
$status = [ 'deleted' ];
break;
}
}
$choices = [];
foreach ( $status as $s ) {
$choices[ $defaultStatus[ $s ] ] = $s;
}
return $choices;
}
}