|
- <?php
-
- namespace Lc\CaracoleBundle\Form\Ticket;
-
- use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
- use Lc\CaracoleBundle\Model\Order\OrderShopInterface;
- use Lc\CaracoleBundle\Model\Section\SectionInterface;
- use Lc\CaracoleBundle\Repository\Order\OrderShopStore;
- use Lc\CaracoleBundle\Repository\Section\SectionStore;
- use Lc\CaracoleBundle\Solver\Price\PriceSolver;
- use Lc\SovBundle\Component\FormComponent;
- use Lc\SovBundle\Doctrine\EntityManager;
- use Lc\SovBundle\Model\Ticket\TicketInterface;
- use Lc\SovBundle\Solver\Ticket\TicketSolver;
- use Lc\SovBundle\Translation\TranslatorAdmin;
- use Symfony\Bridge\Doctrine\Form\Type\EntityType;
- use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
- use Symfony\Component\Form\Extension\Core\Type\EmailType;
- use Symfony\Component\Form\Extension\Core\Type\FileType;
- 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\Component\Validator\Constraints\File;
- use Lc\SovBundle\Form\Ticket\TicketFormType as SovTicketFormType;
-
- class TicketFormType extends SovTicketFormType
- {
- protected Security $security;
- protected FormComponent $formComponent;
- protected OrderShopStore $orderShopStore;
- protected PriceSolver $priceSolver;
- protected SectionStore $sectionStore;
-
- public function __construct(
- Security $security,
- EntityManager $entityManager,
- TranslatorAdmin $translatorAdmin,
- TicketSolver $ticketSolver,
- FormComponent $formComponent,
- OrderShopStore $orderShopStore,
- PriceSolver $priceSolver,
- SectionStore $sectionStore
- ) {
- parent::__construct($entityManager, $translatorAdmin, $ticketSolver);
-
- $this->security = $security;
- $this->formComponent = $formComponent;
- $this->orderShopStore = $orderShopStore;
- $this->priceSolver = $priceSolver;
- $this->sectionStore = $sectionStore;
- }
-
- public function buildForm(FormBuilderInterface $builder, array $options)
- {
- $isConnected = $this->security->getUser();
-
- $sectionList = $this->sectionStore->setMerchant($options['merchant'])->getOnline();
- $builder->add(
- 'section',
- EntityType::class,
- [
- 'label'=> 'Espace concerné',
- 'choices' => $sectionList,
- 'required' => false,
- 'placeholder'=> 'Je ne sais pas',
- 'class' => $this->entityManager->getEntityName(SectionInterface::class),
- ]
- );
-
- if (!$isConnected) {
- $builder->add(
- 'visitorFirstname',
- TextType::class,
- [
- 'label' => 'Prénom'
- ]
- )
- ->add(
- 'visitorLastname',
- TextType::class,
- [
- 'label' => 'Nom'
- ]
- )
- ->add(
- 'visitorEmail',
- EmailType::class,
- [
- 'label' => 'Email'
- ]
- );
- }
-
- $builder->add(
- 'type',
- ChoiceType::class,
- [
- 'label' => 'Type',
- 'choices' => $this->translatorAdmin->transChoices(
- TicketSolver::getTypeChoices(),
- 'Ticket',
- 'type'
- ),
- ]
- );
-
- if ($isConnected) {
- $builder->add(
- 'orderShop',
- EntityType::class,
- [
- 'class' => $this->entityManager->getEntityName(OrderShopInterface::class),
- 'multiple' => false,
- 'expanded' => false,
- 'choices' => $this->orderShopStore->getBy(
- [
- 'user' => $this->security->getUser(),
- 'isValid' => true
- ]
- ),
- 'label' => 'entity.default.fields.order',
- 'placeholder' => '-- Choisissez une commande --',
- 'required' => false,
- 'choice_label' => function ($orderShop, $key, $value) {
- $dateString = '';
- $dateObject = $orderShop->getValidationDate() ? $orderShop->getValidationDate(
- ) : $orderShop->getCreatedAt();
-
- if ($orderShop->getValidationDate()) {
- $dateString .= 'du ' . $dateObject->format('d/m/Y') . ' ';
- }
-
- return 'Commande ' . $dateString .
- '(' . number_format($this->priceSolver->getTotalWithTax($orderShop), 2) .
- ' €)';
- },
- 'translation_domain' => 'admin',
- ]
- );
- } else {
- $this->formComponent->addCaptchaType($builder);
- }
-
- $builder->add(
- 'subject',
- TextType::class
- );
-
- $builder->add(
- 'message',
- TextareaType::class,
- [
- 'mapped' => false,
- 'label' => 'Message'
- ]
- );
-
- $builder->add(
- 'image',
- FileType::class,
- [
- 'label' => 'Photo',
- 'mapped' => false,
- 'required' => false,
- 'constraints' => [
- new File(
- [
- 'maxSize' => '2048k',
- 'mimeTypes' => [
- 'image/png',
- 'image/jpeg',
- 'image/jpg',
- 'image/gif',
- ],
- 'mimeTypesMessage' => "Mauvais format d'image (formats acceptés : jpeg, png, gif)",
- ]
- )
- ],
- ]
- );
- }
-
- /**
- * {@inheritdoc}
- */
- public function configureOptions(OptionsResolver $resolver)
- {
- $resolver->setDefaults(
- [
- 'data_class' => $this->entityManager->getEntityName(TicketInterface::class),
- 'merchant' => MerchantInterface::class,
- ]
- );
- }
- }
|