em = $em; $this->ldap = $ldap; } public function getSubscribedEvents(): array { return [ Events::postPersist, Events::preUpdate, Events::postUpdate, Events::preRemove, Events::postRemove, ]; } public function postPersist(LifecycleEventArgs $args): void { $this->entity = $args->getObject(); if (!$this->entity instanceof Entity) { return; } // Synchronisation nine2ldap $this->nine2ldap(); } public function preUpdate(LifecycleEventArgs $args): void { $this->entity = $args->getObject(); if (!$this->entity instanceof Entity) { return; } } public function postUpdate(LifecycleEventArgs $args): void { $this->entity = $args->getObject(); if (!$this->entity instanceof Entity) { return; } // Synchronisation nine2ldap $this->nine2ldap(); } public function preRemove(LifecycleEventArgs $args): void { $this->entity = $args->getObject(); if (!$this->entity instanceof Entity) { return; } // Impossible de supprimer si présence de niveau04 rattaché if (!$this->entity->getNiveau04s()->isEmpty()) { throw new \Exception('Impossible de supprimer cet enregistrement. Il est lié à des niveaux de rang 04'); } // Impossible de supprimer si présence de registration rattaché if (!$this->entity->getRegistrations()->isEmpty()) { throw new \Exception('Impossible de supprimer cet enregistrement. Il est lié à des inscriptions'); } // Impossible de supprimer si présence de user rattaché if (!$this->entity->getUsers()->isEmpty()) { throw new \Exception('Impossible de supprimer cet enregistrement. Il est lié à des utilisateurs'); } // Synchronisation nine2ldap $this->nine2ldapremove(); } public function postRemove(LifecycleEventArgs $args): void { $this->entity = $args->getObject(); if (!$this->entity instanceof Entity) { return; } } private function nine2ldap() { if ($this->ldap->isNine2Ldap()) { // On s'assure que la structure organisationnelle est présente $this->ldap->addOrganisations(); // Ajout / Modification dans annuaire $filter = 'gidnumber='.$this->entity->getId(); $attributes = $this->ldap->listAttributesNiveau03(); $ldapentrys = $this->ldap->search($filter, $attributes, $this->ldap->getParameter('baseniveau03')); if (empty($ldapentrys)) { $this->ldap->addNiveau03($this->entity); } elseif ($this->ldap->ismodifyNiveau03($this->entity, $ldapentrys[0])) { $this->ldap->modifyNiveau03($this->entity, $ldapentrys[0]['cn']); } } } private function nine2ldapremove() { if ($this->ldap->isNine2Ldap()) { $filter = 'gidnumber='.$this->entity->getId(); $attributes = $this->ldap->listAttributesNiveau03(); $ldapentrys = $this->ldap->search($filter, $attributes, $this->ldap->getParameter('baseniveau03')); if (!empty($ldapentrys)) { $this->ldap->deleteNiveau03($this->entity); } } } }