<?php
namespace App\EventListener;
use App\LiveRanking\Entity\LiveRanking;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\EventDispatcher\GenericEvent;
class LiveRankingSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
return [
'easy_admin.pre_update' => ['preUpdate']
];
}
public function preUpdate(GenericEvent $event)
{
$entity = $event->getSubject();
if ($entity instanceof LiveRanking) {
if ($entity->getShowRanking() === true) {
$entity->setTrackedDriver(null);
$entity->setRankingTimestamp(time()+60);
}
if (null !== $entity->getTrackedDriver()) {
$entity->setTrackTimestamp(time()+60);
}
}
}
}