<?php
declare(strict_types=1);
namespace App\Form;
use App\Entity\Local\PushNotificationSubscription;
use App\Entity\Vista\LoyaltyMember;
use App\Form\DataTransformer\VistaTimestampToDateTimeTransformer;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeImmutableToDateTimeTransformer;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\Extension\Core\Type\FormType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\OptionsResolver\OptionsResolver;
class UserValidateType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('MemberId')
->add('FirstName')
->add('LastName')
->add('Email')
->add('UserName')
->add('Password')
->add('FullName')
->add('CardNumber')
->add('MobilePhone')
->add('ClubID')
->add('MiddleName')
->add('Address1')
->add('State')
->add('City')
->add('ZipCode')
->add('EducationLevel')
->add('HouseholdIncome')
->add('PersonsInHousehold')
->add('DateOfBirth')
->add('Status')
->add('Suburb')
->add('Gender')
->add('ContactByThirdParty')
->add('SendNewsletter')
->add('Opera')
->add('FamilyClubAndChildrenActions')
->add('RemembranceEventsService')
->add('WishToReceiveSMS')
->add('WorkZipCode')
->add('CardList', CollectionType::class, ['allow_add' => true])
->add('PreferredGenres', CollectionType::class, ['allow_add' => true])
->add('PreferenceList', CollectionType::class, ['allow_add' => true])
->add('Occupation')
->add('MaritalStatus')
->add('MailingFrequency')
->add('Pin')
->add('MemberLevelId')
->add('MemberLevelName')
->add('LoyaltySessionExpiry')
->add('LoyaltySessionToken')
->add('GiftCard')
->add('GiftCardBalance')
->add('IsBannedFromMakingUnpaidBookingsUntil')
->add('MembershipActivated')
->add('MemberItemId')
->add('ExternalID')
->add('NationalID')
->add('IsAnonymous')
->add('MemberLanguageIETFCode')
->add('UserSessionId')
->add('ExpiryDate')
->add('BalanceList', CollectionType::class, ['allow_add' => true, 'entry_type' => MemberBalanceType::class])
->add('ExpiryPointsList', CollectionType::class, ['allow_add' => true, 'allow_delete' => true, 'entry_type' => ExpiryPointType::class])
->add('PreferredComplexList', CollectionType::class, ['allow_add' => true, 'allow_delete' => true])
->add(
'PushNotificationSubscription',
FormType::class,
['data_class' => PushNotificationSubscription::class]
)
;
$builder->get('DateOfBirth')
->addModelTransformer(new VistaTimestampToDateTimeTransformer())
->addModelTransformer(new DateTimeImmutableToDateTimeTransformer())
;
$builder->get('LoyaltySessionExpiry')
->addModelTransformer(new VistaTimestampToDateTimeTransformer())
;
$builder->get('ExpiryDate')
->addModelTransformer(new VistaTimestampToDateTimeTransformer())
;
$builder->get('ClubID')->addEventListener(FormEvents::SUBMIT, function (FormEvent $event) {
if (empty($event->getData())) {
$event->setData('1');
}
});
$builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
/** @var LoyaltyMember $user */
$user = $event->getData();
$user->setPreferenceList([]);
});
foreach ($builder->all() as $item) {
/** @var FormBuilderInterface $item */
$item->setPropertyPath(lcfirst($item->getName()));
}
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => LoyaltyMember::class,
'allow_extra_fields' => true,
'csrf_protection' => false,
]);
}
}