Loading src/UnicaenLdap/Entity/Base/People.php +106 −9 Changes for src/UnicaenLdap/Entity/Base/People.php: 106 added lines, 9 removed lines. Original line number Diff line number Diff line Loading @@ -32,9 +32,11 @@ class People extends Entity 'person', 'eduPerson', 'supannPerson', 'posixAccount', 'sambaAccount', 'sambaSamAcount', 'posixAccount', "schacPersonalCharacteristics", "schacEntryMetadata" ]; /** Loading Loading @@ -71,7 +73,9 @@ class People extends Entity 'telephoneNumber', ]; static protected $role_pattern = '/^\[role={SUPANN}(.*)\]\[type={SUPANN}(.*)\]\[code=(.*)\]\[libelle=(.*)\]$/'; static protected $postal_address_pattern = '/(.*)\$(.*)\$(.*)\$(.*)\$(.*)\$(.*)/'; static protected $role_pattern = '/^\[role=(?<role>.+)\]\[type=(?<type>.+)\]\[code=(?<code>.+)\]\[libelle=(?<libelle>.+)\]$/'; static protected $role_src_pattern = '/^(?<code>[\d]{4});(?<libelle>.+)/'; /** Loading @@ -98,7 +102,7 @@ class People extends Entity */ private function preFormat($value) { if (is_scalar($value)) { if (is_scalar($value) || is_null($value)) { $value = [$value]; } Loading Loading @@ -266,7 +270,7 @@ class People extends Entity { $value = $this->preFormat($value); $value = array_filter($value, function ($v) { return preg_match('/.*\$.*\$.*\$.*\$.*\$.*/', $v); return preg_match(self::$postal_address_pattern, $v); }); $this->appendOrNot('postalAddress', $value, $append); Loading Loading @@ -603,15 +607,16 @@ class People extends Entity public function setSupannTypeEntiteAffectation($value = null, $append = false) { $value = $this->preFormat($value); $value = array_map(function ($val) { $supannLabel = $this->getLabel('SUPANN'); $value = array_map(function ($val) use ($supannLabel) { if (is_string($val)) { return sprintf('%s%s', $this->getLabel('SUPANN'), $val); return preg_match("/^$supannLabel.*$/", $val) ? $val : sprintf('%s%s', $supannLabel, $val); } else { return null; return false; } }, $value); $this->appendOrNot('supannTypeEntiteAffectation', $value, $append); $this->appendOrNot('supannTypeEntiteAffectation', array_filter($value), $append); return $this; } Loading @@ -629,7 +634,7 @@ class People extends Entity { $value = $this->preFormat($value); $value = array_map(function ($v) { list($identifiant, $domaine) = explode('@', strtolower($v)); list($identifiant, $domaine) = array_pad(explode('@', strtolower($v)), 2, null); if ($domaine != self::$etablissement_domaine) { $v = sprintf('%s@%s', $v, self::$etablissement_domaine); } Loading Loading @@ -731,6 +736,98 @@ class People extends Entity return $this; } /** * Attribut Ldap "supannRoleGenerique" * * @param array|string|null $value * @param bool $append * @return self * @throws Exception * @throws LdapException */ public function setSupannRoleGenerique($value = null, $append = false) { $value = $this->preFormat($value); $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 false; } }, $value); $this->appendOrNot('supannRoleGenerique', array_filter($value), $append); return $this; } /** * Attribut Ldap "supannRoleEntite" * * @param array|string|null $value * @param bool $append * @return self * @throws Exception * @throws LdapException */ public function setSupannRoleEntite($value = null, $append = false) { $value = $this->preFormat($value); $supannLabel = $this->getLabel('SUPANN'); $value = array_map(function ($v) use ($supannLabel) { if(preg_match(self::$role_pattern, $v, $matches)) { /** * @var string $role * @var string $type * @var string $code */ foreach(['role', 'type'] as $part) { $$part = preg_match("/^$supannLabel.*$/", $matches[$part]) ? $matches[$part] : sprintf('%s%s', $supannLabel, $matches[$part]); } $prefixe = $this->getService()->getCodeStructurePrefixe(); $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 false; } }, $value); $this->appendOrNot('supannRoleEntite', array_filter($value), $append); return $this; } /** * Attribut Ldap "supannRoleEntite" * * @param array|string|null $value * @param bool $append * @return self * @throws Exception * @throws LdapException */ public function setUcbnFonctionStructurelle($value = null, $append = false) { $value = $this->preFormat($value); $value = array_filter($value, function ($v) { return preg_match(self::$role_src_pattern, $v); }); $this->appendOrNot('ucbnFonctionStructurelle', $value, $append); return $this; } /** * Retourne les structures auxquelles appartiennent la personne * Loading Loading
src/UnicaenLdap/Entity/Base/People.php +106 −9 Changes for src/UnicaenLdap/Entity/Base/People.php: 106 added lines, 9 removed lines. Original line number Diff line number Diff line Loading @@ -32,9 +32,11 @@ class People extends Entity 'person', 'eduPerson', 'supannPerson', 'posixAccount', 'sambaAccount', 'sambaSamAcount', 'posixAccount', "schacPersonalCharacteristics", "schacEntryMetadata" ]; /** Loading Loading @@ -71,7 +73,9 @@ class People extends Entity 'telephoneNumber', ]; static protected $role_pattern = '/^\[role={SUPANN}(.*)\]\[type={SUPANN}(.*)\]\[code=(.*)\]\[libelle=(.*)\]$/'; static protected $postal_address_pattern = '/(.*)\$(.*)\$(.*)\$(.*)\$(.*)\$(.*)/'; static protected $role_pattern = '/^\[role=(?<role>.+)\]\[type=(?<type>.+)\]\[code=(?<code>.+)\]\[libelle=(?<libelle>.+)\]$/'; static protected $role_src_pattern = '/^(?<code>[\d]{4});(?<libelle>.+)/'; /** Loading @@ -98,7 +102,7 @@ class People extends Entity */ private function preFormat($value) { if (is_scalar($value)) { if (is_scalar($value) || is_null($value)) { $value = [$value]; } Loading Loading @@ -266,7 +270,7 @@ class People extends Entity { $value = $this->preFormat($value); $value = array_filter($value, function ($v) { return preg_match('/.*\$.*\$.*\$.*\$.*\$.*/', $v); return preg_match(self::$postal_address_pattern, $v); }); $this->appendOrNot('postalAddress', $value, $append); Loading Loading @@ -603,15 +607,16 @@ class People extends Entity public function setSupannTypeEntiteAffectation($value = null, $append = false) { $value = $this->preFormat($value); $value = array_map(function ($val) { $supannLabel = $this->getLabel('SUPANN'); $value = array_map(function ($val) use ($supannLabel) { if (is_string($val)) { return sprintf('%s%s', $this->getLabel('SUPANN'), $val); return preg_match("/^$supannLabel.*$/", $val) ? $val : sprintf('%s%s', $supannLabel, $val); } else { return null; return false; } }, $value); $this->appendOrNot('supannTypeEntiteAffectation', $value, $append); $this->appendOrNot('supannTypeEntiteAffectation', array_filter($value), $append); return $this; } Loading @@ -629,7 +634,7 @@ class People extends Entity { $value = $this->preFormat($value); $value = array_map(function ($v) { list($identifiant, $domaine) = explode('@', strtolower($v)); list($identifiant, $domaine) = array_pad(explode('@', strtolower($v)), 2, null); if ($domaine != self::$etablissement_domaine) { $v = sprintf('%s@%s', $v, self::$etablissement_domaine); } Loading Loading @@ -731,6 +736,98 @@ class People extends Entity return $this; } /** * Attribut Ldap "supannRoleGenerique" * * @param array|string|null $value * @param bool $append * @return self * @throws Exception * @throws LdapException */ public function setSupannRoleGenerique($value = null, $append = false) { $value = $this->preFormat($value); $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 false; } }, $value); $this->appendOrNot('supannRoleGenerique', array_filter($value), $append); return $this; } /** * Attribut Ldap "supannRoleEntite" * * @param array|string|null $value * @param bool $append * @return self * @throws Exception * @throws LdapException */ public function setSupannRoleEntite($value = null, $append = false) { $value = $this->preFormat($value); $supannLabel = $this->getLabel('SUPANN'); $value = array_map(function ($v) use ($supannLabel) { if(preg_match(self::$role_pattern, $v, $matches)) { /** * @var string $role * @var string $type * @var string $code */ foreach(['role', 'type'] as $part) { $$part = preg_match("/^$supannLabel.*$/", $matches[$part]) ? $matches[$part] : sprintf('%s%s', $supannLabel, $matches[$part]); } $prefixe = $this->getService()->getCodeStructurePrefixe(); $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 false; } }, $value); $this->appendOrNot('supannRoleEntite', array_filter($value), $append); return $this; } /** * Attribut Ldap "supannRoleEntite" * * @param array|string|null $value * @param bool $append * @return self * @throws Exception * @throws LdapException */ public function setUcbnFonctionStructurelle($value = null, $append = false) { $value = $this->preFormat($value); $value = array_filter($value, function ($v) { return preg_match(self::$role_src_pattern, $v); }); $this->appendOrNot('ucbnFonctionStructurelle', $value, $append); return $this; } /** * Retourne les structures auxquelles appartiennent la personne * Loading