src/EventSubscriber/AlertEventSubscriber.php line 32

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber;
  3. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  4. use Symfony\Component\HttpKernel\Event\ControllerEvent;
  5. use Twig\Environment;
  6. use App\Repository\DestinationRepository;
  7. use App\Repository\OrderItemRepository;
  8. use App\Repository\SalesRepository;
  9. class AlertEventSubscriber implements EventSubscriberInterface
  10. {
  11.     private $twig;
  12.     private $destinationRepository;
  13.     private $salesRepository;
  14.     public function __construct
  15.     (
  16.         Environment $twig,
  17.         DestinationRepository $destinationRepository,
  18.         OrderItemRepository $orderItemRepository,
  19.         SalesRepository $salesRepository
  20.     )
  21.     {
  22.         $this->twig $twig;
  23.         $this->destinationRepository $destinationRepository;
  24.         $this->orderItemRepository $orderItemRepository;
  25.         $this->salesRepository $salesRepository;
  26.     }
  27.     public function onKernelController(ControllerEvent $event): void
  28.     {
  29.         //承認していない納品先
  30.         $this->unapprovedDestinationAlert();
  31.         //完了していない直送依頼書
  32.         $this->unfinishedSendRequestAlert();
  33.         //完了していない出荷報告書
  34.         $this->unfinishedDeliveryReportAlert();
  35.     }
  36.     protected function unapprovedDestinationAlert()
  37.     {
  38.         $Destinations $this->destinationRepository->getUnapprovedDestination();
  39.         $this->twig->addGlobal('AlertUnapprovedDestination'$Destinations);
  40.     }
  41.     protected function unfinishedSendRequestAlert()
  42.     {
  43.         $searchData = [
  44.             'status' => [3]
  45.         ];
  46.         $OrderItems $this->orderItemRepository->getOrderItemOfUnfinishedSendRequestBySearchData($searchData);
  47.         $this->twig->addGlobal('AlertUnfinishedSendRequest'$OrderItems);
  48.     }
  49.     protected function unfinishedDeliveryReportAlert()
  50.     {
  51.         $searchData = [
  52.             'status' => [2]
  53.         ];
  54.         $Sales $this->salesRepository->getSalesOfUnfinishedDeliveryReportBySearchData($searchData);
  55.         $this->twig->addGlobal('AlertUnfinishedDeliveryReport'$Sales);
  56.     }
  57.     public static function getSubscribedEvents(): array
  58.     {
  59.         return [
  60.             'kernel.controller' => 'onKernelController',
  61.         ];
  62.     }
  63. }