Commit a818b078 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 3363ee6b
Loading
Loading
Loading
Loading
+33 −4
Original line number Diff line number Diff line
@@ -283,11 +283,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;
    }
+12 −12
Original line number Diff line number Diff line
@@ -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;
+33 −4
Original line number Diff line number Diff line
@@ -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;
    }
+1 −1
Original line number Diff line number Diff line
@@ -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