Commit f6fd12e5 authored by David Surville's avatar David Surville
Browse files

Ajout des fonctions pour les attributs liés aux rôles/fonctions

parent d7dd5347
......@@ -32,9 +32,11 @@ class People extends Entity
'person',
'eduPerson',
'supannPerson',
'posixAccount',
'sambaAccount',
'sambaSamAcount',
'posixAccount',
"schacPersonalCharacteristics",
"schacEntryMetadata"
];
/**
......@@ -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>.+)/';
/**
......@@ -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];
}
......@@ -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);
......@@ -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;
}
......@@ -628,15 +633,15 @@ class People extends Entity
public function setEduPersonPrincipalName($value = null, $append = false)
{
$value = $this->preFormat($value);
$value = array_map(function($v) {
list($identifiant, $domaine) = explode('@', strtolower($v));
if($domaine != self::$etablissement_domaine) {
$value = array_map(function ($v) {
list($identifiant, $domaine) = array_pad(explode('@', strtolower($v)), 2, null);
if ($domaine != self::$etablissement_domaine) {
$v = sprintf('%s@%s', $v, self::$etablissement_domaine);
}
return $v;
}, $value);
$value = array_filter($value, function ($v) {
return preg_match('/^[0-9a-z\-]+@'.self::$etablissement_domaine.'$/', $v);
return preg_match('/^[0-9a-z\-]+@' . self::$etablissement_domaine . '$/', $v);
});
$this->appendOrNot('eduPersonPrincipalName', $value, $append);
......@@ -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
*
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment