src/Form/VPN/Service/Service/UnlimitedOpenType.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Form\VPN\Service\Service;
  3. use Symfony\Component\Form\AbstractType;
  4. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  5. use Symfony\Component\Form\Extension\Core\Type\HiddenType;
  6. use Symfony\Component\Form\Extension\Core\Type\NumberType;
  7. use Symfony\Component\Form\Extension\Core\Type\TextType;
  8. use Symfony\Component\Form\FormBuilderInterface;
  9. use Symfony\Component\OptionsResolver\OptionsResolver;
  10. class UnlimitedOpenType extends AbstractType
  11. {
  12.     public function buildForm(FormBuilderInterface $builder, array $options): void
  13.     {
  14.         $builder
  15.             ->add('serviceType'HiddenType::class, [
  16.                 'data' => 'unlimited'
  17.             ])
  18.             ->add('protocol'HiddenType::class, [
  19.                 'data' => 'open'
  20.             ])
  21.             ->add('username' null , [
  22.                 'label' => 'نام انتخابی سرویس'
  23.             ])
  24.             ->add('host' ChoiceType::class , [
  25.                 'label' => 'میزبانی سرویس',
  26.                 'choices' => [
  27.                     'سرور های تهران نت' => 'tehrannet',
  28.                     'سرور های خودم' => 'mine'
  29.                 ],
  30.                 'mapped' => false,
  31.                 'choice_attr' => function($choice$key$value) {
  32.                     if ($value !== 'tehrannet') {
  33.                         return ['disabled' => 'disabled'];
  34.                     }
  35.                     return [];
  36.                 },
  37.             ])
  38.             ->add('password' null , [
  39.                 'label'=>'کلمه عبور انتخابی'
  40.             ])
  41.             ->add('clientId'NumberType::class, [
  42.                 'data' => $options['clientId'],
  43.                 'disabled' => true,
  44.                 'label' => 'شناسه یکتا سرویس'
  45.             ])
  46.             ->add('users'ChoiceType::class, [
  47.                 'attr' => ['class' => 'ajax-openUnLimited'],
  48.                 'label' => 'تعداد کاربر مورد نیاز',
  49.                 'choices' => [
  50.                     'یک کاربر' => 1,
  51.                     'دو کاربر' => 2,
  52.                     'سه کاربر' => 3,
  53.                     'چهار کاربر' => 4,
  54.                     'پنج کاربر' => 5,
  55. //                    'بدون محدودیت کاربر' => 0,
  56.                 ]
  57.             ])
  58.             ->add('size'HiddenType::class, [
  59.                 'data' => 0
  60.             ])
  61.             ->add('country' ChoiceType::class, [
  62.                 'label' => 'کشور',
  63.                 'choices' => $options['locations'] ,
  64.                 'mapped' => false,
  65.                 'required'=> true
  66.             ])
  67.             ->add('days'ChoiceType::class, [
  68.                 'attr' => ['class' => 'ajax-openUnLimited'],
  69.                 'label' => 'زمان مورد نیاز',
  70.                 'choices' => [
  71.                     'یک ماه' => 30,
  72.                     'دو ماه' => 60,
  73.                     'سه ماه' => 90,
  74.                     'شش ماه' => 180,
  75.                     'دوازده ماه' => 365,
  76.                 ]
  77.             ])
  78.             ->add('price' TextType::class , [
  79.                 'label' => 'هزینه بسته انتخابی',
  80.                 'disabled' => true ,
  81.                 'mapped' => false,
  82.                 'data' => 'ابتدا موارد بالا را انتخاب فرمایید',
  83.                 'attr' => ['class' => 'form-control text-warning border-warning']
  84.             ]);
  85.     }
  86.     public function configureOptions(OptionsResolver $resolver): void
  87.     {
  88.         $resolver->setDefaults([
  89.             'clientId' => null,
  90.             'locations' => []
  91.         ]);
  92.     }
  93. }