<?php
namespace App\Form\Payment;
use App\Entity\Account\User;
use App\Entity\Scholar\Training\Training;
use InvalidArgumentException;
use Karser\Recaptcha3Bundle\Form\Recaptcha3Type;
use Karser\Recaptcha3Bundle\Validator\Constraints\Recaptcha3;
use Nellapp\Bundle\SDKBundle\ApiClientInterApp\Model\Crm\FundingContactRequestDTO;
use Nellapp\Bundle\SDKBundle\Enum\ChannelUserData\ApplicantTypeEnum;
use Nellapp\Bundle\SDKBundle\Enum\ChannelUserData\CursusCourseEnum;
use Nellapp\Bundle\SDKBundle\Enum\ChannelUserData\CursusModalityEnum;
use Nellapp\Bundle\SDKBundle\Enum\ChannelUserData\FounderTypeEnum;
use Nellapp\Bundle\SDKBundle\Enum\ChannelUserData\RqthStatusEnum;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\TelType;
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 Symfony\Component\Security\Core\Security;
use Symfony\Contracts\Translation\TranslatorInterface;
class FundingType extends AbstractType
{
public function __construct(
private Security $security,
private TranslatorInterface $translator,
) {}
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$user = $this->security->getUser();
$training = $options['training'];
if (!$training instanceof Training) {
throw new InvalidArgumentException();
}
$builder
->add('trainingId', HiddenType::class, [
'data' => $training->getId(),
'attr' => [
'readonly' => true,
],
'required' => true,
])
->add('trainingPrice', HiddenType::class, [
'data' => $training->getPrice() * 100,
'attr' => [
'readonly' => true,
],
'required' => true,
])
->add('founderType', ChoiceType::class, [
'choices' => FounderTypeEnum::getFormChoices(),
'translation_domain' => 'NellappSDKBundle',
'label' => $this->translator->trans('funding.form.payment_meaning.label'),
'required' => true,
])
->add('status', ChoiceType::class, [
'choices' => ApplicantTypeEnum::getFormChoices(),
'translation_domain' => 'NellappSDKBundle',
'label' => $this->translator->trans('funding.form.status.label'),
'required' => true,
])
->add('lastName', TextType::class, [
'label' => 'funding.form.last_name.label',
'data' => $user instanceof User ? $user->getLastname() : '',
'attr' => [
'readonly' => $user instanceof User,
],
'required' => true,
])
->add('firstName', TextType::class, [
'label' => 'funding.form.first_name.label',
'data' => $user instanceof User ? $user->getFirstName() : '',
'attr' => [
'readonly' => $user instanceof User,
],
'required' => true,
])
->add('email', TextType::class, [
'label' => 'funding.form.mail.label',
'data' => $user instanceof User ? $user->getEmail() : '',
'attr' => [
'readonly' => $user instanceof User,
],
'required' => true,
])
->add('phone', TelType::class, [
'required' => true,
'label' => 'funding.form.phone.label',
])
->add('message', TextareaType::class, [
'label' => 'funding.form.message.label',
'required' => false,
])
->add('cursusModality', ChoiceType::class, [
'choices' => CursusModalityEnum::getOpportunityFormChoices(),
'placeholder' => "cursus.entity.cursusModality.no_preference.label",
'translation_domain' => 'NellappSDKBundle',
'label' => $this->translator->trans('funding.form.cursus_modality.label'),
'required' => false,
])
->add('cursusCourse', ChoiceType::class, [
'choices' => CursusCourseEnum::getFormChoices(),
'placeholder' => "cursus.entity.cursusCourse.no_preference.label",
'translation_domain' => 'NellappSDKBundle',
'label' => $this->translator->trans('funding.form.cursus_course.label'),
'required' => false,
])
->add('rqth', ChoiceType::class, [
'choices' => RqthStatusEnum::getFormChoices(),
'label' => $this->translator->trans("funding.form.rqth.label"),
'translation_domain' => 'NellappSDKBundle',
'required' => true,
])
->add('captcha', Recaptcha3Type::class, [
'mapped' => false,
'constraints' => new Recaptcha3([
'message' => 'karser_recaptcha3.message',
]),
'action_name' => 'funding_contact',
'locale' => $options['locale'],
])
;
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'locale' => 'fr',
'data_class' => FundingContactRequestDTO::class,
'training' => null,
]);
}
}