Commit 3543f1b2 authored by David Surville's avatar David Surville
Browse files

[Fix] Les fonctions setUnicaenTermsOfUse et setSupannRefId géraient mal la...

[Fix] Les fonctions setUnicaenTermsOfUse et setSupannRefId géraient mal la modification multi-valuée pour une même étiquette
parent 32126161
......@@ -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;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment