src/Form/GuardianRegister/GuardianRegisterType.php line 130

Open in your IDE?
  1. <?php
  2. namespace App\Form\GuardianRegister;
  3. use App\Entity\GuardianContract;
  4. use App\Entity\GuardianRegister\GuardianRegister;
  5. use App\Entity\GuardianRegister\GuardianRegisterChild;
  6. use App\Entity\GuardianRegister\GuardianRegisterChildPreference;
  7. use App\Entity\Lesson;
  8. use App\Repository\GuardianContractRepository;
  9. use App\Service\PriceIncreaseService;
  10. use App\Utils\HelperUtils;
  11. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  12. use Symfony\Component\Form\AbstractType;
  13. use Symfony\Component\Form\ChoiceList\ChoiceList;
  14. use Symfony\Component\Form\Extension\Core\Type\ButtonType;
  15. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  16. use Symfony\Component\Form\Extension\Core\Type\CollectionType;
  17. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  18. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  19. use Symfony\Component\Form\FormBuilderInterface;
  20. use Symfony\Component\OptionsResolver\OptionsResolver;
  21. class GuardianRegisterType extends AbstractType
  22. {
  23. private PriceIncreaseService $priceIncreaseService;
  24. public function __construct(PriceIncreaseService $priceIncreaseService)
  25. {
  26. $this->priceIncreaseService = $priceIncreaseService;
  27. }
  28. public function buildForm(FormBuilderInterface $builder, array $options)
  29. {
  30. /** @var GuardianRegister $guardianRegister */
  31. $guardianRegister = $options['data'];
  32. $phone = $guardianRegister->getPhone();
  33. $countryCode = 'LT';
  34. $countryChoices = [];
  35. $countryChoicesAttr = [];
  36. $countryData = HelperUtils::countryData(1);
  37. foreach ($countryData as $countryDatum)
  38. {
  39. $countryChoices["{$countryDatum['country']} {$countryDatum['dialCode']}"] = "{$countryDatum['code']}";
  40. $countryChoicesAttr["{$countryDatum['country']} {$countryDatum['dialCode']}"] = [
  41. 'data-dialcode' => "{$countryDatum['dialCode']}",
  42. 'data-digits' => "{$countryDatum['digits']}",
  43. 'data-size' => "{$countryDatum['size']}",
  44. ];
  45. if(strpos($phone, $countryDatum['dialCode']) !== false)
  46. {
  47. $countryCode = $countryDatum['code'];
  48. }
  49. }
  50. $builder
  51. ->add('isGuardian', null, ['label' => 'forms.labels.isGuardian'])
  52. ->add('sign', null, ['label' => 'guardian_register.sign'])
  53. ->add('currentGuardianFoundBy', ChoiceType::class,
  54. [
  55. 'choices' => [
  56. 'EMAIL' => 'EMAIL',
  57. 'TEL' => 'TEL',
  58. 'EMAIL&TEL' => 'EMAIL&TEL',
  59. ],
  60. 'label' => 'forms.labels.currentGuardianFoundBy',
  61. 'disabled' => true,
  62. 'required' => false,
  63. ]
  64. )
  65. // ->add('change', SubmitType::class, ['label' => 'forms.labels.change'])
  66. ->add('comment', null, ['label' => 'forms.labels.comment'])
  67. ->add('recallAt', null, [
  68. 'label' => 'forms.labels.recall',
  69. 'widget' => 'single_text',
  70. 'html5' => true,
  71. ])
  72. ->add('email', EmailType::class, ['label' => 'forms.labels.email', 'required' => true])
  73. ->add('name', null, ['label' => 'forms.labels.firstname', 'required' => true])
  74. ->add('lastname', null, ['label' => 'forms.labels.lastname', 'required' => true])
  75. ->add('country', ChoiceType::class, [
  76. 'label' => 'forms.labels.country',
  77. 'required' => true,
  78. 'choices' => $countryChoices,
  79. 'choice_attr' => $countryChoicesAttr,
  80. 'mapped' => false,
  81. 'attr' => ['data-country' => $countryCode]
  82. ])
  83. ->add('phone', null, ['label' => 'forms.labels.phone', 'required' => true])
  84. ->add('guardianName', null, ['label' => 'forms.labels.guardianName'])
  85. ->add('guardianLastname', null, ['label' => 'forms.labels.guardianLastname'])
  86. ->add('guardianPhone', null, ['label' => 'forms.labels.guardianPhone'])
  87. ->add('guardianEmail', null, ['label' => 'forms.labels.guardianEmail'])
  88. ->add('status',
  89. ChoiceType::class,
  90. [
  91. 'choices' => [
  92. GuardianRegister::STATUS_NEW['text'] => GuardianRegister::STATUS_NEW['value'],
  93. GuardianRegister::STATUS_IGNORED['text'] => GuardianRegister::STATUS_IGNORED['value'],
  94. GuardianRegister::STATUS_SENT['text'] => GuardianRegister::STATUS_SENT['value'],
  95. GuardianRegister::STATUS_SLEEP['text'] => GuardianRegister::STATUS_SLEEP['value'],
  96. GuardianRegister::STATUS_DECLINED['text'] => GuardianRegister::STATUS_DECLINED['value'],
  97. GuardianRegister::STATUS_CONFIRMED['text'] => GuardianRegister::STATUS_CONFIRMED['value'],
  98. GuardianRegister::STATUS_LOST['text'] => GuardianRegister::STATUS_LOST['value'],
  99. GuardianRegister::STATUS_UNTARGETED['text'] => GuardianRegister::STATUS_UNTARGETED['value'],
  100. //extra
  101. GuardianRegister::STATUS_WAITING['text'] => GuardianRegister::STATUS_WAITING['value'],
  102. GuardianRegister::STATUS_LOST_48['text'] => GuardianRegister::STATUS_LOST_48['value'],
  103. GuardianRegister::STATUS_PAID_FIRST['text'] => GuardianRegister::STATUS_PAID_FIRST['value'],
  104. GuardianRegister::STATUS_NOT_PAID['text'] => GuardianRegister::STATUS_NOT_PAID['value'],
  105. GuardianRegister::STATUS_NOT_PAID_48['text'] => GuardianRegister::STATUS_NOT_PAID_48['value']
  106. ],
  107. 'label' => 'forms.labels.status'
  108. ])
  109. // ->add('priceChange', null, ['label' => 'guardian_register.priceChange'])
  110. ->add('guardianPriceDiscount', null, ['label' => 'guardian_register.guardianPriceDiscount', 'required' => false])
  111. ->add('referralCode', null, ['label' => 'Kodas', 'required' => false])
  112. ->add('flagTrial', null, ['label' => 'forms.labels.flagTrial'])
  113. ->add('contractToken', null, ['disabled' => true, 'required' => false])
  114. ->add('guardianContract', EntityType::class, [
  115. 'class' => GuardianContract::class,
  116. 'label' => 'tutorhiring.teacherHiringContract',
  117. 'choice_label' => function(GuardianContract $contract) {
  118. return $contract->getCreatedAt()->format('Y/m/d') . " " .$contract->getFilePath();
  119. },
  120. 'query_builder' => function (GuardianContractRepository $er) {
  121. return $er->createQueryBuilder('u')
  122. ->andWhere('u.comment IS NULL OR u.comment NOT LIKE :excludeCommentLikePattern')
  123. ->setParameter('excludeCommentLikePattern', $this->priceIncreaseService->getDuplicateMarkerLikePattern())
  124. ->orderBy('u.flagTrial', 'ASC')
  125. ->addOrderBy('u.createdAt', 'DESC');
  126. },
  127. 'choice_attr' => ChoiceList::attr($this, function (?GuardianContract $guardianContract): array {
  128. return $guardianContract ? ['data-id' => $guardianContract->getId(), 'data-trial' => $guardianContract->getFlagTrial() ? 1 : 0] : [];
  129. }),
  130. 'required' => true
  131. ])
  132. ->add('salesPerson', null, ['label' => 'forms.labels.salesPerson', 'disabled' => true])
  133. ->add('guardianRegisterChildren', CollectionType::class, [
  134. 'entry_type' => GuardianRegisterChildType::class,
  135. 'allow_add' => true,
  136. 'allow_delete' => true,
  137. 'prototype' => true,
  138. 'prototype_data' => (new GuardianRegisterChild())->setName('Vardas1')->setClass(8),
  139. 'attr' => [
  140. 'inline-add' => true,
  141. 'btn-delete-label' => 'Naikinti vaiką',
  142. 'btn-add-label' => 'Pridėti vaiką',
  143. 'class' => 'add-new',
  144. 'data-widget-tags' => 'flex-add-new with-calendar',
  145. 'data-widget-delete' => '<button class="btn btn-danger" type="button" onclick="this.parentNode.parentNode.remove()">Naikinti vaiką</button>'
  146. ],
  147. 'row_attr' => [
  148. 'class' => 'card card-body',
  149. ],
  150. 'label' => 'guardian_register.guardianRegisterChildren'
  151. ])
  152. ->add('flagManualAssignment', null, ['label' => 'Priskyrimas rankiniu būdu'])
  153. ->add('flagEarlyPayment', null, ['label' => 'Įjungti mokėjimą į priekį']);
  154. $paymentDays = [];
  155. for($i = 1; $i <= 28; $i++)
  156. {
  157. $paymentDays[$i] = $i;
  158. }
  159. $builder
  160. ->add('earlyPaymentDay', ChoiceType::class, [
  161. 'label' => 'Mokėjimo data',
  162. 'choices' => $paymentDays,
  163. 'required' => false
  164. // 'row_attr' => ['style' => 'display: none;'],
  165. ])
  166. ;
  167. }
  168. public function configureOptions(OptionsResolver $resolver)
  169. {
  170. $resolver->setDefaults([
  171. 'data_class' => GuardianRegister::class,
  172. ]);
  173. }
  174. }