src/EventSubscriber/EasyAdminSubscriber.php line 31

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber;
  3. use App\Entity\Conferences;
  4. use App\Entity\Communications;
  5. use EasyCorp\Bundle\EasyAdminBundle\Event\AfterEntityPersistedEvent;
  6. use EasyCorp\Bundle\EasyAdminBundle\Event\AfterEntityUpdatedEvent;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. use Doctrine\Persistence\ManagerRegistry;
  9. use Doctrine\ORM\EntityManagerInterface;
  10. class EasyAdminSubscriber implements EventSubscriberInterface
  11. {
  12.     //private $slugger;
  13.     private $entityManager;
  14.     public function __construct(ManagerRegistry $doctrine)//$slugger)
  15.     {
  16.         //$this->slugger = $slugger;
  17.         $this->entityManager $doctrine->getManager();
  18.     }
  19.     public static function getSubscribedEvents()
  20.     {
  21.         return [
  22.             AfterEntityPersistedEvent::class => ['createCommunications'],
  23.             AfterEntityUpdatedEvent::class => ['createCommunications1'],
  24.         ];
  25.     }
  26.     public function createCommunications(AfterEntityPersistedEvent $event)
  27.     {
  28.         $entity $event->getEntityInstance();
  29.         if (!($entity instanceof Conferences)) {
  30.             return;
  31.         }
  32.         $conferenciers $entity->getConferenciers();
  33.         $confid $entity->getId();
  34.         $heure_debut "09:00";
  35.         $duree 15;
  36.         $pause 10;
  37.         foreach($conferenciers as $conferencier){
  38.             //pour chaque conferencier on verifie si une communication pour cet id de conference existe
  39.             $conferencierid $conferencier->getId();
  40.             $commu $this->entityManager->getRepository(Communications::class)->findExistant($conferencier,$entity);
  41.             if($commu){
  42.                 //si oui on update
  43.                 $comm $commu[0];
  44.                 $comm->setTitle('titre');
  45.                 $comm->setDescription('description');
  46.                 $comm->setHeureDebut($heure_debut);
  47.                 $comm->setDuree($duree);
  48.                 $comm->setConferencier($conferencier);
  49.                 $comm->setConference($entity);
  50.                 $this->entityManager->persist($comm);
  51.                 $this->entityManager->flush();
  52.             } else {
  53.                 //si non on la crée
  54.                 $com = new Communications();
  55.                 $com->setTitle('titre');
  56.                 $com->setDescription('description');
  57.                 $com->setHeureDebut($heure_debut);
  58.                 $com->setDuree($duree);
  59.                 $com->setConferencier($conferencier);
  60.                 $com->setConference($entity);
  61.                 $this->entityManager->persist($com);
  62.                 $this->entityManager->flush();
  63.             }
  64.             //$heure_debut += $duree + $pause;
  65.         }
  66.     }
  67.     public function createCommunications1(AfterEntityUpdatedEvent $event)
  68.     {
  69.         $entity $event->getEntityInstance();
  70.         if (!($entity instanceof Conferences)) {
  71.             return;
  72.         }
  73.         $conferenciers $entity->getConferenciers();
  74.         $confid $entity->getId();
  75.         $heure_debut "09:00";
  76.         $duree 15;
  77.         $pause 10;
  78.         foreach($conferenciers as $conferencier){
  79.             //pour chaque conferencier on verifie si une communication pour cet id de conference existe
  80.             $conferencierid $conferencier->getId();
  81.             $commu $this->entityManager->getRepository(Communications::class)->findExistant($conferencier,$entity);
  82.             if($commu){
  83.                 //si oui on update
  84.                 $comm $commu[0];
  85.                 $comm->setTitle('titre');
  86.                 $comm->setDescription('description');
  87.                 $comm->setHeureDebut($heure_debut);
  88.                 $comm->setDuree($duree);
  89.                 $comm->setConferencier($conferencier);
  90.                 $comm->setConference($entity);
  91.                 $this->entityManager->persist($comm);
  92.                 $this->entityManager->flush();
  93.             } else {
  94.                 //si non on la crée
  95.                 $com = new Communications();
  96.                 $com->setTitle('titre');
  97.                 $com->setDescription('description');
  98.                 $com->setHeureDebut($heure_debut);
  99.                 $com->setDuree($duree);
  100.                 $com->setConferencier($conferencier);
  101.                 $com->setConference($entity);
  102.                 $this->entityManager->persist($com);
  103.                 $this->entityManager->flush();
  104.             }
  105.             //$heure_debut += $duree + $pause;
  106.         }
  107.         
  108.         
  109.     }
  110. }