src/EventListener/LiveRankingSubscriber.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\EventListener;
  3. use App\LiveRanking\Entity\LiveRanking;
  4. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  5. use Symfony\Component\EventDispatcher\GenericEvent;
  6. class LiveRankingSubscriber implements EventSubscriberInterface
  7. {
  8.     public static function getSubscribedEvents()
  9.     {
  10.         return [
  11.             'easy_admin.pre_update' => ['preUpdate']
  12.         ];
  13.     }
  14.     public function preUpdate(GenericEvent $event)
  15.     {
  16.         $entity $event->getSubject();
  17.         if ($entity instanceof LiveRanking) {
  18.             if ($entity->getShowRanking() === true) {
  19.                 $entity->setTrackedDriver(null);
  20.                 $entity->setRankingTimestamp(time()+60);
  21.             }
  22.             if (null !== $entity->getTrackedDriver()) {
  23.                 $entity->setTrackTimestamp(time()+60);
  24.             }
  25.         }
  26.     }
  27. }