<?php
namespace App\Form;
use App\Entity\Claim;
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\CollectionType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\FileType;
use Symfony\Component\Form\Extension\Core\Type\NumberType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Constraints\File;
class ClaimSachType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('department', null, [
'label' => 'Dienststelle',
'required' => true,
'constraints' => [
new Assert\NotBlank(),
],
])
->add('claimDate', null, [
'label' => 'Wann hat sich das Schadenereignis zugetragen?',
'required' => false,
'years' => range(date('Y'), date('Y')-5),
])
->add('claimAddress', AddressBlockType::class, [
'label' => "Schadenort",
'required' => true,
'constraints' => [
new Assert\NotBlank(),
],
])
->add('claimDescription', null, [
'label' => "Schadenshergang",
'required' => true,
'constraints' => [
new Assert\NotBlank(),
],
])
->add('damageCosts', NumberType::class, [
'scale' => 2,
'label' => "Schadensumme",
'required' => false,
'html5' => true,
'constraints' => [
new Assert\Range([
'min' => 0,
'max' => 9999999999999.99,
]),
],
])
->add('sachOwner', NameAddressBlockType::class, [
'label' => "Wer ist der Eigentümer?",
'required' => true,
'constraints' => [
new Assert\NotBlank(),
],
])
->add('damageBy', NameAddressBlockType::class, [
'label' => "Wer hat den Schaden verursacht?",
'required' => false,
'constraints' => [
new Assert\NotBlank(),
],
])
->add('policeReport', null, [
'label' => "Schaden gemeldet bei (Polizei, Feuerwehr, ...)",
'required' => true,
])
->add('policeReportDate', null, [
'label' => "Datum der Anzeige",
'required' => true,
])
->add('persons', CollectionType::class, [
'label' => false,
'entry_type' => PersonType::class,
'entry_options' => [],
'allow_add' => true,
'allow_delete' => true,
'by_reference' => false,
'prototype' => true,
'prototype_name' => '__item__',
])
->add('remark', null, [
'label' => "Beschädigte Sachen / Weitere Angaben / Bemerkungen",
'required' => false,
])
->add('name', null, [
'label' => false,
'required' => true,
'constraints' => [
new Assert\NotBlank(),
],
'attr' => [
'placeholder' => 'Name',
],
])
->add('email', EmailType::class, [
'label' => false,
'required' => true,
'constraints' => [
new Assert\NotBlank(),
new Assert\Email(),
],
'attr' => [
'placeholder' => 'Email',
],
])
->add('ccEmail', EmailType::class, [
'label' => false,
'required' => false,
'constraints' => [
new Assert\Email(),
],
'attr' => [
'placeholder' => 'CC Email',
],
])
->add('claimFiles', FileType::class,[
'label' => 'Dateien',
'data_class' => null,
'required' => false,
'multiple' => true,
'mapped' => false,
'constraints' => [
new Assert\All([
new File(['maxSize' => '100m'])
])
]
])
->add('submit', SubmitType::class, [
'label' => 'Senden',
'attr' => [
'class' => 'btn btn-primary',
],
])
;
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => Claim::class,
]);
}
}