src/EventSubscriber/QuotationCommentEventSubscriber.php line 70

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber;
  3. use App\Entity\Event;
  4. use App\Event\QuotationCommentEvent;
  5. use App\Service\RabbitMQ\RabbitMQDispatcher;
  6. use App\Service\Subscription\SubscriptionService;
  7. use App\Service\UserLog;
  8. use Doctrine\ORM\EntityManagerInterface;
  9. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  10. use Symfony\Component\Security\Core\Security;
  11. class QuotationCommentEventSubscriber implements EventSubscriberInterface
  12. {
  13.     private $security;
  14.     private $em;
  15.     private $subscriptionService;
  16.     private $userLog;
  17.     public function __construct(
  18.         Security $security,
  19.         EntityManagerInterface $em,
  20.         SubscriptionService $subscriptionService,
  21.         UserLog $userLog
  22.     )
  23.     {
  24.         $this->userLog $userLog;
  25.         $this->security $security;
  26.         $this->subscriptionService $subscriptionService;
  27.         $this->em $em;
  28.     }
  29.     public static function getSubscribedEvents()
  30.     {
  31.         return [
  32.             QuotationCommentEvent::NEW => [
  33.                 ['addQuotationLastUpdateTime'],
  34.                 ['quotationCommentNewNotify'],
  35.                 ['logAction']
  36.             ]
  37.         ];
  38.     }
  39.     public function addQuotationLastUpdateTime(QuotationCommentEvent $event)
  40.     {
  41.         $event->getQuotation()->setLastUpdate(new \DateTime());
  42.         $this->em->persist($event->getQuotation());
  43.         $this->em->flush();
  44.     }
  45.     public function quotationCommentNewNotify(QuotationCommentEvent $event)
  46.     {
  47.         $this->subscriptionService->proceedEvent(
  48.             Event::QUOTATION_NEW_COMMENT,
  49.             $event->getQuotation(),
  50.             [
  51.                 'data' => [
  52.                     'uuid' => $event->getQuotation()->getUuid(),
  53.                     'user_id' => $this->security->getUser()? $this->security->getUser()->getId():null,
  54.                     'comment' => $event->getComment(),
  55.                     'commented_at' => time(),
  56.                 ],
  57.                 'action_name' => 'quotationCommentNewNotify',
  58.             ]
  59.         );
  60.     }
  61.     public function logAction(QuotationCommentEvent $event)
  62.     {
  63.         $this->userLog->log(
  64.             'quotation',
  65.             'new.comment',
  66.             $event->getQuotation()->getId(),
  67.             'New quotation comment ' $event->getQuotation()->getUuid()
  68.         );
  69.     }
  70. }