Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
lib
unicaen
ldap
Commits
f6fd12e5
Commit
f6fd12e5
authored
Feb 12, 2019
by
David Surville
Browse files
Ajout des fonctions pour les attributs liés aux rôles/fonctions
parent
d7dd5347
Changes
1
Show whitespace changes
Inline
Side-by-side
src/UnicaenLdap/Entity/Base/People.php
View file @
f6fd12e5
...
@@ -32,9 +32,11 @@ class People extends Entity
...
@@ -32,9 +32,11 @@ class People extends Entity
'person'
,
'person'
,
'eduPerson'
,
'eduPerson'
,
'supannPerson'
,
'supannPerson'
,
'posixAccount'
,
'sambaAccount'
,
'sambaAccount'
,
'sambaSamAcount'
,
'sambaSamAcount'
,
'posixAccount'
,
"schacPersonalCharacteristics"
,
"schacEntryMetadata"
];
];
/**
/**
...
@@ -71,7 +73,9 @@ class People extends Entity
...
@@ -71,7 +73,9 @@ class People extends Entity
'telephoneNumber'
,
'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
...
@@ -98,7 +102,7 @@ class People extends Entity
*/
*/
private
function
preFormat
(
$value
)
private
function
preFormat
(
$value
)
{
{
if
(
is_scalar
(
$value
))
{
if
(
is_scalar
(
$value
)
||
is_null
(
$value
)
)
{
$value
=
[
$value
];
$value
=
[
$value
];
}
}
...
@@ -266,7 +270,7 @@ class People extends Entity
...
@@ -266,7 +270,7 @@ class People extends Entity
{
{
$value
=
$this
->
preFormat
(
$value
);
$value
=
$this
->
preFormat
(
$value
);
$value
=
array_filter
(
$value
,
function
(
$v
)
{
$value
=
array_filter
(
$value
,
function
(
$v
)
{
return
preg_match
(
'/.*\$.*\$.*\$.*\$.*\$.*/'
,
$v
);
return
preg_match
(
self
::
$postal_address_pattern
,
$v
);
});
});
$this
->
appendOrNot
(
'postalAddress'
,
$value
,
$append
);
$this
->
appendOrNot
(
'postalAddress'
,
$value
,
$append
);
...
@@ -603,15 +607,16 @@ class People extends Entity
...
@@ -603,15 +607,16 @@ class People extends Entity
public
function
setSupannTypeEntiteAffectation
(
$value
=
null
,
$append
=
false
)
public
function
setSupannTypeEntiteAffectation
(
$value
=
null
,
$append
=
false
)
{
{
$value
=
$this
->
preFormat
(
$value
);
$value
=
$this
->
preFormat
(
$value
);
$value
=
array_map
(
function
(
$val
)
{
$supannLabel
=
$this
->
getLabel
(
'SUPANN'
);
$value
=
array_map
(
function
(
$val
)
use
(
$supannLabel
)
{
if
(
is_string
(
$val
))
{
if
(
is_string
(
$val
))
{
return
sprintf
(
'%s%s'
,
$this
->
getLabel
(
'SUPANN'
)
,
$val
);
return
preg_match
(
"/^
$supannLabel
.*$/"
,
$val
)
?
$val
:
sprintf
(
'%s%s'
,
$supannLabel
,
$val
);
}
else
{
}
else
{
return
null
;
return
false
;
}
}
},
$value
);
},
$value
);
$this
->
appendOrNot
(
'supannTypeEntiteAffectation'
,
$value
,
$append
);
$this
->
appendOrNot
(
'supannTypeEntiteAffectation'
,
array_filter
(
$value
)
,
$append
);
return
$this
;
return
$this
;
}
}
...
@@ -628,15 +633,15 @@ class People extends Entity
...
@@ -628,15 +633,15 @@ class People extends Entity
public
function
setEduPersonPrincipalName
(
$value
=
null
,
$append
=
false
)
public
function
setEduPersonPrincipalName
(
$value
=
null
,
$append
=
false
)
{
{
$value
=
$this
->
preFormat
(
$value
);
$value
=
$this
->
preFormat
(
$value
);
$value
=
array_map
(
function
(
$v
)
{
$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
)
{
if
(
$domaine
!=
self
::
$etablissement_domaine
)
{
$v
=
sprintf
(
'%s@%s'
,
$v
,
self
::
$etablissement_domaine
);
$v
=
sprintf
(
'%s@%s'
,
$v
,
self
::
$etablissement_domaine
);
}
}
return
$v
;
return
$v
;
},
$value
);
},
$value
);
$value
=
array_filter
(
$value
,
function
(
$v
)
{
$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
);
$this
->
appendOrNot
(
'eduPersonPrincipalName'
,
$value
,
$append
);
...
@@ -731,6 +736,98 @@ class People extends Entity
...
@@ -731,6 +736,98 @@ class People extends Entity
return
$this
;
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
* Retourne les structures auxquelles appartiennent la personne
*
*
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment