Skip to content
Snippets Groups Projects
Commit 669f4479 authored by David Surville's avatar David Surville
Browse files

Meilleure gestion du setter de l'attribut "unicaenServiceEtat"

parent 384a29b1
No related branches found
No related tags found
No related merge requests found
......@@ -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;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment