<?php
namespace App\EventDispatcher;
use App\Model\Invoice\Entity\Invoice\InvoiceActivityLog;
use DateTime;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class InvoiceLoggingSubscribe implements EventSubscriberInterface
{
private $em;
public function __construct(EntityManagerInterface $em)
{
$this->em = $em;
}
public static function getSubscribedEvents(): array
{
return array(
InvoiceLoggingEvent::class => 'onInvoiceLogging'
);
}
public function onInvoiceLogging(InvoiceLoggingEvent $event)
{
$invoice_log = new InvoiceActivityLog();
$invoice_log->setStatus($event->getStatus());
$invoice_log->setInvoiceId($event->getInvoice());
$invoice_log->setChangeUserId($event->getUser());
$invoice_log->setChangeTime(new DateTime());
$this->em->persist($invoice_log);
}
}