<?php
namespace App\Form;
use App\Entity\Demand;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
use Symfony\Component\Form\Extension\Core\Type\TelType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class CalculatorType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
switch ($options['flow_step']) {
case 1:
$builder->add('place', TextType::class, [
'required' => true,
'label' => 'Adresa nemovitosti',
'attr' => [
'class' => 'form-control',
'placeholder' => 'Zadejte adresu',
],
])
->add('floor_area', IntegerType::class, [
'required' => true,
'label' => 'Podlahová plocha v m²',
'attr' => [
'class' => 'form-control',
'placeholder' => '0',
'data-input-type' => 'int',
'min' => 0,
],
])
->add('kind', ChoiceType::class, [
'required' => true,
'label' => 'Prodej nebo pronájem',
'expanded' => true,
'choices' => array_flip(Demand::KIND_CHOICES),
'attr' => [
'class' => 'form-control',
],
]);
if ($options['property_type'] !== Demand::PROPERTY_TYPE_HOUSE) {
$builder
->add('ownership', ChoiceType::class, [
'required' => false,
'label' => 'Vlastnictví',
'placeholder' => false,
'expanded' => true,
'choices' => array_flip(Demand::OWNERSHIP_CHOICES),
'attr' => [
'class' => 'form-control',
],
]);
}
$builder
->add('local_type', ChoiceType::class, [
'required' => false,
'label' => 'Dispozice',
'placeholder' => false,
'expanded' => true,
'choices' => array_flip(Demand::LOCAL_TYPE_CHOICES),
'attr' => [
'class' => 'form-control',
],
])
->add('property_type', ChoiceType::class, [
'required' => true,
'label' => 'Druh nemovitosti',
'expanded' => true,
'choices' => array_flip(Demand::PROPERTY_TYPE_CHOICES),
'attr' => [
'class' => 'form-control',
],
])
->add('house_type', ChoiceType::class, [
'required' => false,
'label' => 'Druh domu',
'expanded' => true,
'choices' => array_flip(Demand::HOUSE_TYPE_CHOICES),
'attr' => [
'class' => 'form-control',
],
'placeholder' => false,
])
->add('rating', ChoiceType::class, [
'required' => true,
'label' => 'Stav nemovitosti',
'expanded' => true,
'choices' => array_flip(Demand::RATING_CHOICES),
'attr' => [
'class' => 'form-control',
],
])
->add('isSkipped', CheckboxType::class, [
'required' => false,
'attr' => [
'hidden' => true,
],
])
->add('garages', IntegerType::class, [
'required' => true,
'label' => 'Počet garáží',
'data' => 0,
'attr' => [
'class' => 'form-control',
'placeholder' => '0',
'data-input-type' => 'int',
'min' => 0,
],
])
->add('parking_spaces', IntegerType::class, [
'required' => true,
'label' => 'Počet parkovacích míst',
'data' => 0,
'attr' => [
'class' => 'form-control',
'placeholder' => '0',
'data-input-type' => 'int',
'min' => 0,
],
])
->add('balcony_area', IntegerType::class, [
'required' => true,
'label' => 'Balkón v m²',
'data' => 0,
'attr' => [
'class' => 'form-control',
'placeholder' => '0',
'data-input-type' => 'int',
'min' => 0,
],
])
->add('garden_area', IntegerType::class, [
'required' => true,
'label' => 'Plocha pozemku v m²',
'data' => 0,
'attr' => [
'class' => 'form-control',
'placeholder' => '0',
'data-input-type' => 'int',
'min' => 0,
],
])
->add('other_area', IntegerType::class, [
'required' => false,
'data' => 0,
'label' => 'Jiné v m²',
'attr' => [
'class' => 'form-control',
'placeholder' => '0',
'data-input-type' => 'int',
'min' => 0,
],
])
->add('coordinates', HiddenType::class, [
'required' => false,
]);
break;
case 2:
if ($options['property_type'] === Demand::PROPERTY_TYPE_HOUSE) {
$builder
->add('local_type', ChoiceType::class, [
'required' => false,
'label' => 'Dispozice',
'placeholder' => false,
'expanded' => true,
'choices' => array_flip(Demand::LOCAL_TYPE_CHOICES),
'attr' => [
'class' => 'form-control',
],
]);
}
$builder
->add('construction', ChoiceType::class, [
'required' => false,
'label' => 'Materiál konstrukce',
'placeholder' => false,
'expanded' => true,
'choices' => array_flip(Demand::CONSTRUCTION_CHOICES),
'attr' => [
'class' => 'form-control',
],
]);
if ($options['property_type'] !== Demand::PROPERTY_TYPE_HOUSE) {
$builder
->add('lift', CheckboxType::class, [
'required' => false,
'label' => 'Výtah',
'attr' => [
'class' => 'form-check-input',
],
])
->add('floor', IntegerType::class, [
'required' => false,
'label' => 'Patro',
'data' => 0,
'attr' => [
'class' => 'form-control',
],
])
->add('total_floors', IntegerType::class, [
'required' => false,
'label' => 'Celkem pater',
'data' => 1,
'attr' => [
'class' => 'form-control',
],
]);
}
break;
case 3:
$builder->add('name', TextType::class, [
'required' => true,
'label' => 'Jméno a příjmení',
'attr' => [
'class' => 'form-control',
'placeholder' => 'Jméno a příjmení',
'data-input-type' => 'name',
],
])
->add('email', EmailType::class, [
'required' => true,
'label' => 'Email',
'attr' => [
'class' => 'form-control',
'placeholder' => 'Email',
'data-input-type' => 'email',
],
])
->add('phone', TelType::class, [
'required' => true,
'label' => 'Telefon',
'attr' => [
'class' => 'form-control',
'placeholder' => 'Telefon',
'data-input-type' => 'phone',
],
])
->add('gdpr', CheckboxType::class, [
'mapped' => false,
'required' => true,
'attr' => [
'class' => 'form-control',
],
]);
break;
}
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'property_type' => null,
]);
}
}