src/EventSubscriber/Quote/RequestForQuoteFileTypeResourceSubscriber.php line 36

  1. <?php
  2. namespace App\EventSubscriber\Quote;
  3. use Symfony\Component\HttpFoundation\RequestStack;
  4. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  5. use Symfony\Component\EventDispatcher\GenericEvent;
  6. use Webmozart\Assert\Assert;
  7. use Sylius\Component\Customer\Model\CustomerInterface;
  8. use App\Repository\Customer\CustomerRepository;
  9. use App\Entity\Channel\ChannelEcodaAccountInfo;
  10. use App\Repository\Channel\ChannelEcodaAccountInfoRepository;
  11. use App\Repository\Channel\ChannelEcodaAccountTypeRepository;
  12. use Doctrine\ORM\EntityManagerInterface;
  13. use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
  14. use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
  15. use App\Manager\EcodaAccountManager;
  16. use App\Entity\Quote\RequestForQuoteFileType;
  17. use App\Entity\Quote\RequestForQuoteFileTypeBlank;
  18. use App\Entity\Quote\RequestForQuoteFileTypeExample;
  19. class RequestForQuoteFileTypeResourceSubscriber  implements EventSubscriberInterface
  20.     private $request
  21.     public function __construct(RequestStack $request)
  22.     {
  23.         $this->request $request->getCurrentRequest(); 
  24.     }
  25.     public function onSyliusEntityPreCreate(GenericEvent $event)
  26.     {  
  27.         $entity $event->getSubject();  
  28.         Assert::isInstanceOf($entityRequestForQuoteFileType::class); 
  29.         $this->uplaodFiles($entity);
  30.     } 
  31.     public function onSyliusEntityPreUpdate(GenericEvent $event)
  32.     {   
  33.         $entity $event->getSubject();  
  34.         Assert::isInstanceOf($entityRequestForQuoteFileType::class); 
  35.         $this->uplaodFiles($entity); 
  36.     } 
  37.     private function uplaodFiles($entity){
  38.         $example $this->request->files->get('request_for_quote_file_type')['example']['file'];
  39.         $blank $this->request->files->get('request_for_quote_file_type')['blank']['file']; 
  40.       
  41.         if($example){
  42.             $exampleFile = new RequestForQuoteFileTypeExample();
  43.             $exampleFile->setFile($example); 
  44.             $exampleFile->setUpdatedAt(new \DateTime()); 
  45.             $entity->setExample($exampleFile);
  46.         }else{
  47.             $entity->setExample(null);
  48.         }
  49.  
  50.        
  51.         if($blank){
  52.             $blankFile = new RequestForQuoteFileTypeBlank();
  53.             $blankFile->setFile($blank);
  54.             $blankFile->setUpdatedAt(new \DateTime());
  55.             $entity->setBlank($blankFile);
  56.         }else{
  57.             $entity->setBlank(null);
  58.         } 
  59.         //dd($entity);
  60.     }
  61.     public static function getSubscribedEvents()
  62.     {
  63.         return [
  64.            'app.request_for_quote_file_type.pre_create' => 'onSyliusEntityPreCreate'
  65.            'app.request_for_quote_file_type.pre_update' => 'onSyliusEntityPreUpdate'
  66.         ];
  67.     }
  68. }