<?php
// src/EventSubscriber/LoginSuccessSubscriber.php
namespace App\EventSubscriber;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
use Symfony\Component\Security\Http\Event\LoginSuccessEvent;
use App\Repository\EventRepository;
use App\Repository\WarrantyRepository;
use App\Service\WorkFlowEventService;
use App\Service\WorkFlowWarrantyService;
class LoginSuccessSubscriber implements EventSubscriberInterface
{
private $eventRepository;
private $workFlowEventService;
private $warrantyRepository;
private $workFlowWarrantyService;
public function __construct(EventRepository $eventRepository, WarrantyRepository $warrantyRepository, WorkFlowEventService $workFlowEventService, WorkFlowWarrantyService $workFlowWarrantyService) {
$this->eventRepository = $eventRepository;
$this->warrantyRepository = $warrantyRepository;
$this->workFlowEventService = $workFlowEventService;
$this->workFlowWarrantyService = $workFlowWarrantyService;
}
public static function getSubscribedEvents()
{
// return the subscribed events, their methods and priorities
return [
LoginSuccessEvent::class => 'onLoginSuccessUser',
//LoginSuccessEvent::class => 'onLoginSuccessUserWarranty',
];
}
public function onLoginSuccessUser(LoginSuccessEvent $event )
{
$date = new \DateTime();
$findEventsActiveBeforeCurrentDate = $this->eventRepository->findEventsActiveBeforeCurrentDate($date, 'active');
foreach($findEventsActiveBeforeCurrentDate as $event) {
$this->workFlowEventService->closeTransition($event);
$this->eventRepository->save($event, true);
}
$warranties = $this->warrantyRepository->findWarrantiesActiveBeforeCurrentDate($date, 'active');
//dd($warranties);
foreach($warranties as $warranty) {
$this->workFlowWarrantyService->expireTransition($warranty);
$this->warrantyRepository->save($warranty, true);
}
//dd($findEventsActiveBeforeCurrentDate);
}
}