<?php
namespace App\EventSubscriber;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\ControllerEvent;
use Twig\Environment;
use App\Repository\DestinationRepository;
use App\Repository\OrderItemRepository;
use App\Repository\SalesRepository;
class AlertEventSubscriber implements EventSubscriberInterface
{
private $twig;
private $destinationRepository;
private $salesRepository;
public function __construct
(
Environment $twig,
DestinationRepository $destinationRepository,
OrderItemRepository $orderItemRepository,
SalesRepository $salesRepository
)
{
$this->twig = $twig;
$this->destinationRepository = $destinationRepository;
$this->orderItemRepository = $orderItemRepository;
$this->salesRepository = $salesRepository;
}
public function onKernelController(ControllerEvent $event): void
{
//承認していない納品先
$this->unapprovedDestinationAlert();
//完了していない直送依頼書
$this->unfinishedSendRequestAlert();
//完了していない出荷報告書
$this->unfinishedDeliveryReportAlert();
}
protected function unapprovedDestinationAlert()
{
$Destinations = $this->destinationRepository->getUnapprovedDestination();
$this->twig->addGlobal('AlertUnapprovedDestination', $Destinations);
}
protected function unfinishedSendRequestAlert()
{
$searchData = [
'status' => [3]
];
$OrderItems = $this->orderItemRepository->getOrderItemOfUnfinishedSendRequestBySearchData($searchData);
$this->twig->addGlobal('AlertUnfinishedSendRequest', $OrderItems);
}
protected function unfinishedDeliveryReportAlert()
{
$searchData = [
'status' => [2]
];
$Sales = $this->salesRepository->getSalesOfUnfinishedDeliveryReportBySearchData($searchData);
$this->twig->addGlobal('AlertUnfinishedDeliveryReport', $Sales);
}
public static function getSubscribedEvents(): array
{
return [
'kernel.controller' => 'onKernelController',
];
}
}