src/Form/VehicleRtsActivitiesType.php line 26

  1. <?php
  2. namespace App\Form;
  3. use App\Entity\Activity;
  4. use App\Entity\VehicleRtsActivitiesInventories;
  5. use App\Entity\VehicleRtsActivityTransports;
  6. use App\Entity\Vehicles;
  7. use App\EventListener\WorkFlowFormSubscriber;
  8. use Doctrine\ORM\EntityManagerInterface as EntityManager;
  9. use Symfony\Component\Form\AbstractType;
  10. use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
  11. use Symfony\Component\Form\Extension\Core\Type\FileType;
  12. use Symfony\Component\Form\Extension\Core\Type\HiddenType;
  13. use Symfony\Component\Form\FormBuilderInterface;
  14. use Symfony\Component\HttpFoundation\RequestStack;
  15. use Symfony\Component\OptionsResolver\OptionsResolver;
  16. use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
  17. use Symfony\Component\Workflow\Registry;
  18. use Symfony\Contracts\Translation\TranslatorInterface;
  19. /**
  20.  * Class VehicleRtsActivitiesType
  21.  * @package App\Form
  22.  */
  23. class VehicleRtsActivitiesType extends AbstractType
  24. {
  25.     /**
  26.      * @var EntityManager
  27.      */
  28.     public $entityManager;
  29.     /**
  30.      * @var Translator
  31.      */
  32.     protected $translator;
  33.     /**
  34.      * @var Translator
  35.      */
  36.     protected $workflowRegistry;
  37.     protected \Symfony\Component\HttpFoundation\RequestStack $request;
  38.     protected \Doctrine\ORM\EntityManagerInterface $EntityManager;
  39.     protected \Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface $tokenStorage;
  40.     /**
  41.      * VehicleRevokeRequestsType constructor.
  42.      * @param Translator|null $translator
  43.      */
  44.     public function __construct(Registry $workflowRegistry,RequestStack $request,EntityManager $EntityManager,TokenStorageInterface $tokenStorageTranslatorInterface $translatornull)
  45.     {
  46.         $this->translator $translator;
  47.         $this->workflowRegistry $workflowRegistry;
  48.         $this->request $request;
  49.         $this->entityManager $EntityManager;
  50.         $this->tokenStorage $tokenStorage;
  51.     }
  52.     /**
  53.      * {@inheritdoc}
  54.      */
  55.     public function buildForm(FormBuilderInterface $builder, array $options)
  56.     {
  57.         $builder->add('activityDate'DateTimeType::class, array(
  58.                 'label'    => 'Activity Date',
  59.                 'widget'   => 'single_text',
  60.                 'required' => false,
  61.                 'html5'    => false
  62.             ))
  63.             ->add('notes'null, array('label' => 'Notes'));
  64.         if ($options['activityType'] == 'Transport_To_Distination') {
  65.             $vehicleId $this->request->getCurrentRequest()->get('vehicleId');
  66.             $vehicle $this->entityManager->getRepository(Vehicles::class)->find($vehicleId);
  67.             $receivingAt $vehicle->getReceivingAt();
  68.             $builder->add('activityDestination'DestinationType::class, array(
  69.                 'label'                => false,
  70.                 'locale'               => $options['locale'],
  71.                 'required'             => true,
  72.                 'vehicleExitDate'      => $options['vehicleExitDate'],
  73.                 'isReturnedInActivity' => $options['isReturnedInActivity'],
  74.                 'isRepairInActivity' => $options['isRepairInActivity'],
  75.                 'checkDisable'          =>$options['checkDisable'],
  76.                 'receivingAt'           => $receivingAt
  77.             ));
  78.         }
  79.         
  80.         if ($options['activityType'] == 'Transport_And_Store' || $options['activityType'] == 'Store_Only') {
  81.             $builder->add('activityStorage'VehicleRtsActivityStorageType::class, array(
  82.                 'label'    => false
  83.                 'locale'   => $options['locale'], 
  84.                 'required' => true,
  85.                 'oldWarehouseId' => $options['oldWarehouseId']
  86.             ));
  87.         }
  88.         
  89.         if ($options['activityType'] == 'Transport_To_Distination' || $options['activityType'] == 'Transport_And_Store') {
  90.             $builder->add('activityTransport'VehicleRtsActivityTransportsType::class, array(
  91.                 'label'      => false
  92.                 'data_class' => VehicleRtsActivityTransports::class,
  93.                 'locale'     => $options['locale'], 
  94.                 'required'   => true,
  95.                 'theEffectiveVat'=> $options['theEffectiveVat']
  96.             ));
  97.         }
  98.         if ($options['revokeInventory'] != null) {
  99.             $builder->add('activityInventory'VehicleRtsActivitiesInventoriesType::class, array(
  100.                 'required'     => false,
  101.                 'data_class'   => VehicleRtsActivitiesInventories::class,
  102.                 'label'        => false,
  103.                 'by_reference' => false
  104.             ))
  105.                 ->add('images'FileType::class, array(
  106.                     'label'                 => false,
  107.                     'multiple'              => true,
  108.                     'required'              => false,
  109.                     'mapped'                => false,
  110.                     'attr' => array('class' => 'images','accept' => 'image/*','multiple' => 'multiple')
  111.                 ))
  112.                 ->add('deletedImageIds'HiddenType::class, array(
  113.                     'label'    => false,
  114.                     'required' => false,
  115.                     'mapped'   => false,
  116.                     'attr' => array(
  117.                         'class' => 'deletedImageIds'
  118.                     )
  119.                 ))
  120.                 ->add('deletedUploadIds'HiddenType::class, array(
  121.                     'label'    => false,
  122.                     'required' => false,
  123.                     'mapped'   => false,
  124.                     'attr' => array(
  125.                         'class' => 'deletedUploadIds'
  126.                     )
  127.                 ))
  128.                 ->add('newImages'HiddenType::class, array(
  129.                     'label'    => false,
  130.                     'required' => false,
  131.                     'mapped'   => false,
  132.                     'attr' => array(
  133.                         'class' => 'newImages'
  134.                     )
  135.                 ));
  136.         }
  137.         $builder->addEventSubscriber(new WorkFlowFormSubscriber($this->workflowRegistry,$this->request,$this->entityManager,$this->tokenStorage$this->translator));
  138.     }
  139.     
  140.     /**
  141.      * {@inheritdoc}
  142.      */
  143.     public function configureOptions(OptionsResolver $resolver)
  144.     {
  145.         $resolver->setDefaults(array(
  146.             'data_class'           => Activity::class,
  147.             'translation_domain'   => 'vehicles',
  148.             'locale'               => 'en',
  149.             'activityType'         => '',
  150.             'revokeInventory'      => null,
  151.             'vehicleExitDate'      => null,
  152.             'isReturnedInActivity' => false,
  153.             'isRepairInActivity' => false,
  154.             'method' => 'POST',      //adding this to allow the controller to explicitly set the form method
  155.             'checkDisable'        => [],
  156.             'oldWarehouseId'       => null,
  157.             'theEffectiveVat'=> null
  158.         ));
  159.     }
  160.     /**
  161.      * {@inheritdoc}
  162.      */
  163.     public function getBlockPrefix()
  164.     {
  165.         return 'appbundle_vehiclertsactivities';
  166.     }
  167. }