synchronisation label niveau01 et niveau02 dans fiche annuaire user (ref #65)

This commit is contained in:
afornerot 2020-02-26 15:08:06 +01:00
parent 5e7f1ba3c7
commit 70c1d6cd8c
6 changed files with 80 additions and 6 deletions

View File

@ -8,7 +8,7 @@ INSERT IGNORE INTO `niveau01` (`id`, `label`, `siren`) VALUES
(-100, 'DRAAF', '130007107');
INSERT IGNORE INTO `user` (`id`, `niveau01_id`, `username`, `firstname`, `lastname`, `password`, `email`, `avatar`, `role`,`siren`,`authlevel`) VALUES
(-100, -100, 'admin', 'Administrateur', 'draaf', '{SSHA}oBuVhAUjam9tCeMBwS0xBsAM2PdHZLW3
(-100, -100, 'admin', 'Administrateur', 'draaf', '{SSHA}RpichoTKCN2p1e9VPz1JnGxjaZ7Xe1Eq
', 'admin@ldapbundle.ac-arno.fr', 'admin.jpg', 'ROLE_ADMIN', '130007107', 'simple');

View File

@ -92,6 +92,17 @@ class User implements UserInterface, \Serializable
*/
private $siret;
/**
* @ORM\Column(type="string", length=250, nullable=true)
*/
private $labelniveau01;
/**
* @ORM\Column(type="string", length=250, nullable=true)
*/
private $labelniveau02;
/**
* @ORM\Column(type="string", length=60, nullable=true)
*/
@ -629,6 +640,54 @@ class User implements UserInterface, \Serializable
return $this->siret;
}
/**
* Set labelniveau01
*
* @param string $labelniveau01
*
* @return User
*/
public function setLabelniveau01($labelniveau01)
{
$this->labelniveau01 = $labelniveau01;
return $this;
}
/**
* Get labelniveau01
*
* @return string
*/
public function getLabelniveau01()
{
return $this->labelniveau01;
}
/**
* Set labelniveau02
*
* @param string $labelniveau02
*
* @return User
*/
public function setLabelniveau02($labelniveau02)
{
$this->labelniveau02 = $labelniveau02;
return $this;
}
/**
* Get labelniveau02
*
* @return string
*/
public function getLabelniveau02()
{
return $this->labelniveau02;
}
/**
* Set usualname
*

View File

@ -20,6 +20,7 @@ class syncNiveau01 implements EventSubscriber
$this->em = $em;
$this->shouldSync = true;
$this->changeSiren = true;
$this->changeLabel = true;
}
public function getSubscribedEvents()
@ -41,6 +42,7 @@ class syncNiveau01 implements EventSubscriber
// Synchronisation uniquement si changement de valeur
$this->shouldSync = $args->hasChangedField('label')||$args->hasChangedField('siren');
$this->changeSiren = $args->hasChangedField('siren');
$this->changeLabel = $args->hasChangedField('label');
if($args->hasChangedField('label')) $this->oldid=$args->getOldValue('label');
@ -57,7 +59,7 @@ class syncNiveau01 implements EventSubscriber
}
if ($entity instanceof Niveau01 && $this->changeSiren) {
if ($entity instanceof Niveau01 && ($this->changeSiren||$this->changeLabel)) {
// On change le SIRET de l'ensemble des utlisateurs associés à cet établissement
$qb = $this->em->createQueryBuilder();
$datas= $qb ->select('table')->from('CadolesCoreBundle:User','table')
@ -67,10 +69,11 @@ class syncNiveau01 implements EventSubscriber
->getResult();
foreach($datas as $data) {
$data->setSiren($entity->getSiren());
$data->setLabelniveau01($entity->getLabel());
$this->em->persist($data);
$this->em->flush();
}
}
}
}
public function postPersist(LifecycleEventArgs $args)

View File

@ -22,6 +22,7 @@ class syncNiveau02 implements EventSubscriber
$this->em = $em;
$this->shouldSync = true;
$this->changeSiret = true;
$this->changeLabel = true;
}
public function getSubscribedEvents()
@ -43,6 +44,7 @@ class syncNiveau02 implements EventSubscriber
// Synchronisation uniquement si changement de valeur
$this->shouldSync = $args->hasChangedField('label')||$args->hasChangedField('siret')||$args->hasChangedField('postaladress');
$this->changeSiret = $args->hasChangedField('siret');
$this->changeLabel = $args->hasChangedField('label');
if($args->hasChangedField('label')) $this->oldid=$args->getOldValue('label');
}
@ -56,7 +58,7 @@ class syncNiveau02 implements EventSubscriber
$this->upsertNiveau02($entity);
}
if ($entity instanceof Niveau02 && $this->changeSiret) {
if ($entity instanceof Niveau02 && ($this->changeSiret||$this->changeLabel)) {
// On change le SIRET de l'ensemble des utlisateurs associés à cet établissement
$qb = $this->em->createQueryBuilder();
$datas= $qb ->select('table')->from('CadolesCoreBundle:User','table')
@ -66,6 +68,7 @@ class syncNiveau02 implements EventSubscriber
->getResult();
foreach($datas as $data) {
$data->setSiret($entity->getSiret());
$data->setLabelniveau02($entity->getLabel());
$this->em->persist($data);
$this->em->flush();
}

View File

@ -53,6 +53,8 @@ class syncUser implements EventSubscriber
$args->hasChangedField('niveau02') ||
$args->hasChangedField('siren') ||
$args->hasChangedField('siret') ||
$args->hasChangedField('labelniveau01') ||
$args->hasChangedField('labelniveau02') ||
$args->hasChangedField('authlevel') ||
$args->hasChangedField('usualname') ||
$args->hasChangedField('telephonenumber') ||
@ -68,10 +70,15 @@ class syncUser implements EventSubscriber
;
$entity->setSiren($entity->getNiveau01()->getSiren());
if($entity->getNiveau02()!==null)
$entity->setLabelniveau01($entity->getNiveau01()->getLabel());
if($entity->getNiveau02()!==null) {
$entity->setSiret($entity->getNiveau02()->getSiret());
else
$entity->setLabelniveau02($entity->getNiveau02()->getLabel());
}
else {
$entity->setSiret(null);
$entity->setLabelniveau02(null);
}
}
public function postUpdate(LifecycleEventArgs $args)

View File

@ -270,7 +270,9 @@ class ldapService
$attrs['userPassword'] = $user->getPassword();
$attrs['cn'] = $user->getFirstname() . ' ' . $user->getLastname();
$attrs['siren'] = $user->getNiveau01()->getSiren();
$attrs['niveau01'] = $user->getNiveau01()->getLabel();
$attrs['siret'] = ($user->getNiveau02()!==null?$user->getNiveau02()->getSiret():"");
$attrs['niveau02'] = ($user->getNiveau02()!==null?$user->getNiveau02()->getLabel():"");
$attrs['authlevel'] = $user->getAuthlevel();
$attrs['usualname'] = $user->getUsualname();
$attrs['telephoneNumber'] = $user->getTelephonenumber();