src/Form/ContractOrderType.php line 14

  1. <?php
  2. namespace App\Form;
  3. use App\Entity\ContractOrder;
  4. use App\Entity\Destination;
  5. use App\Service\ContractOrderService;
  6. use Symfony\Component\Form\AbstractType;
  7. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  8. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  9. use Symfony\Component\Form\FormBuilderInterface;
  10. use Symfony\Component\OptionsResolver\OptionsResolver;
  11. class ContractOrderType extends AbstractType
  12. {
  13.     public function __construct(private ContractOrderService $contractOrderService)
  14.     {
  15.     }
  16.     public function buildForm(FormBuilderInterface $builder, array $options): void
  17.     {
  18.         /** @var ContractOrder $contractOrder */
  19.         $contractOrder $builder->getData();
  20.         $isUnlocked false;
  21.         if($contractOrder->getDestination() instanceof Destination) {
  22.             $isUnlocked $this->contractOrderService->canOrderFullDestination($contractOrder->getDestination());
  23.         }
  24.         $transferChoices = [
  25.             'Autokar CK' => 'bus',
  26.             'Vlastní' => 'car',
  27.         ];
  28.         if($contractOrder->getTerm()->getOnlyBus() && !$isUnlocked) {
  29.             $transferChoices = [
  30.                 'Autokar CK' => 'bus',
  31.             ];
  32.         }
  33.         if($contractOrder->getTerm()->getOnlyCar() && !$isUnlocked) {
  34.             $transferChoices = [
  35.                 'Vlastní' => 'car',
  36.             ];
  37.         }
  38.         $builder
  39.             ->add('transferType'ChoiceType::class, [
  40.                 'label' => 'Typ dopravy',
  41.                 'choices' => $transferChoices,
  42.             ])
  43. //            ->add('cateringType', null, ['label' => 'Typ stravování'])
  44.             ->add('boardingPlace'ChoiceType::class, ['label' => 'Nástupní místo',
  45.                 'choices' => [
  46.                     'Ústí nad Labem' => 'Ústí nad Labem',
  47.                     'Brno' => 'Brno',
  48.                     'Praha' => 'Praha',
  49.                     'Ostatní po dohodě v CK' => 'Ostatní po dohodě v CK',
  50.                 ]])
  51.             ->add('note'null, ['label' => 'Poznámka'])
  52.             ->add('client'ClientType::class, ['label' => 'Klient'])
  53.             ->add('returningClient'CheckboxType::class, [ 'required'=>false'label' => 'Cestovali jste s námi?'])
  54.             ->add('withPet'CheckboxType::class, ['required'=>false,'label' => 'Domácí mazlíček?'])
  55.             ->add('firstMinute'CheckboxType::class, ['required'=>false,'label' => 'Zavazuji se, že uhradím do konce ledna 50% zálohu'])
  56.             ->add('gdpr'CheckboxType::class, ['mapped' => false'required' => true'label' => 'Souhlasím se zpracováním osobních údajů']);
  57.         if(!empty($contractOrder->getDestination()->getDietPrice())) {
  58.             $builder->add('withDiet'CheckboxType::class, ['required'=>true,'label' => sprintf('Potvrzuji poplatek za stravování %s Kč na osobu'$contractOrder->getDestination()->getDietPrice())]);
  59.         }
  60.     }
  61.     public function configureOptions(OptionsResolver $resolver): void
  62.     {
  63.         $resolver->setDefaults([
  64.             'data_class' => ContractOrder::class,
  65.         ]);
  66.     }
  67. }