Commit 82796fdf authored by David Surville's avatar David Surville
Browse files

Meilleure gestion du setter de l'attribut "unicaenServiceEtat"

parent a421d20a
......@@ -1572,11 +1572,40 @@ class People extends Entity
public function setUnicaenServiceEtat($value = null, $append = false)
{
$value = $this->preFormat($value);
$value = array_filter($value, function ($v) {
return preg_match(self::$service_etat_pattern, $v);
});
$this->appendOrNot('unicaenServiceEtat', $value, $append);
if(empty($value)) {
$this->appendOrNot('unicaenServiceEtat', $value, false);
}
if ($append) {
$this->appendOrNot('unicaenServiceEtat', $value, true);
}
$newValues = [];
foreach ($value as $v) {
if (preg_match(self::$service_etat_pattern, $v, $matches)) {
$newValues[$matches['etiquette']][] = $matches['value'];
}
};
foreach ($newValues as $label => $values) {
$currentValues = $this->preFormat($this->unicaenServiceEtat);
array_walk($currentValues, function (&$cv) use ($label, $values) {
if (preg_match("/^".$label."(?<value>.+)$/", $cv, $matches)) {
if(!in_array($matches['value'], $values)) {
$this->remove('unicaenServiceEtat', $cv);
$cv = null;
}
}
});
foreach($values as $v) {
$v = $label.$v;
if (!in_array($v, $currentValues)) {
$currentValues[] = $v;
}
}
$this->appendOrNot('unicaenServiceEtat', 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