Commit 80f41192 authored by surville's avatar surville
Browse files

[Evolution] Ajout des attributs : supannEtuInscription, ucbnSiteLocalisation,...

[Evolution] Ajout des attributs : supannEtuInscription, ucbnSiteLocalisation, ucbnAnneePostBac, ucbnPrivateAddress, ucbnPrivateAddresseBis, supannEtuTypeDiplome + pas mal de corrections
parent f7a511b6
Loading
Loading
Loading
Loading
+402 −27
Changes for src/UnicaenLdap/Entity/Base/People.php: 402 added lines, 27 removed lines.
Original line number Diff line number Diff line
@@ -234,9 +234,22 @@ class People extends Entity
     * 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 $role_pattern = '/^\[role=(?<role>[\w\-]+)\]\[type=(?<type>[\w\-]+)\]\[code=(?<code>[\w\-]+)\]\[libelle=(?<libelle>.+)\]$/';
    static protected $role_src_pattern = '/^(?<code>[\d]{4});(?<libelle>.+)$/';
    static protected $localisation_pattern = '/^(?<code>[\w\-]+);(?<libelle>.+)$/';
    static protected $etape_pattern = '/^(?<code>.+);(?<libelle>.+)$/';
    static protected $secteur_disciplinaire_pattern = '/^(?<code>\d+);(?<libelle>.+)$/';
    static protected $inscription_pattern =
        '/^\[etab=(?<etab>\{[\w\-:]+\}.+)\]' .
          '\[anneeinsc=(?<anneeinsc>\d{4})\]' .
          '\[regimeinsc=(?<regimeinsc>\{[\w\-:]+\}\w*)\]' . // {SISE}.* ou {INCONNU}
          '\[sectdisc=(?<sectdisc>\{[\w\-:]+\}\w*)\]' . // {SISE}.* ou {INCONNU}
          '\[typedip=(?<typedip>\{[\w\-:]+\}\w*)\]' . // {SISE}.* ou {INCONNU}
          '\[cursusann=(?<cursusann>\{SUPANN\}\w+)\]' .
          '\[affect=(?<affect>[\w\-]+)\]' .
          '\[diplome=(?<diplome>\{[\w\-:]+\}\w+)\]' .
          '\[etape=(?<etape>\{[\w\-:]+\}.+)\]$/';
    static protected $inscription_complement_pattern = '/^\[anneeinsc=(?<anneeinsc>\d{4})\]\[etape=(?<etape>\{[\w\-:]+\}.+)\]\[adistance=(?<adistance>\{[\w\-:]+\}\w{1})\]$/';
    static protected $role_pattern = '/^\[role=(?<role>\{SUPANN\}[\w\-]+)\]\[type=(?<type>\{SUPANN\}[\w\-]+)\]\[code=(?<code>[\w\-]+)\]\[libelle=(?<libelle>.+)\]$/';
    static protected $role_src_pattern = '/^(?<code>\d{4});(?<libelle>.+)$/';


    /**
@@ -585,7 +598,7 @@ class People extends Entity
    {
        $value = $this->preFormat($value);
        $value = array_filter($value, function ($v) {
            return preg_match('/^\d+$/', $v);
            return preg_match('/^\d{13}$/', $v);
        });

        $this->appendOrNot('leoCode', $value, $append);
@@ -649,6 +662,73 @@ class People extends Entity
        return $this;
    }

    /**
     * Attribut Ldap "supannEtuInscription"
     *
     * @param array|string|null $value
     * @param bool $append
     * @return self
     * @throws Exception
     * @throws LdapException
     */
    public function setSupannEtuInscription($value = null, $append = false)
    {
        $value = $this->preFormat($value);

        $supannLabel = $this->getLabel('SUPANN');
        $siseLabel = $this->getLabel('SISE');
        $inconnuLabel = $this->getLabel('INCONNU');
        $value = array_map(function ($v) use ($supannLabel, $siseLabel, $inconnuLabel) {
            if (preg_match(self::$inscription_pattern, $v, $matches)) {
                /**
                 * @var string $etab
                 * @var string $anneeinsc
                 * @var string $regimeinsc
                 * @var string $sectdisc
                 * @var string $typedip
                 * @var string $cursusann
                 * @var string $affect
                 * @var string $diplome
                 * @var string $etape
                 */
                foreach (['regimeinsc', 'sectdisc', 'typedip'] as $part) {
                    $$part = preg_match("/^($siseLabel|$inconnuLabel)\w*$/", $matches[$part])
                        ? $matches[$part]
                        : sprintf('%s%s', $siseLabel, $matches[$part]);
                }
                foreach (['cursusann'] as $part) {
                    $$part = preg_match("/^$supannLabel\w+$/", $matches[$part])
                        ? $matches[$part]
                        : sprintf('%s%s', $supannLabel, $matches[$part]);
                }

                $prefixe = $this->getService()->getCodeStructurePrefixe();
                $affect = (0 !== strpos($matches['affect'], $prefixe))
                    ? sprintf('%s%s', $structure_prefixe, $matches['affect'])
                    : $matches['affect'];

                $prefixe = $this->getService()->getCodeModuleEnseignementPrefixe();
                preg_match('/^(?<etiquette>\{[\w\-:]+\})(?<identifiant>.+)$/', $matches['etape'], $parts);
                $val = (0 !== strpos($parts['identifiant'], $prefixe))
                    ? $prefixe . $parts['identifiant']
                    : $parts['identifiant'];
                $etape = sprintf('%s%s', $parts['etiquette'], $val);

                return preg_replace(
                    self::$inscription_pattern,
                    "[etab=\\1][anneeinsc=\\2][regimeinsc=$regimeinsc][sectdisc=$sectdisc][typedip=$typedip][cursusann=$cursusann][affect=$affect][diplome=\\8][etape=$etape]",
                    $v, 1);
            } else {
                return null;
            }

        }, $value);

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

        return $this;
    }

    /**
     * Attribut Ldap "supannCodeINE"
     *
@@ -663,7 +743,7 @@ class People extends Entity
        $value = $this->preFormat($value);
        $value = array_map('strtoupper', $value);
        $value = array_filter($value, function ($v) {
            return preg_match('/^[0-9]{10}[A-Z]{1}$/', $v);
            return preg_match('/^[\w]{11}$/', $v);
        });

        $this->appendOrNot('supannCodeINE', $value, $append);
@@ -831,10 +911,14 @@ 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);
            } else {
                return null;
                if(preg_match("/^".$supannLabel."[\w\-]+$/", $val)) {
                    return $val;
                }
                elseif(preg_match("/^[\w\-]+$/", $val)) {
                    return sprintf('%s%s', $supannLabel, $val);
                }
            }
            return null;
        }, $value);

        $this->appendOrNot('supannTypeEntiteAffectation', array_filter($value), $append);
@@ -842,6 +926,27 @@ class People extends Entity
        return $this;
    }

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

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

        return $this;
    }

    /**
     * Attribut Ldap "ucbnSousStructure"
     *
@@ -1028,10 +1133,14 @@ 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);
            } else {
                return null;
                if(preg_match("/^".$supannLabel."[\w\-]+$/", $val)) {
                    return $val;
                }
                elseif(preg_match("/^[\w\-]+$/", $val)) {
                    return sprintf('%s%s', $supannLabel, $val);
                }
            }
            return null;
        }, $value);

        $this->appendOrNot('supannRoleGenerique', array_filter($value), $append);
@@ -1061,7 +1170,7 @@ class People extends Entity
                 * @var string $code
                 */
                foreach (['role', 'type'] as $part) {
                    $$part = preg_match("/^$supannLabel.+$/", $matches[$part])
                    $$part = preg_match("/^".$supannLabel."[\w\-]+$/", $matches[$part])
                        ? $matches[$part]
                        : sprintf('%s%s', $supannLabel, $matches[$part]);
                }
@@ -1070,6 +1179,7 @@ class People extends Entity
                $code = (0 !== strpos($matches['code'], $prefixe))
                    ? sprintf('%s%s', $prefixe, $matches['code'])
                    : $matches['code'];

                return preg_replace(self::$role_pattern, "[role=$role][type=$type][code=$code][libelle=\\4]", $v, 1);
            } else {
                return null;
@@ -1082,6 +1192,90 @@ class People extends Entity
        return $this;
    }

    /**
     * Attribut Ldap "ucbnAnneePostBac"
     *
     * @param array|string|null $value
     * @param bool $append
     * @return $this
     * @throws Exception
     * @throws LdapException
     */
    public function setUcbnAnneePostBac($value = null, $append = false)
    {
        $value = $this->preFormat($value);
        $value = array_filter($value, function ($v) {
            return preg_match('/^\d{1}$/', $v);
        });

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

        return $this;
    }

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

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

        return $this;
    }

    /**
     * Attribut Ldap "ucbnEtuComplementInscription"
     *
     * @param array|string|null $value
     * @param bool $append
     * @return self
     * @throws Exception
     * @throws LdapException
     */
    public function setUcbnEtuComplementInscription($value = null, $append = false)
    {
        $value = $this->preFormat($value);

        $value = array_map(function ($v) {
            if (preg_match(self::$inscription_complement_pattern, $v, $matches)) {
                /**
                 * @var string $anneeinsc
                 * @var string $etape
                 * @var string $adistance
                 */
                $prefixe = $this->getService()->getCodeModuleEnseignementPrefixe();
                preg_match('/^(?<etiquette>\{[\w\-:]+\})(?<identifiant>.+)$/', $matches['etape'], $parts);
                $val = (0 !== strpos($parts['identifiant'], $prefixe))
                    ? $prefixe . $parts['identifiant']
                    : $parts['identifiant'];
                $etape = sprintf('%s%s', $parts['etiquette'], $val);

                return preg_replace(
                    self::$inscription_pattern,
                    "[anneeinsc=\\1][etape=$etape][adistance=\\3]",
                    $v, 1);
            } else {
                return null;
            }

        }, $value);

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

        return $this;
    }

    /**
     * Attribut Ldap "ucbnFonctionStructurelle"
     *
@@ -1104,6 +1298,48 @@ class People extends Entity
        return $this;
    }

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

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

        return $this;
    }

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

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

        return $this;
    }

    /**
     * Attribut Ldap "supannParrainDN"
     *
@@ -1250,10 +1486,14 @@ class People extends Entity
        $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;
                if(preg_match("/^$corpsLabel\w+$/", $val)) {
                    return $val;
                }
                elseif(preg_match("/^\w+$/", $val)) {
                    return sprintf('%s%s', $corpsLabel, $val);
                }
            }
            return null;
        }, $value);

        $this->appendOrNot('supannEmpCorps', array_filter($value), $append);
@@ -1295,10 +1535,10 @@ class People extends Entity
    {
        $value = $this->preFormat($value);
        $value = array_filter($value, function ($v) {
            return preg_match('/\d{4}/', $v);
            return preg_match('/^\d{4}$/', $v);
        });

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

        return $this;
    }
@@ -1318,10 +1558,14 @@ class People extends Entity
        $supannLabel = $this->getLabel('SUPANN');
        $value = array_map(function ($val) use ($supannLabel) {
            if (is_string($val)) {
                return preg_match("/^".$supannLabel."[\d]{4}$/", $val) ? $val : sprintf('%s%s', $supannLabel, $val);
            } else {
                return null;
                if(preg_match("/^$supannLabel\w+$/", $val)) {
                    return $val;
                }
                elseif(preg_match("/^\w+$/", $val)) {
                    return sprintf('%s%s', $supannLabel, $val);
                }
            }
            return null;
        }, $value);

        $this->appendOrNot('supannEtuCursusAnnee', array_filter($value), $append);
@@ -1362,11 +1606,142 @@ class People extends Entity
    public function setSupannEtuEtape($value = null, $append = false)
    {
        $value = $this->preFormat($value);
        $value = array_filter($value, function ($v) {
            return preg_match(self::$attribute_with_label_pattern, $v);
        });
        $value = array_map(function ($val) {
            if (is_string($val)) {
                if(preg_match(self::$attribute_with_label_pattern, $val, $matches)) {
                    $prefixe = $this->getService()->getCodeModuleEnseignementPrefixe();
                    $val = (0 !== strpos($matches['identifiant'], $prefixe))
                        ? $prefixe . $matches['identifiant']
                        : $matches['identifiant'];
                    return sprintf('%s%s', $matches['etiquette'], $val);
                }
                return null;
            }
            return null;
        }, $value);

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

        return $this;
    }

    /**
     * Attribut Ldap "supannEtuElementPedagogique"
     *
     * @param array|string|null $value
     * @param bool $append
     * @return $this
     * @throws Exception
     * @throws LdapException
     */
    public function setSupannEtuElementPedagogique($value = null, $append = false)
    {
        $value = $this->preFormat($value);
        $value = array_map(function ($val) {
            if (is_string($val)) {
                if(preg_match(self::$attribute_with_label_pattern, $val, $matches)) {
                    $prefixe = $this->getService()->getCodeModuleEnseignementPrefixe();
                    $val = (0 !== strpos($matches['identifiant'], $prefixe))
                        ? $prefixe . $matches['identifiant']
                        : $matches['identifiant'];
                    return sprintf('%s%s', $matches['etiquette'], $val);
                }
                return null;
            }
            return null;
        }, $value);

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

        return $this;
    }

    /**
     * Attribut Ldap "supannEtuRegimeInscription"
     *
     * @param array|string|null $value
     * @param bool $append
     * @return $this
     * @throws Exception
     * @throws LdapException
     */
    public function setSupannEtuRegimeInscription($value = null, $append = false)
    {
        $value = $this->preFormat($value);
        $siseLabel = $this->getLabel('SISE');
        $value = array_map(function ($val) use ($siseLabel) {
            if (is_string($val)) {
                if(preg_match("/^$siseLabel\w+$/", $val)) {
                    return $val;
                }
                elseif(preg_match("/^\w+$/", $val)) {
                    return sprintf('%s%s', $siseLabel, $val);
                }
            }
            return null;
        }, $value);

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

        return $this;
    }

    /**
     * Attribut Ldap "supannEtuSecteurDisciplinaire"
     *
     * @param array|string|null $value
     * @param bool $append
     * @return $this
     * @throws Exception
     * @throws LdapException
     */
    public function setSupannEtuSecteurDisciplinaire($value = null, $append = false)
    {
        $value = $this->preFormat($value);
        $siseLabel = $this->getLabel('SISE');
        $value = array_map(function ($val) use ($siseLabel) {
            if (is_string($val)) {
                if(preg_match("/^$siseLabel\w+$/", $val)) {
                    return $val;
                }
                elseif(preg_match("/^\w+$/", $val)) {
                    return sprintf('%s%s', $siseLabel, $val);
                }
            }
            return null;
        }, $value);

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

        return $this;
    }

    /**
     * Attribut Ldap "supannEtuTypeDiplome"
     *
     * @param array|string|null $value
     * @param bool $append
     * @return $this
     * @throws Exception
     * @throws LdapException
     */
    public function setSupannEtuTypeDiplome($value = null, $append = false)
    {
        $value = $this->preFormat($value);
        $siseLabel = $this->getLabel('SISE');
        $value = array_map(function ($val) use ($siseLabel) {
            if (is_string($val)) {
                if(preg_match("/^$siseLabel\w+$/", $val)) {
                    return $val;
                }
                elseif(preg_match("/^\w+$/", $val)) {
                    return sprintf('%s%s', $siseLabel, $val);
                }
            }
            return null;
        }, $value);

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

        return $this;
    }
@@ -1384,7 +1759,7 @@ class People extends Entity
    {
        $value = $this->preFormat($value);
        $value = array_filter($value, function ($v) {
            return preg_match('/[0-9]+/', $v);
            return preg_match('/^\d+$/', $v);
        });
        $this->appendOrNot('rid', $value, $append);

@@ -1421,7 +1796,7 @@ class People extends Entity
    {
        $value = $this->preFormat($value);
        $value = array_filter($value, function ($v) {
            return preg_match('/[0-9]+/', $v);
            return preg_match('/^\d+$/', $v);
        });
        $this->appendOrNot('uidNumber', $value, $append);

@@ -1441,7 +1816,7 @@ class People extends Entity
    {
        $value = $this->preFormat($value);
        $value = array_filter($value, function ($v) {
            return preg_match('/[0-9]+/', $v);
            return preg_match('/^\d+$/', $v);
        });
        $this->appendOrNot('gidNumber', $value, $append);

+3 −3
Changes for src/UnicaenLdap/Entity/Entity.php: 3 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -76,7 +76,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\-:]+\})(?<identifiant>.+)$/';

    /**
     * Liste des patterns spécifiques utilisés pour différents attributs
@@ -493,7 +493,7 @@ abstract class Entity
            return null;
        }

        $num = preg_replace('/\s+/', '', $num);
        $num = preg_replace('/[\.\-\s]+/', '', $num);

        return preg_match("/0\d{9}/", $num)
            ? preg_replace("/0(\d{1})(\d{2})(\d{2})(\d{2})(\d{2})/", "+33 $1 $2 $3 $4 $5", $num)
@@ -545,7 +545,7 @@ abstract class Entity
            $value = [$value];
        }

        $value = array_filter($value);
        $value = array_filter($value, 'strlen'); // Delete NULL, '' and FALSE values

        return $value;
    }