src/EventSubscriber/FileUploadSubscriber.php line 89

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber;
  3. use App\Entity\CustomerQuotations;
  4. use App\Entity\Upload;
  5. use App\Entity\Event;
  6. use App\Event\QuotationFileUploadEvent;
  7. use App\Repository\UserRepository;
  8. use App\Service\Log\QuotationLogService;
  9. use App\Service\RabbitMQ\RabbitMQDispatcher;
  10. use App\Service\Subscription\SubscriptionService;
  11. use App\Service\UserLog;
  12. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  13. use Symfony\Component\Security\Core\Security;
  14. class FileUploadSubscriber implements EventSubscriberInterface
  15. {
  16.     protected $userRepo;
  17.     protected $subscriptionService;
  18.     protected $userLog;
  19.     protected $quoteLog;
  20.     protected $security;
  21.     public function __construct(
  22.         UserRepository      $userRepo,
  23.         SubscriptionService $subscriptionService,
  24.         QuotationLogService $logService,
  25.         Security            $security,
  26.         UserLog             $userLog
  27.     )
  28.     {
  29.         $this->userLog $userLog;
  30.         $this->quoteLog $logService;
  31.         $this->userRepo $userRepo;
  32.         $this->subscriptionService $subscriptionService;
  33.         $this->security $security;
  34.     }
  35.     public static function getSubscribedEvents(): array
  36.     {
  37.         return [
  38.             QuotationFileUploadEvent::UPLOAD => [['sendQuotationFileNotification'], ['logUploadAction']],
  39.             QuotationFileUploadEvent::REMOVE => [['logRemoveAction']],
  40.         ];
  41.     }
  42.     public function sendQuotationFileNotification(QuotationFileUploadEvent $event)
  43.     {
  44.         $invoicesType = [Upload::TYPE_CUSTOMER_INVOICEUpload::TYPE_MF_INVOICE];
  45.         $file $event->getFile();
  46.         if (in_array($file['type'], $invoicesType)) {
  47.             $this->subscriptionService->proceedEvent(
  48.                 Event::QUOTATION_FILE_UPLOAD,
  49.                 $event->getQuotation(),
  50.                 [
  51.                     'data' => [
  52.                         'email_data' => $file['email_data']
  53.                     ],
  54.                     'action_name' => 'quotationFileNotification',
  55.                 ]
  56.             );
  57.         }
  58.     }
  59.     public function logUploadAction(QuotationFileUploadEvent $event)
  60.     {
  61.         $file $event->getFile();
  62.         $quotation $event->getQuotation();
  63.         $this->quoteLog->logAction(
  64.             $quotation,
  65.             'log.quotation.file.upload',
  66.             $quotation->getOrderNumber()
  67.         );
  68.         $this->userLog->log(
  69.             'quotation',
  70.             'file.upload',
  71.             null,
  72.             'Quotation, file uploaded. Order number: ' $file['email_data']['order_number']
  73.         );
  74.     }
  75.     public function logRemoveAction(QuotationFileUploadEvent $event)
  76.     {
  77.         $quotation $event->getQuotation();
  78.         $file $event->getFile();
  79.         $this->quoteLog->logAction(
  80.             $quotation,
  81.             'log.quotation.file.remove',
  82.             $quotation->getOrderNumber()
  83.         );
  84.         $this->userLog->log(
  85.             'quotation',
  86.             'file.remove',
  87.             null,
  88.             'Quotation, file removed. File path: ' $file['path']
  89.         );
  90.     }
  91. }