src/EventSubscriber/EasyAdminChantierSubscriber.php line 57

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber;
  3. use App\Entity\Chantier;
  4. use App\Entity\CommercialNotification;
  5. use App\Entity\User;
  6. use App\Service\Notification;
  7. use Doctrine\ORM\EntityManagerInterface;
  8. use Doctrine\ORM\Mapping\Entity;
  9. use EasyCorp\Bundle\EasyAdminBundle\Event\AfterEntityUpdatedEvent;
  10. use EasyCorp\Bundle\EasyAdminBundle\Event\BeforeCrudActionEvent;
  11. use EasyCorp\Bundle\EasyAdminBundle\Event\BeforeEntityPersistedEvent;
  12. use EasyCorp\Bundle\EasyAdminBundle\Event\BeforeEntityUpdatedEvent;
  13. use Symfony\Component\DependencyInjection\ContainerInterface;
  14. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  15. use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
  16. class EasyAdminChantierSubscriber implements EventSubscriberInterface
  17. {
  18.     private $entityManager;
  19.     private $container;
  20.     private $notification;
  21.     private $status;
  22.     public function __construct(
  23.         EntityManagerInterface $entityManager,
  24.         ContainerInterface $container,
  25.         Notification $notification
  26.     ){
  27.         $this->entityManager $entityManager;
  28.         $this->container $container;
  29.         $this->notification $notification;
  30.     }
  31.     public static function getSubscribedEvents()
  32.     {
  33.         return [
  34.             BeforeEntityPersistedEvent::class => ['add'],
  35.             BeforeEntityUpdatedEvent::class => ['update'],
  36.             AfterEntityUpdatedEvent::class => ['after'],
  37.             BeforeCrudActionEvent::class =>  ['before']
  38.         ];
  39.     }
  40.     public function update(BeforeEntityUpdatedEvent $event)
  41.     {
  42.         $entity $event->getEntityInstance();
  43.         if (!$entity instanceof Chantier) {
  44.             return;
  45.         }
  46.     }
  47.     public function before(BeforeCrudActionEvent $event)
  48.     {
  49.         $instance $event->getAdminContext()->getEntity()->getInstance();
  50.         if (!$instance instanceof Chantier) {
  51.             return;
  52.         }
  53.         $this->status $instance->getStatus();
  54.     }
  55.     public function after(AfterEntityUpdatedEvent $event)
  56.     {
  57.         $entity $event->getEntityInstance();
  58.         if (!$entity instanceof Chantier) {
  59.             return;
  60.         }
  61.     }
  62.     public function add(BeforeEntityPersistedEvent $event)
  63.     {
  64.         $entity $event->getEntityInstance();
  65.         if (!$entity instanceof Chantier) {
  66.             return;
  67.         }
  68.     }
  69. }