src/Form/ReviewType.php line 160

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use App\Dictionary\ReviewTypeForm;
  4. use App\Entity\ReviewComment;
  5. use App\Repository\ReviewServiceAreaRepository;
  6. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  7. use Symfony\Component\Form\AbstractType;
  8. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  9. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  10. use Symfony\Component\Form\Extension\Core\Type\HiddenType;
  11. use Symfony\Component\Form\Extension\Core\Type\TextType;
  12. use Symfony\Component\Form\FormBuilderInterface;
  13. use Symfony\Component\OptionsResolver\OptionsResolver;
  14. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  15. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  16. use Symfony\Component\Validator\Constraints\Email;
  17. use Symfony\Component\Validator\Constraints\Length;
  18. use Symfony\Component\Validator\Constraints\NotBlank;
  19. use Symfony\Component\Validator\Constraints\NotNull;
  20. /**
  21.  * Formularz zapisu opinii
  22.  *
  23.  * @package App\Form
  24.  */
  25. class ReviewType extends AbstractType
  26. {
  27.     public function buildForm(FormBuilderInterface $builder, array $options)
  28.     {
  29.         $builder
  30.             ->add('signature'TextType::class, array(
  31.                 'label' => 'Podpis, czyli kto dodaje opinię',
  32.                 'required' => true,
  33.                 'constraints' => [
  34.                     new NotBlank([
  35.                         'message' => 'To pole nie może być puste'
  36.                     ]),
  37.                     new Length([
  38.                         'min' => 3,
  39.                         'max' => 50,
  40.                         'minMessage' => 'Minimalna liczba znaków wynosi 3',
  41.                         'maxMessage' => 'Maksymalna liczna znaków wynosi 50'
  42.                     ])
  43.                 ],
  44.                 'attr' =>
  45.                     array(
  46.                         'maxlength' => 50,
  47.                         'placeholder' => 'np. imię i nazwisko',
  48.                         'class' => 'form-control'
  49.                     )
  50.             ))
  51.             ->add('photo_author'TextType::class, array(
  52.                 'label' => 'Autor fotografii',
  53.                 'required' => false,
  54.                 'constraints' => [
  55.                     new Length([
  56.                         'max' => 250,
  57.                         'maxMessage' => 'Maksymalna liczna znaków wynosi 250'
  58.                     ])
  59.                 ],
  60.                 'attr' =>
  61.                     array(
  62.                         'maxlength' => 250,
  63.                         'placeholder' => 'np. imię i nazwisko lub link do strony www',
  64.                         'class' => 'form-control'
  65.                     )
  66.             ))
  67.             ->add('person'EntityType::class, array(
  68.                 'class' => 'App\Entity\ReviewCommentAuthorDictionary',
  69.                 'label' => 'Kim jesteś?',
  70.                 'choice_label' => 'name',
  71.                 'required' => true,
  72.                 'constraints' => [
  73.                     new NotBlank([
  74.                         'message' => 'To pole nie może być puste'
  75.                     ])
  76.                 ],
  77.                 'attr' =>
  78.                     array(
  79.                         'class' => 'form-control'
  80.                     )
  81.             ))
  82.             ->add('email'EmailType::class, array(
  83.                 'label' => 'Twój adres e-mail',
  84.                 'required' => false,
  85.                 'constraints' => [
  86.                     new NotBlank([
  87.                         'message' => 'To pole nie może być puste'
  88.                     ]),
  89.                     new Email([
  90.                         'message' => 'Niepoprawny adres e-mail'
  91.                     ])
  92.                 ],
  93.                 'attr' =>
  94.                     array(
  95.                         'maxlength' => 150,
  96.                         'placeholder' => 'Email',
  97.                         'class' => 'form-control'
  98.                     )
  99.             ))
  100.             ->add('description'TextareaType::class, array(
  101.                 'label' => false,
  102.                 'required' => true,
  103.                 'constraints' => [
  104.                     new NotBlank([
  105.                         'message' => 'To pole nie może być puste'
  106.                     ]),
  107.                     new Length([
  108.                         'min' => 10,
  109.                         'max' => 5000,
  110.                         'minMessage' => 'Minimalna liczba znaków wynosi 10',
  111.                         'maxMessage' => 'Maksymalna liczna znaków wynosi 5000'
  112.                     ])
  113.                 ],
  114.                 'attr' =>
  115.                     array(
  116.                         'maxlength' => 5000,
  117.                         'class' => 'textarea-full form-control',
  118.                         'rows' => 6,
  119.                         'placeholder' => 'Podziel się wrażeniami! Twoja opinia może pomóc innym parom wybrać tego wystawcę.'
  120.                     )
  121.             ))
  122.             ->add('price'TextType::class, array(
  123.                 'label' => 'Jaki był koszt wykonania zlecenia?',
  124.                 'required' => false,
  125.                 'attr' =>
  126.                     array(
  127.                         'placeholder' => '0,00 zł',
  128.                         'maxlength' => 9,
  129.                         'class' => 'form-control'
  130.                     )
  131.             ))
  132.             ->add('portal'ChoiceType::class, array(
  133.                 'label' => 'Czy skorzystałeś z naszego portalu, aby wybrać tego wystawcę?',
  134.                 'required' => true,
  135.                 'choices' => [
  136.                     'Tak' => 'T',
  137.                     'Nie' => 'N'
  138.                 ],
  139.                 'multiple' => false,
  140.                 'expanded' => true,
  141.                 'data' => 'N',
  142.                 'attr' =>
  143.                     array(
  144.                         'class' => 'form-check-input'
  145.                     )
  146.             ))
  147.             ->add('service'EntityType::class, array(
  148.                 'class' => 'App\Entity\ReviewServiceArea',
  149.                 'label' => 'Usługi świadczone przez wystawcę',
  150.                 'choice_label' => function ($serviceName) {
  151.                     return $serviceName->getService()->getName();
  152.                 },
  153.                 'expanded' => true,
  154.                 'multiple' => true,
  155.                 'required' => false,
  156.                 'query_builder' => function (ReviewServiceAreaRepository $repository) use ($options) {
  157.                     return $repository->getAllActiveService($options['data']['areaId']);
  158.                 }
  159.             ))
  160.             /** START : OCENY W FORMIE GWIAZDEK */
  161.             ->add('stars_quality'ChoiceType::class, array(
  162.                 'label' => 'Jakość usługi',
  163.                 'constraints' => [
  164.                     new NotNull([
  165.                         'message' => 'Ocena nie jest liczbą'
  166.                     ])
  167.                 ],
  168.                 'required' => false,
  169.                 'choices' => ReviewTypeForm::STARS_CHOICES
  170.             ))
  171.             ->add('stars_professional'ChoiceType::class, array(
  172.                 'label' => 'Profesjonalizm',
  173.                 'constraints' => [
  174.                     new NotNull([
  175.                         'message' => 'Ocena nie jest liczbą'
  176.                     ])
  177.                 ],
  178.                 'required' => false,
  179.                 'choices' => ReviewTypeForm::STARS_CHOICES
  180.             ))
  181.             ->add('stars_flexibility'ChoiceType::class, array(
  182.                 'label' => 'Elastyczność',
  183.                 'constraints' => [
  184.                     new NotNull([
  185.                         'message' => 'Ocena nie jest liczbą'
  186.                     ])
  187.                 ],
  188.                 'required' => false,
  189.                 'choices' => ReviewTypeForm::STARS_CHOICES
  190.             ))
  191.             ->add('stars_price'ChoiceType::class, array(
  192.                 'label' => 'Cena',
  193.                 'constraints' => [
  194.                     new NotNull([
  195.                         'message' => 'Ocena nie jest liczbą'
  196.                     ])
  197.                 ],
  198.                 'required' => false,
  199.                 'choices' => ReviewTypeForm::STARS_CHOICES
  200.             ))
  201.             ->add('stars_cooperation'ChoiceType::class, array(
  202.                 'label' => 'Współpraca',
  203.                 'constraints' => [
  204.                     new NotNull([
  205.                         'message' => 'Ocena nie jest liczbą'
  206.                     ])
  207.                 ],
  208.                 'required' => false,
  209.                 'choices' => ReviewTypeForm::STARS_CHOICES
  210.             ))
  211.             /** STOP : OCENY W FORMIE GWIAZDEK */
  212.             ->add('offerId'HiddenType::class, array(
  213.                 'data' => $options['data']['offerId'],
  214.                 'required' => true,
  215.                 'constraints' => [
  216.                     new NotBlank([
  217.                         'message' => 'Błąd podczas przesyłu formularza.'
  218.                     ])
  219.                 ]
  220.             ))
  221.             ->add('condition_regulations'CheckboxType::class, array(
  222.                 '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",
  223.                 'required' => true,
  224.                 'attr' =>
  225.                     array(
  226.                         'class' => 'form-control'
  227.                     )
  228.             ))
  229. //            ->add('save', SubmitType::class, array('label' => 'Create Post'))
  230.         ;
  231.     }
  232.     public function configureOptions(OptionsResolver $resolver)
  233.     {
  234.         $resolver->setDefaults(array(
  235. //            'data_class' => ReviewComment::class
  236.         ));
  237. //        $resolver->setRequired('offerId');
  238.     }
  239. }