<?php
/**
* Created by PhpStorm.
* User: bertrand
* Date: 29/03/2019
* Time: 13:53
*/
namespace App\Listener;
use App\Entity\StoreManagementRequest;
use App\Service\StoreManagementRequestService;
use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Workflow\Event\Event;
class StoreWorflowListener implements EventSubscriberInterface
{
private $logger;
private $storeManagementRequestService;
private $entityManager;
public function __construct(LoggerInterface $logger, StoreManagementRequestService $storeManagementRequestService, EntityManagerInterface $entityManager)
{
$this->logger = $logger;
$this->storeManagementRequestService = $storeManagementRequestService;
$this->entityManager = $entityManager;
}
public function onValidation(Event $event){
$store = $event->getSubject();
$store->setAcquisitionEnabled(true);
$this->logger->info('Validation du centre: activation des leads par défaut');
}
public function onRejectCreation(Event $event)
{
$store = $event->getSubject();
$this->entityManager->remove($store);
$this->entityManager->flush();
}
public function onAskForSuppression(Event $event)
{
$store = $event->getSubject();
$this->storeManagementRequestService->createNewSuppressionRequestForStore($store);
}
public function onValidateSuppression(Event $event)
{
$store = $event->getSubject();
$this->entityManager->remove($store);
$this->entityManager->flush();
}
public static function getSubscribedEvents()
{
return [
'workflow.store.completed.validate' => 'onValidation',
'workflow.store.completed.reject' => 'onRejectCreation',
'workflow.store.completed.askForSuppression' => 'onAskForSuppression',
'workflow.store.completed.validate_suppression' => 'onValidateSuppression',
];
}
}