src/Form/CalculatorType.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use App\Entity\Demand;
  4. use Symfony\Component\Form\AbstractType;
  5. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  6. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  7. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  8. use Symfony\Component\Form\Extension\Core\Type\HiddenType;
  9. use Symfony\Component\Form\Extension\Core\Type\IntegerType;
  10. use Symfony\Component\Form\Extension\Core\Type\TelType;
  11. use Symfony\Component\Form\Extension\Core\Type\TextType;
  12. use Symfony\Component\Form\FormBuilderInterface;
  13. use Symfony\Component\OptionsResolver\OptionsResolver;
  14. class CalculatorType extends AbstractType
  15. {
  16.     public function buildForm(FormBuilderInterface $builder, array $options): void
  17.     {
  18.         switch ($options['flow_step']) {
  19.             case 1:
  20.                 $builder->add('place'TextType::class, [
  21.                     'required' => true,
  22.                     'label' => 'Adresa nemovitosti',
  23.                     'attr' => [
  24.                         'class' => 'form-control',
  25.                         'placeholder' => 'Zadejte adresu',
  26.                     ],
  27.                 ])
  28.                 ->add('floor_area'IntegerType::class, [
  29.                     'required' => true,
  30.                     'label' => 'Podlahová plocha v m²',
  31.                     'attr' => [
  32.                         'class' => 'form-control',
  33.                         'placeholder' => '0',
  34.                         'data-input-type' => 'int',
  35.                         'min' => 0,
  36.                     ],
  37.                 ])
  38.                 ->add('kind'ChoiceType::class, [
  39.                     'required' => true,
  40.                     'label' => 'Prodej nebo pronájem',
  41.                     'expanded' => true,
  42.                     'choices' => array_flip(Demand::KIND_CHOICES),
  43.                     'attr' => [
  44.                         'class' => 'form-control',
  45.                     ],
  46.                 ]);
  47.                 if ($options['property_type'] !== Demand::PROPERTY_TYPE_HOUSE) {
  48.                     $builder
  49.                         ->add('ownership'ChoiceType::class, [
  50.                             'required' => false,
  51.                             'label' => 'Vlastnictví',
  52.                             'placeholder' => false,
  53.                             'expanded' => true,
  54.                             'choices' => array_flip(Demand::OWNERSHIP_CHOICES),
  55.                             'attr' => [
  56.                                 'class' => 'form-control',
  57.                             ],
  58.                         ]);
  59.                 }
  60.                 $builder
  61.                 ->add('local_type'ChoiceType::class, [
  62.                     'required' => false,
  63.                     'label' => 'Dispozice',
  64.                     'placeholder' => false,
  65.                     'expanded' => true,
  66.                     'choices' => array_flip(Demand::LOCAL_TYPE_CHOICES),
  67.                     'attr' => [
  68.                         'class' => 'form-control',
  69.                     ],
  70.                 ])
  71.                 ->add('property_type'ChoiceType::class, [
  72.                     'required' => true,
  73.                     'label' => 'Druh nemovitosti',
  74.                     'expanded' => true,
  75.                     'choices' => array_flip(Demand::PROPERTY_TYPE_CHOICES),
  76.                     'attr' => [
  77.                         'class' => 'form-control',
  78.                     ],
  79.                 ])
  80.                 ->add('house_type'ChoiceType::class, [
  81.                     'required' => false,
  82.                     'label' => 'Druh domu',
  83.                     'expanded' => true,
  84.                     'choices' => array_flip(Demand::HOUSE_TYPE_CHOICES),
  85.                     'attr' => [
  86.                         'class' => 'form-control',
  87.                     ],
  88.                     'placeholder' => false,
  89.                 ])
  90.                 ->add('rating'ChoiceType::class, [
  91.                     'required' => true,
  92.                     'label' => 'Stav nemovitosti',
  93.                     'expanded' => true,
  94.                     'choices' => array_flip(Demand::RATING_CHOICES),
  95.                     'attr' => [
  96.                         'class' => 'form-control',
  97.                     ],
  98.                 ])
  99.                 ->add('isSkipped'CheckboxType::class, [
  100.                     'required' => false,
  101.                     'attr' => [
  102.                         'hidden' => true,
  103.                     ],
  104.                 ])
  105.                 ->add('garages'IntegerType::class, [
  106.                     'required' => true,
  107.                     'label' => 'Počet garáží',
  108.                     'data' => 0,
  109.                     'attr' => [
  110.                         'class' => 'form-control',
  111.                         'placeholder' => '0',
  112.                         'data-input-type' => 'int',
  113.                         'min' => 0,
  114.                     ],
  115.                 ])
  116.                 ->add('parking_spaces'IntegerType::class, [
  117.                     'required' => true,
  118.                     'label' => 'Počet parkovacích míst',
  119.                     'data' => 0,
  120.                     'attr' => [
  121.                         'class' => 'form-control',
  122.                         'placeholder' => '0',
  123.                         'data-input-type' => 'int',
  124.                         'min' => 0,
  125.                     ],
  126.                 ])
  127.                 ->add('balcony_area'IntegerType::class, [
  128.                     'required' => true,
  129.                     'label' => 'Balkón v m²',
  130.                     'data' => 0,
  131.                     'attr' => [
  132.                         'class' => 'form-control',
  133.                         'placeholder' => '0',
  134.                         'data-input-type' => 'int',
  135.                         'min' => 0,
  136.                     ],
  137.                 ])
  138.                 ->add('garden_area'IntegerType::class, [
  139.                     'required' => true,
  140.                     'label' => 'Plocha pozemku v m²',
  141.                     'data' => 0,
  142.                     'attr' => [
  143.                         'class' => 'form-control',
  144.                         'placeholder' => '0',
  145.                         'data-input-type' => 'int',
  146.                         'min' => 0,
  147.                     ],
  148.                 ])
  149.                 ->add('other_area'IntegerType::class, [
  150.                     'required' => false,
  151.                     'data' => 0,
  152.                     'label' => 'Jiné v m²',
  153.                     'attr' => [
  154.                         'class' => 'form-control',
  155.                         'placeholder' => '0',
  156.                         'data-input-type' => 'int',
  157.                         'min' => 0,
  158.                     ],
  159.                 ])
  160.                 ->add('coordinates'HiddenType::class, [
  161.                     'required' => false,
  162.                 ]);
  163.                 break;
  164.             case 2:
  165.                 if ($options['property_type'] === Demand::PROPERTY_TYPE_HOUSE) {
  166.                     $builder
  167.                         ->add('local_type'ChoiceType::class, [
  168.                             'required' => false,
  169.                             'label' => 'Dispozice',
  170.                             'placeholder' => false,
  171.                             'expanded' => true,
  172.                             'choices' => array_flip(Demand::LOCAL_TYPE_CHOICES),
  173.                             'attr' => [
  174.                                 'class' => 'form-control',
  175.                             ],
  176.                         ]);
  177.                 }
  178.                 $builder
  179.                 ->add('construction'ChoiceType::class, [
  180.                     'required' => false,
  181.                     'label' => 'Materiál konstrukce',
  182.                     'placeholder' => false,
  183.                     'expanded' => true,
  184.                     'choices' => array_flip(Demand::CONSTRUCTION_CHOICES),
  185.                     'attr' => [
  186.                         'class' => 'form-control',
  187.                     ],
  188.                 ]);
  189.                 if ($options['property_type'] !== Demand::PROPERTY_TYPE_HOUSE) {
  190.                     $builder
  191.                         ->add('lift'CheckboxType::class, [
  192.                             'required' => false,
  193.                             'label' => 'Výtah',
  194.                             'attr' => [
  195.                                 'class' => 'form-check-input',
  196.                             ],
  197.                         ])
  198.                         ->add('floor'IntegerType::class, [
  199.                             'required' => false,
  200.                             'label' => 'Patro',
  201.                             'data' => 0,
  202.                             'attr' => [
  203.                                 'class' => 'form-control',
  204.                             ],
  205.                         ])
  206.                         ->add('total_floors'IntegerType::class, [
  207.                             'required' => false,
  208.                             'label' => 'Celkem pater',
  209.                             'data' => 1,
  210.                             'attr' => [
  211.                                 'class' => 'form-control',
  212.                             ],
  213.                         ]);
  214.                 }
  215.                 break;
  216.             case 3:
  217.                 $builder->add('name'TextType::class, [
  218.                     'required' => true,
  219.                     'label' => 'Jméno a příjmení',
  220.                     'attr' => [
  221.                         'class' => 'form-control',
  222.                         'placeholder' => 'Jméno a příjmení',
  223.                         'data-input-type' => 'name',
  224.                     ],
  225.                 ])
  226.                 ->add('email'EmailType::class, [
  227.                     'required' => true,
  228.                     'label' => 'Email',
  229.                     'attr' => [
  230.                         'class' => 'form-control',
  231.                         'placeholder' => 'Email',
  232.                         'data-input-type' => 'email',
  233.                     ],
  234.                 ])
  235.                 ->add('phone'TelType::class, [
  236.                     'required' => true,
  237.                     'label' => 'Telefon',
  238.                     'attr' => [
  239.                         'class' => 'form-control',
  240.                         'placeholder' => 'Telefon',
  241.                         'data-input-type' => 'phone',
  242.                     ],
  243.                 ])
  244.                 ->add('gdpr'CheckboxType::class, [
  245.                     'mapped' => false,
  246.                     'required' => true,
  247.                     'attr' => [
  248.                         'class' => 'form-control',
  249.                     ],
  250.                 ]);
  251.                 break;
  252.         }
  253.     }
  254.     public function configureOptions(OptionsResolver $resolver)
  255.     {
  256.         $resolver->setDefaults([
  257.             'property_type' => null,
  258.         ]);
  259.     }
  260. }