<?php
namespace App\Form;
use App\Dictionary\ReviewTypeForm;
use App\Entity\ReviewComment;
use App\Repository\ReviewServiceAreaRepository;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
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\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Validator\Constraints\Email;
use Symfony\Component\Validator\Constraints\Length;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Constraints\NotNull;
/**
* Formularz zapisu opinii
*
* @package App\Form
*/
class ReviewType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('signature', TextType::class, array(
'label' => 'Podpis, czyli kto dodaje opinię',
'required' => true,
'constraints' => [
new NotBlank([
'message' => 'To pole nie może być puste'
]),
new Length([
'min' => 3,
'max' => 50,
'minMessage' => 'Minimalna liczba znaków wynosi 3',
'maxMessage' => 'Maksymalna liczna znaków wynosi 50'
])
],
'attr' =>
array(
'maxlength' => 50,
'placeholder' => 'np. imię i nazwisko',
'class' => 'form-control'
)
))
->add('photo_author', TextType::class, array(
'label' => 'Autor fotografii',
'required' => false,
'constraints' => [
new Length([
'max' => 250,
'maxMessage' => 'Maksymalna liczna znaków wynosi 250'
])
],
'attr' =>
array(
'maxlength' => 250,
'placeholder' => 'np. imię i nazwisko lub link do strony www',
'class' => 'form-control'
)
))
->add('person', EntityType::class, array(
'class' => 'App\Entity\ReviewCommentAuthorDictionary',
'label' => 'Kim jesteś?',
'choice_label' => 'name',
'required' => true,
'constraints' => [
new NotBlank([
'message' => 'To pole nie może być puste'
])
],
'attr' =>
array(
'class' => 'form-control'
)
))
->add('email', EmailType::class, array(
'label' => 'Twój adres e-mail',
'required' => false,
'constraints' => [
new NotBlank([
'message' => 'To pole nie może być puste'
]),
new Email([
'message' => 'Niepoprawny adres e-mail'
])
],
'attr' =>
array(
'maxlength' => 150,
'placeholder' => 'Email',
'class' => 'form-control'
)
))
->add('description', TextareaType::class, array(
'label' => false,
'required' => true,
'constraints' => [
new NotBlank([
'message' => 'To pole nie może być puste'
]),
new Length([
'min' => 10,
'max' => 5000,
'minMessage' => 'Minimalna liczba znaków wynosi 10',
'maxMessage' => 'Maksymalna liczna znaków wynosi 5000'
])
],
'attr' =>
array(
'maxlength' => 5000,
'class' => 'textarea-full form-control',
'rows' => 6,
'placeholder' => 'Podziel się wrażeniami! Twoja opinia może pomóc innym parom wybrać tego wystawcę.'
)
))
->add('price', TextType::class, array(
'label' => 'Jaki był koszt wykonania zlecenia?',
'required' => false,
'attr' =>
array(
'placeholder' => '0,00 zł',
'maxlength' => 9,
'class' => 'form-control'
)
))
->add('portal', ChoiceType::class, array(
'label' => 'Czy skorzystałeś z naszego portalu, aby wybrać tego wystawcę?',
'required' => true,
'choices' => [
'Tak' => 'T',
'Nie' => 'N'
],
'multiple' => false,
'expanded' => true,
'data' => 'N',
'attr' =>
array(
'class' => 'form-check-input'
)
))
->add('service', EntityType::class, array(
'class' => 'App\Entity\ReviewServiceArea',
'label' => 'Usługi świadczone przez wystawcę',
'choice_label' => function ($serviceName) {
return $serviceName->getService()->getName();
},
'expanded' => true,
'multiple' => true,
'required' => false,
'query_builder' => function (ReviewServiceAreaRepository $repository) use ($options) {
return $repository->getAllActiveService($options['data']['areaId']);
}
))
/** START : OCENY W FORMIE GWIAZDEK */
->add('stars_quality', ChoiceType::class, array(
'label' => 'Jakość usługi',
'constraints' => [
new NotNull([
'message' => 'Ocena nie jest liczbą'
])
],
'required' => false,
'choices' => ReviewTypeForm::STARS_CHOICES
))
->add('stars_professional', ChoiceType::class, array(
'label' => 'Profesjonalizm',
'constraints' => [
new NotNull([
'message' => 'Ocena nie jest liczbą'
])
],
'required' => false,
'choices' => ReviewTypeForm::STARS_CHOICES
))
->add('stars_flexibility', ChoiceType::class, array(
'label' => 'Elastyczność',
'constraints' => [
new NotNull([
'message' => 'Ocena nie jest liczbą'
])
],
'required' => false,
'choices' => ReviewTypeForm::STARS_CHOICES
))
->add('stars_price', ChoiceType::class, array(
'label' => 'Cena',
'constraints' => [
new NotNull([
'message' => 'Ocena nie jest liczbą'
])
],
'required' => false,
'choices' => ReviewTypeForm::STARS_CHOICES
))
->add('stars_cooperation', ChoiceType::class, array(
'label' => 'Współpraca',
'constraints' => [
new NotNull([
'message' => 'Ocena nie jest liczbą'
])
],
'required' => false,
'choices' => ReviewTypeForm::STARS_CHOICES
))
/** STOP : OCENY W FORMIE GWIAZDEK */
->add('offerId', HiddenType::class, array(
'data' => $options['data']['offerId'],
'required' => true,
'constraints' => [
new NotBlank([
'message' => 'Błąd podczas przesyłu formularza.'
])
]
))
->add('condition_regulations', CheckboxType::class, array(
'label' => "Przesyłając tę opinię, akceptuję Regulamin oraz Warunki dodawania opinii i potwierdzam, żę prowadziłam/em inteeresy z tym Wystawcą lub miałam/em styczność z jego usługami lub produktami",
'required' => true,
'attr' =>
array(
'class' => 'form-control'
)
))
// ->add('save', SubmitType::class, array('label' => 'Create Post'))
;
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
// 'data_class' => ReviewComment::class
));
// $resolver->setRequired('offerId');
}
}