src/App/Form/WantedJobsSearchParametersType.php line 21

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use App\Entity\Profile\JobseekerProfile;
  4. use App\Entity\WantedJob;
  5. use App\Entity\WantedJobsSearch\WantedJobsSearchParameters;
  6. use App\Service\LocationService;
  7. use App\Value\PossibleAvailabilitiesValue;
  8. use App\Value\ZipcodeRadiusesValue;
  9. use Symfony\Component\Form\AbstractType;
  10. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  11. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  12. use Symfony\Component\Form\Extension\Core\Type\HiddenType;
  13. use Symfony\Component\Form\Extension\Core\Type\TextType;
  14. use Symfony\Component\Form\FormBuilderInterface;
  15. use Symfony\Component\Form\FormEvent;
  16. use Symfony\Component\Form\FormEvents;
  17. use Symfony\Component\OptionsResolver\OptionsResolver;
  18. class WantedJobsSearchParametersType extends AbstractType
  19. {
  20. private LocationService $locationService;
  21. public function __construct(LocationService $locationService)
  22. {
  23. $this->locationService = $locationService;
  24. }
  25. public function buildForm(FormBuilderInterface $builder, array $options)
  26. {
  27. $builder->add(
  28. 'filterSearchterm',
  29. TextType::class,
  30. [
  31. 'label' => 'recurrent_jobs.new_page.occupational_field_searchterm_intro'
  32. ]
  33. );
  34. $builder->add(
  35. 'filterZipcodeRadius',
  36. ChoiceType::class,
  37. [
  38. 'choices' => array_flip(ZipcodeRadiusesValue::ALL_ASSOCIATIVE),
  39. 'choice_label' => function (int $number): string {
  40. return $number . 'km';
  41. },
  42. 'label' => '',
  43. 'data' => ZipcodeRadiusesValue::DEFAULT
  44. ]
  45. );
  46. $builder->add(
  47. 'filterZipcode',
  48. TextType::class,
  49. [
  50. 'label' => 'wanted_jobs_search.form_page.zipcode_label'
  51. ]
  52. );
  53. $builder->add(
  54. 'filterAlreadyContacted',
  55. CheckboxType::class,
  56. [
  57. 'label' => 'wanted_jobs.new_page.already_contacted',
  58. 'required' => false,
  59. 'data' => true
  60. ]
  61. );
  62. $builder->add(
  63. 'filterRequiredCareerLevels',
  64. ChoiceType::class,
  65. [
  66. 'required' => false,
  67. 'expanded' => true,
  68. 'multiple' => true,
  69. 'choices' => WantedJob::POSSIBLE_CAREER_LEVEL_AVAILABLE_FOR_SELECTION_WITH_TRANSLATION_MAPPING,
  70. 'data' => WantedJob::POSSIBLE_CAREER_LEVEL_AVAILABLE_FOR_SELECTION_WITH_TRANSLATION_MAPPING
  71. ]
  72. );
  73. $builder->add(
  74. 'filterRequiredEmploymentTypes',
  75. ChoiceType::class,
  76. [
  77. 'required' => false,
  78. 'expanded' => true,
  79. 'multiple' => true,
  80. 'choices' => WantedJob::POSSIBLE_EMPLOYMENT_TYPE_AVAILABLE_FOR_SELECTION_WITH_TRANSLATION_MAPPING,
  81. 'data' => WantedJob::POSSIBLE_EMPLOYMENT_TYPE_AVAILABLE_FOR_SELECTION_WITH_TRANSLATION_MAPPING
  82. ]
  83. );
  84. $builder->add(
  85. 'filterRequiredExperience',
  86. ChoiceType::class,
  87. [
  88. 'label' => 'wanted_jobs_search.form_page.experience_label',
  89. 'choices' => JobseekerProfile::POSSIBLE_EXPERIENCES_AVAILABLE_FOR_SELECTION_WITH_TRANSLATION_MAPPING,
  90. 'expanded' => true,
  91. 'multiple' => false
  92. ]
  93. );
  94. $builder->add(
  95. 'atLeastOneRequiredCareerLevelMustMatch',
  96. HiddenType::class,
  97. [
  98. 'data' => '0',
  99. 'empty_data' => '0'
  100. ]
  101. );
  102. $builder->add(
  103. 'atLeastOneRequiredEmploymentTypeMustMatch',
  104. HiddenType::class,
  105. [
  106. 'data' => '0',
  107. 'empty_data' => '0'
  108. ]
  109. );
  110. foreach (PossibleAvailabilitiesValue::WEEKDAYS as $weekday) {
  111. foreach (PossibleAvailabilitiesValue::TIMES_OF_DAY as $timeOfDay) {
  112. $builder->add(
  113. 'filterIsRequiredOn' . $weekday . $timeOfDay,
  114. CheckboxType::class,
  115. [
  116. 'required' => false,
  117. 'label' => false
  118. ]
  119. );
  120. }
  121. }
  122. $builder->addEventListener(FormEvents::PRE_SUBMIT, [$this, 'onPreSubmit']);
  123. }
  124. public function configureOptions(OptionsResolver $resolver)
  125. {
  126. $resolver->setDefaults([
  127. 'data_class' => WantedJobsSearchParameters::class,
  128. 'csrf_protection' => false,
  129. ]);
  130. }
  131. public function onPreSubmit(FormEvent $event)
  132. {
  133. $this->locationService->normalizeZipcode($event, 'filterZipcode');
  134. }
  135. }