src/EventSubscriber/LoginSuccessSubscriber.php line 35

Open in your IDE?
  1. <?php 
  2. // src/EventSubscriber/LoginSuccessSubscriber.php
  3. namespace App\EventSubscriber;
  4. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  5. use Symfony\Component\HttpKernel\Event\ExceptionEvent;
  6. use Symfony\Component\Security\Http\Event\LoginSuccessEvent;
  7. use App\Repository\EventRepository;
  8. use App\Repository\WarrantyRepository;
  9. use App\Service\WorkFlowEventService;
  10. use App\Service\WorkFlowWarrantyService;
  11. class LoginSuccessSubscriber implements EventSubscriberInterface
  12. {
  13.     private $eventRepository;
  14.     private $workFlowEventService;
  15.     private $warrantyRepository;
  16.     private $workFlowWarrantyService;
  17.     
  18.     public function __construct(EventRepository $eventRepository, WarrantyRepository $warrantyRepository, WorkFlowEventService $workFlowEventService, WorkFlowWarrantyService $workFlowWarrantyService) {
  19.         $this->eventRepository = $eventRepository;
  20.         $this->warrantyRepository = $warrantyRepository;
  21.         $this->workFlowEventService = $workFlowEventService;
  22.         $this->workFlowWarrantyService = $workFlowWarrantyService;
  23.     }
  24.     public static function getSubscribedEvents()
  25.     {
  26.         // return the subscribed events, their methods and priorities
  27.         return [
  28.             LoginSuccessEvent::class => 'onLoginSuccessUser',
  29.             //LoginSuccessEvent::class => 'onLoginSuccessUserWarranty',
  30.         ];
  31.     }
  32.     public function onLoginSuccessUser(LoginSuccessEvent $event )
  33.     {
  34.         $date = new \DateTime();
  35.         $findEventsActiveBeforeCurrentDate = $this->eventRepository->findEventsActiveBeforeCurrentDate($date, 'active');
  36.         foreach($findEventsActiveBeforeCurrentDate as $event) {
  37.             $this->workFlowEventService->closeTransition($event);
  38.             $this->eventRepository->save($event, true);
  39.         }
  40.         $warranties = $this->warrantyRepository->findWarrantiesActiveBeforeCurrentDate($date, 'active');
  41.         //dd($warranties);
  42.         foreach($warranties as $warranty) {
  43.             $this->workFlowWarrantyService->expireTransition($warranty);
  44.             $this->warrantyRepository->save($warranty, true);
  45.         }
  46.         //dd($findEventsActiveBeforeCurrentDate);
  47.         
  48.     }
  49. }