diff --git a/src/UnicaenLdap/Entity/Base/People.php b/src/UnicaenLdap/Entity/Base/People.php index 0a516d828f1e522e62ef1ac382194d032f9f8bc1..e4d57f560fd15828188fe336b371d764d88e0799 100644 --- a/src/UnicaenLdap/Entity/Base/People.php +++ b/src/UnicaenLdap/Entity/Base/People.php @@ -1514,31 +1514,37 @@ class People extends Entity $value = $this->preFormat($value); if(empty($value)) { - $this->appendOrNot('supannRefId', $value, $append); + $this->appendOrNot('supannRefId', $value, false); } + if ($append) { + $this->appendOrNot('supannRefId', $value, true); + } + + $newValues = []; foreach ($value as $v) { if (preg_match(self::$attribute_with_label_pattern, $v, $matches)) { - if ($append) { - $this->appendOrNot('supannRefId', $v, true); - } else { - $label = $matches['etiquette']; - $identifiant = $matches['identifiant']; - $currentValues = $this->preFormat($this->supannRefId); - array_walk($currentValues, function (&$cv) use ($label, $identifiant) { - if (preg_match("/^".$label."(?<identifiant>.+)$/", $cv, $matches)) { - if($matches['identifiant'] != $identifiant) { - $this->remove('supannRefId', $cv); - $cv = null; - } - } - }); - if(!in_array($v, $currentValues)) { - $currentValues[] = $v; + $newValues[$matches['etiquette']][] = $matches['identifiant']; + } + }; + + foreach ($newValues as $label => $values) { + $currentValues = $this->preFormat($this->supannRefId); + array_walk($currentValues, function (&$cv) use ($label, $values) { + if (preg_match("/^".$label."(?<identifiant>.+)$/", $cv, $matches)) { + if(!in_array($matches['identifiant'], $values)) { + $this->remove('supannRefId', $cv); + $cv = null; } - $this->appendOrNot('supannRefId', array_filter($currentValues), false); + } + }); + foreach($values as $v) { + $v = $label.$v; + if (!in_array($v, $currentValues)) { + $currentValues[] = $v; } } + $this->appendOrNot('supannRefId', array_filter($currentValues), false); } return $this; @@ -1579,31 +1585,37 @@ class People extends Entity $value = $this->preFormat($value); if(empty($value)) { - $this->appendOrNot('unicaenTermsOfUse', $value, $append); + $this->appendOrNot('unicaenTermsOfUse', $value, false); } + if ($append) { + $this->appendOrNot('unicaenTermsOfUse', $value, true); + } + + $newValues = []; foreach ($value as $v) { if (preg_match(self::$attribute_with_label_pattern, $v, $matches)) { - if ($append) { - $this->appendOrNot('unicaenTermsOfUse', $v, true); - } else { - $label = $matches['etiquette']; - $identifiant = $matches['identifiant']; - $currentValues = $this->preFormat($this->unicaenTermsOfUse); - array_walk($currentValues, function (&$cv) use ($label, $identifiant) { - if (preg_match("/^".$label."(?<identifiant>.+)$/", $cv, $matches)) { - if($matches['identifiant'] != $identifiant) { - $this->remove('unicaenTermsOfUse', $cv); - $cv = null; - } - } - }); - if(!in_array($v, $currentValues)) { - $currentValues[] = $v; + $newValues[$matches['etiquette']][] = $matches['identifiant']; + } + }; + + foreach ($newValues as $label => $values) { + $currentValues = $this->preFormat($this->unicaenTermsOfUse); + array_walk($currentValues, function (&$cv) use ($label, $values) { + if (preg_match("/^".$label."(?<identifiant>.+)$/", $cv, $matches)) { + if(!in_array($matches['identifiant'], $values)) { + $this->remove('unicaenTermsOfUse', $cv); + $cv = null; } - $this->appendOrNot('unicaenTermsOfUse', array_filter($currentValues), false); + } + }); + foreach($values as $v) { + $v = $label.$v; + if (!in_array($v, $currentValues)) { + $currentValues[] = $v; } } + $this->appendOrNot('unicaenTermsOfUse', array_filter($currentValues), false); } return $this;