<?php
namespace App\EventSubscriber;
use App\Entity\CustomerQuotations;
use App\Entity\Upload;
use App\Entity\Event;
use App\Event\QuotationFileUploadEvent;
use App\Repository\UserRepository;
use App\Service\Log\QuotationLogService;
use App\Service\RabbitMQ\RabbitMQDispatcher;
use App\Service\Subscription\SubscriptionService;
use App\Service\UserLog;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Security\Core\Security;
class FileUploadSubscriber implements EventSubscriberInterface
{
protected $userRepo;
protected $subscriptionService;
protected $userLog;
protected $quoteLog;
protected $security;
public function __construct(
UserRepository $userRepo,
SubscriptionService $subscriptionService,
QuotationLogService $logService,
Security $security,
UserLog $userLog
)
{
$this->userLog = $userLog;
$this->quoteLog = $logService;
$this->userRepo = $userRepo;
$this->subscriptionService = $subscriptionService;
$this->security = $security;
}
public static function getSubscribedEvents(): array
{
return [
QuotationFileUploadEvent::UPLOAD => [['sendQuotationFileNotification'], ['logUploadAction']],
QuotationFileUploadEvent::REMOVE => [['logRemoveAction']],
];
}
public function sendQuotationFileNotification(QuotationFileUploadEvent $event)
{
$invoicesType = [Upload::TYPE_CUSTOMER_INVOICE, Upload::TYPE_MF_INVOICE];
$file = $event->getFile();
if (in_array($file['type'], $invoicesType)) {
$this->subscriptionService->proceedEvent(
Event::QUOTATION_FILE_UPLOAD,
$event->getQuotation(),
[
'data' => [
'email_data' => $file['email_data']
],
'action_name' => 'quotationFileNotification',
]
);
}
}
public function logUploadAction(QuotationFileUploadEvent $event)
{
$file = $event->getFile();
$quotation = $event->getQuotation();
$this->quoteLog->logAction(
$quotation,
'log.quotation.file.upload',
$quotation->getOrderNumber()
);
$this->userLog->log(
'quotation',
'file.upload',
null,
'Quotation, file uploaded. Order number: ' . $file['email_data']['order_number']
);
}
public function logRemoveAction(QuotationFileUploadEvent $event)
{
$quotation = $event->getQuotation();
$file = $event->getFile();
$this->quoteLog->logAction(
$quotation,
'log.quotation.file.remove',
$quotation->getOrderNumber()
);
$this->userLog->log(
'quotation',
'file.remove',
null,
'Quotation, file removed. File path: ' . $file['path']
);
}
}