Commit 41fb1f8b authored by David Surville's avatar David Surville
Browse files

Gestions des attributs 'supannActivite', 'ucbnSecteurDisciplinaire' et 'supannEmpCorps'

parent fba6e707
Loading
Loading
Loading
Loading
+135 −47
Changes for src/UnicaenLdap/Entity/Base/People.php: 135 added lines, 47 removed lines.
Original line number Diff line number Diff line
@@ -4,7 +4,8 @@ namespace UnicaenLdap\Entity\Base;

use DateTime;
use UnicaenLdap\Entity\Entity;
use UnicaenLdap\Entity\Structure;
use UnicaenLdap\Entity\People as PeopleEntity;
use UnicaenLdap\Entity\Structure as StructureEntity;
use UnicaenLdap\Exception;
use Zend\Ldap\Dn;
use Zend\Ldap\Exception\LdapException;
@@ -222,13 +223,18 @@ class People extends Entity
    ];

    /**
     * Liste des patterns utilisés pour différents attributs
     * Liste des patterns génériques utilisés pour différents attributs
     */
    static protected $attribute_with_label_pattern = '/^\{(?<etiquette>[\w-:]+)\}(?<identifiant>.+)$/';

    /**
     * Liste des patterns spécifiques utilisés pour différents attributs
     */
    static protected $structure_pattern = '/^(?<code>[\w-]+);(?<libelle>.+)$/';
    static protected $secteur_disciplinaire_pattern = '/^(?<code>[\d]+);(?<libelle>.+)$/';
    static protected $postal_address_pattern = '/^(.*)\$(.*)\$(.*)\$(.*)\$(.*)\$(.*)$/';
    static protected $role_pattern = '/^\[role=(?<role>[\w-]+)\]\[type=(?<type>[\w-]+)\]\[code=(?<code>[\w-]+)\]\[libelle=(?<libelle>.+)\]$/';
    static protected $role_src_pattern = '/^(?<code>[\d]{4});(?<libelle>.+)$/';
    static protected $refid_pattern = '/^\{(?<etiquette>[\w-:]+)\}(?<identifiant>.+)$/';


    /**
@@ -240,7 +246,7 @@ class People extends Entity
     * @throws Exception
     * @throws LdapException
     */
    private function appendOrNot($attrName, $value, $append)
    protected function appendOrNot($attrName, $value, $append)
    {
        (!$append)
            ? $this->set($attrName, $value)
@@ -253,7 +259,7 @@ class People extends Entity
     * @param mixed $value
     * @return array
     */
    private function preFormat($value)
    protected function preFormat($value)
    {
        if (is_scalar($value)
            || is_null($value)
@@ -760,7 +766,7 @@ class People extends Entity
    /**
     * Attribut Ldap "supannAffectation"
     *
     * @param array|string|Structure|null $value
     * @param array|string|StructureEntity|null $value
     * @param bool $append
     * @return self
     * @throws Exception
@@ -771,15 +777,16 @@ class People extends Entity
        $value = $this->preFormat($value);
        $value = array_map(function ($val) {
            if (is_string($val)) {
                return preg_match('/.+;.+/', $val) ? $val : null;
            } elseif ($val instanceof Structure) {
                return sprintf('%s;%s', substr($val->get('supannCodeEntite'), 3), $val->get('description'));
                return preg_match(self::$structure_pattern, $val) ? $val : null;
            } elseif ($val instanceof StructureEntity) {
                $val = sprintf('%s;%s', strtr($val->get('supannCodeEntite'), $this->getService()->getCodeStructurePrefixe(), ''), $val->get('description'));
                return preg_match(self::$structure_pattern, $val) ? $val : null;
            } else {
                return null;
            }
        }, $value);

        $this->appendOrNot('supannAffectation', $value, $append);
        $this->appendOrNot('supannAffectation', array_filter($value), $append);

        return $this;
    }
@@ -787,7 +794,7 @@ class People extends Entity
    /**
     * Attribut Ldap "supannEntiteAffectation"
     *
     * @param array|string|Structure|null $value
     * @param array|string|StructureEntity|null $value
     * @param bool $append
     * @return self
     * @throws Exception
@@ -802,14 +809,14 @@ class People extends Entity
                    $val = $this->getService()->getCodeStructurePrefixe() . $val;
                }
                return $val;
            } elseif ($val instanceof Structure) {
            } elseif ($val instanceof StructureEntity) {
                return $val->get('supannCodeEntite');
            } else {
                return null;
            }
        }, $value);

        $this->appendOrNot('supannEntiteAffectation', $value, $append);
        $this->appendOrNot('supannEntiteAffectation', array_filter($value), $append);

        return $this;
    }
@@ -817,7 +824,7 @@ class People extends Entity
    /**
     * Attribut Ldap "supannEntiteAffectationPrincipale"
     *
     * @param array|string|Structure|null $value
     * @param array|string|StructureEntity|null $value
     * @param bool $append
     * @return self
     * @throws Exception
@@ -832,14 +839,14 @@ class People extends Entity
                    $val = $this->getService()->getCodeStructurePrefixe() . $val;
                }
                return $val;
            } elseif ($val instanceof Structure) {
            } elseif ($val instanceof StructureEntity) {
                return $val->get('supannCodeEntite');
            } else {
                return null;
            }
        }, $value);

        $this->appendOrNot('supannEntiteAffectationPrincipale', $value, $append);
        $this->appendOrNot('supannEntiteAffectationPrincipale', array_filter($value), $append);

        return $this;
    }
@@ -859,9 +866,9 @@ class People extends Entity
        $supannLabel = $this->getLabel('SUPANN');
        $value = array_map(function ($val) use ($supannLabel) {
            if (is_string($val)) {
                return preg_match("/^$supannLabel.*$/", $val) ? $val : sprintf('%s%s', $supannLabel, $val);
                return preg_match("/^$supannLabel.+$/", $val) ? $val : sprintf('%s%s', $supannLabel, $val);
            } else {
                return false;
                return null;
            }
        }, $value);

@@ -873,7 +880,7 @@ class People extends Entity
    /**
     * Attribut Ldap "ucbnSousStructure"
     *
     * @param array|string|null $value
     * @param array|string|StructureEntity|null $value
     * @param bool $append
     * @return self
     * @throws Exception
@@ -882,12 +889,18 @@ class People extends Entity
    public function setUcbnSousStructure($value = null, $append = false)
    {
        $value = $this->preFormat($value);
        $value = array_filter($value, function ($v) {
            return preg_match(self::$structure_pattern, $v);

        });
        $value = array_map(function ($val) {
            if (is_string($val)) {
                return preg_match(self::$structure_pattern, $val) ? $val : null;
            } elseif ($val instanceof StructureEntity) {
                $val = sprintf('%s;%s', strtr($val->get('supannCodeEntite'), $this->getService()->getCodeStructurePrefixe(), ''), $val->get('description'));
                return preg_match(self::$structure_pattern, $val) ? $val : null;
            } else {
                return null;
            }
        }, $value);

        $this->appendOrNot('ucbnSousStructure', $value, $append);
        $this->appendOrNot('ucbnSousStructure', array_filter($value), $append);

        return $this;
    }
@@ -895,7 +908,7 @@ class People extends Entity
    /**
     * Attribut Ldap "ucbnStructureRecherche"
     *
     * @param array|string|null $value
     * @param array|string|StructureEntity|null $value
     * @param bool $append
     * @return self
     * @throws Exception
@@ -904,12 +917,18 @@ class People extends Entity
    public function setUcbnStructureRecherche($value = null, $append = false)
    {
        $value = $this->preFormat($value);
        $value = array_filter($value, function ($v) {
            return preg_match(self::$structure_pattern, $v);

        });
        $value = array_map(function ($val) {
            if (is_string($val)) {
                return preg_match(self::$structure_pattern, $val) ? $val : null;
            } elseif ($val instanceof StructureEntity) {
                $val = sprintf('%s;%s', strtr($val->get('supannCodeEntite'), $this->getService()->getCodeStructurePrefixe(), ''), $val->get('description'));
                return preg_match(self::$structure_pattern, $val) ? $val : null;
            } else {
                return null;
            }
        }, $value);

        $this->appendOrNot('ucbnStructureRecherche', $value, $append);
        $this->appendOrNot('ucbnStructureRecherche', array_filter($value), $append);

        return $this;
    }
@@ -945,7 +964,7 @@ class People extends Entity
    /**
     * Attribut Ldap "eduPersonOrgDN"
     *
     * @param array|string|Dn|Structure|null $value
     * @param array|string|Dn|StructureEntity|null $value
     * @param bool $append
     * @return self
     * @throws Exception
@@ -959,14 +978,14 @@ class People extends Entity
                return Dn::checkDn($val) ? $val : null;
            } elseif ($val instanceof Dn) {
                return $val->toString();
            } elseif ($val instanceof Structure) {
            } elseif ($val instanceof StructureEntity) {
                return $val->getDn();
            } else {
                return null;
            }
        }, $value);

        $this->appendOrNot('eduPersonOrgDN', $value, $append);
        $this->appendOrNot('eduPersonOrgDN', array_filter($value), $append);

        return $this;
    }
@@ -974,7 +993,7 @@ class People extends Entity
    /**
     * Attribut Ldap "eduPersonOrgUnitDN"
     *
     * @param array|string|Dn|Structure|null $value
     * @param array|string|Dn|StructureEntity|null $value
     * @param bool $append
     * @return self
     * @throws Exception
@@ -988,14 +1007,14 @@ class People extends Entity
                return Dn::checkDn($val) ? $val : null;
            } elseif ($val instanceof Dn) {
                return $val->toString();
            } elseif ($val instanceof Structure) {
            } elseif ($val instanceof StructureEntity) {
                return $val->getDn();
            } else {
                return null;
            }
        }, $value);

        $this->appendOrNot('eduPersonOrgUnitDN', $value, $append);
        $this->appendOrNot('eduPersonOrgUnitDN', array_filter($value), $append);

        return $this;
    }
@@ -1003,7 +1022,7 @@ class People extends Entity
    /**
     * Attribut Ldap "eduPersonPrimaryOrgUnitDN"
     *
     * @param array|string|Dn|Structure|null $value
     * @param array|string|Dn|StructureEntity|null $value
     * @param bool $append
     * @return self
     * @throws Exception
@@ -1017,14 +1036,14 @@ class People extends Entity
                return Dn::checkDn($val) ? $val : null;
            } elseif ($val instanceof Dn) {
                return $val->toString();
            } elseif ($val instanceof Structure) {
            } elseif ($val instanceof StructureEntity) {
                return $val->getDn();
            } else {
                return null;
            }
        }, $value);

        $this->appendOrNot('eduPersonPrimaryOrgUnitDN', $value, $append);
        $this->appendOrNot('eduPersonPrimaryOrgUnitDN', array_filter($value), $append);

        return $this;
    }
@@ -1044,9 +1063,9 @@ class People extends Entity
        $supannLabel = $this->getLabel('SUPANN');
        $value = array_map(function ($val) use ($supannLabel) {
            if (is_string($val)) {
                return preg_match("/^$supannLabel.*$/", $val) ? $val : sprintf('%s%s', $supannLabel, $val);
                return preg_match("/^$supannLabel.+$/", $val) ? $val : sprintf('%s%s', $supannLabel, $val);
            } else {
                return false;
                return null;
            }
        }, $value);

@@ -1077,7 +1096,7 @@ class People extends Entity
                 * @var string $code
                 */
                foreach (['role', 'type'] as $part) {
                    $$part = preg_match("/^$supannLabel.*$/", $matches[$part])
                    $$part = preg_match("/^$supannLabel.+$/", $matches[$part])
                        ? $matches[$part]
                        : sprintf('%s%s', $supannLabel, $matches[$part]);
                }
@@ -1088,7 +1107,7 @@ class People extends Entity
                    : $matches['code'];
                return preg_replace(self::$role_pattern, "[role=$role][type=$type][code=$code][libelle=\\4]", $v, 1);
            } else {
                return false;
                return null;
            }

        }, $value);
@@ -1123,7 +1142,7 @@ class People extends Entity
    /**
     * Attribut Ldap "supannParrainDN"
     *
     * @param array|string|Dn|Structure|null $value
     * @param array|string|Dn|PeopleEntity|null $value
     * @param bool $append
     * @return self
     * @throws Exception
@@ -1137,14 +1156,14 @@ class People extends Entity
                return Dn::checkDn($val) ? $val : null;
            } elseif ($val instanceof Dn) {
                return $val->toString();
            } elseif ($val instanceof \UnicaenLdap\Entity\People) {
            } elseif ($val instanceof PeopleEntity) {
                return $val->getDn();
            } else {
                return null;
            }
        }, $value);

        $this->appendOrNot('supannParrainDN', $value, $append);
        $this->appendOrNot('supannParrainDN', array_filter($value), $append);

        return $this;
    }
@@ -1162,7 +1181,7 @@ class People extends Entity
    {
        $value = $this->preFormat($value);
        $value = array_filter($value, function ($v) {
            return preg_match(self::$refid_pattern, $v);
            return preg_match(self::$attribute_with_label_pattern, $v);
        });

        $this->appendOrNot('supannRefId', $value, $append);
@@ -1209,6 +1228,75 @@ class People extends Entity
        return $this;
    }

    /**
     * Attribut Ldap "supannActivite"
     *
     * @param array|string|null $value
     * @param bool $append
     * @return $this
     * @throws Exception
     * @throws LdapException
     */
    public function setSupannActivite($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('supannActivite', $value, $append);

        return $this;
    }

    /**
     * Attribut Ldap "ucbnSecteurDisciplinaire"
     *
     * @param array|string|null $value
     * @param bool $append
     * @return $this
     * @throws Exception
     * @throws LdapException
     */
    public function setUcbnSecteurDisciplinaire($value = null, $append = false)
    {
        $value = $this->preFormat($value);
        $value = array_filter($value, function ($v) {
            return preg_match(self::$secteur_disciplinaire_pattern, $v);

        });

        $this->appendOrNot('ucbnSecteurDisciplinaire', $value, $append);

        return $this;
    }

    /**
     * Attribut Ldap "supannEmpCorps"
     *
     * @param array|string|null $value
     * @param bool $append
     * @return $this
     * @throws Exception
     * @throws LdapException
     */
    public function setSupannEmpCorps($value = null, $append = false)
    {
        $value = $this->preFormat($value);
        $corpsLabel = $this->getLabel('NCORPS');
        $value = array_map(function ($val) use ($corpsLabel) {
            if (is_string($val)) {
                return preg_match("/^$corpsLabel.+$/", $val) ? $val : sprintf('%s%s', $corpsLabel, $val);
            } else {
                return null;
            }
        }, $value);

        $this->appendOrNot('supannEmpCorps', array_filter($value), $append);

        return $this;
    }

    /**
     * Retourne les structures auxquelles appartiennent la personne
     *
+3 −2
Changes for src/UnicaenLdap/Entity/Entity.php: 3 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -190,11 +190,12 @@ abstract class Entity
    /**
     * Retourne la liste des attributs de l'entité
     *
     * @param  bool $includeSystemAttributes
     * @return string[]
     */
    public function getAttributesList()
    public function getAttributesList($includeSystemAttributes = true)
    {
        return array_keys($this->getNode()->getAttributes());
        return array_keys($this->getNode()->getAttributes($includeSystemAttributes));
    }

    /**