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

- Modification de la gestion de l'attribut supannRefId pour les structures et les groupes

- Modification du pattern utilisé pour valider les attributs étiquetés
parent 2f9b0a8a
No related branches found
No related tags found
No related merge requests found
Pipeline #32438 passed
......@@ -269,11 +269,40 @@ class Group extends Entity
public function setSupannRefId($value = null, $append = false)
{
$value = $this->preFormat($value);
$value = array_filter($value, function ($v) {
return preg_match(self::$attribute_with_label_pattern, $v);
});
$this->appendOrNot('supannRefId', $value, $append);
if(empty($value)) {
$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)) {
$newValues[$matches['etiquette']][] = $matches['value'];
}
};
foreach ($newValues as $label => $values) {
$currentValues = $this->preFormat($this->supannRefId);
array_walk($currentValues, function (&$cv) use ($label, $values) {
if (preg_match("/^".$label."(?<value>.*)$/", $cv, $matches)) {
if(!in_array($matches['value'], $values)) {
$this->remove('supannRefId', $cv);
$cv = null;
}
}
});
foreach($values as $v) {
$v = $label.$v;
if (!in_array($v, $currentValues)) {
$currentValues[] = $v;
}
}
$this->appendOrNot('supannRefId', array_filter($currentValues), false);
}
return $this;
}
......
......@@ -1540,15 +1540,15 @@ class People extends Entity
$newValues = [];
foreach ($value as $v) {
if (preg_match(self::$attribute_with_label_pattern, $v, $matches)) {
$newValues[$matches['etiquette']][] = $matches['identifiant'];
$newValues[$matches['etiquette']][] = $matches['value'];
}
};
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)) {
if (preg_match("/^".$label."(?<value>.*)$/", $cv, $matches)) {
if(!in_array($matches['value'], $values)) {
$this->remove('supannRefId', $cv);
$cv = null;
}
......@@ -1738,15 +1738,15 @@ class People extends Entity
$newValues = [];
foreach ($value as $v) {
if (preg_match(self::$attribute_with_label_pattern, $v, $matches)) {
$newValues[$matches['etiquette']][] = $matches['identifiant'];
$newValues[$matches['etiquette']][] = $matches['value'];
}
};
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)) {
if (preg_match("/^".$label."(?<value>.+)$/", $cv, $matches)) {
if(!in_array($matches['value'], $values)) {
$this->remove('unicaenTermsOfUse', $cv);
$cv = null;
}
......@@ -1944,9 +1944,9 @@ class People extends Entity
if (is_string($val)) {
if (preg_match(self::$attribute_with_label_pattern, $val, $matches)) {
$prefixe = $this->service->getLdapStructureService()->getCodeModuleEnseignementPrefixe();
$val = (0 !== strpos($matches['identifiant'], $prefixe))
? $prefixe . $matches['identifiant']
: $matches['identifiant'];
$val = (0 !== strpos($matches['value'], $prefixe))
? $prefixe . $matches['value']
: $matches['value'];
return sprintf('%s%s', $matches['etiquette'], $val);
}
return null;
......@@ -1975,9 +1975,9 @@ class People extends Entity
if (is_string($val)) {
if (preg_match(self::$attribute_with_label_pattern, $val, $matches)) {
$prefixe = $this->service->getLdapStructureService()->getCodeModuleEnseignementPrefixe();
$val = (0 !== strpos($matches['identifiant'], $prefixe))
? $prefixe . $matches['identifiant']
: $matches['identifiant'];
$val = (0 !== strpos($matches['value'], $prefixe))
? $prefixe . $matches['value']
: $matches['value'];
return sprintf('%s%s', $matches['etiquette'], $val);
}
return null;
......
......@@ -220,11 +220,40 @@ class Structure extends Entity
public function setSupannRefId($value = null, $append = false)
{
$value = $this->preFormat($value);
$value = array_filter($value, function ($v) {
return preg_match(self::$attribute_with_label_pattern, $v);
});
$this->appendOrNot('supannRefId', $value, $append);
if(empty($value)) {
$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)) {
$newValues[$matches['etiquette']][] = $matches['value'];
}
};
foreach ($newValues as $label => $values) {
$currentValues = $this->preFormat($this->supannRefId);
array_walk($currentValues, function (&$cv) use ($label, $values) {
if (preg_match("/^".$label."(?<value>.*)$/", $cv, $matches)) {
if(!in_array($matches['value'], $values)) {
$this->remove('supannRefId', $cv);
$cv = null;
}
}
});
foreach($values as $v) {
$v = $label.$v;
if (!in_array($v, $currentValues)) {
$currentValues[] = $v;
}
}
$this->appendOrNot('supannRefId', array_filter($currentValues), false);
}
return $this;
}
......
......@@ -74,7 +74,7 @@ abstract class Entity
/**
* Liste des patterns génériques utilisés pour différents attributs
*/
static protected $attribute_with_label_pattern = '/^(?<etiquette>\{[\w\-:]+\})(?<identifiant>.+)$/';
static protected $attribute_with_label_pattern = '/^(?<etiquette>\{[\w\-:]+\})(?<value>.*)$/';
/**
* Liste des patterns spécifiques utilisés pour différents attributs
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment