Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
lib
unicaen
ldap
Commits
a6d29378
Commit
a6d29378
authored
Jan 22, 2014
by
Laurent Lécluse
Browse files
Mise en place de la structure de base et début d'implémentation de la couche fonctionnelle
parent
5fc2880e
Changes
6
Hide whitespace changes
Inline
Side-by-side
src/UnicaenLdap/Entity/Entity.php
View file @
a6d29378
...
...
@@ -46,8 +46,11 @@ abstract class Entity
public
static
function
getNodeParams
(
$type
)
{
$params
=
array
(
'Generic'
=>
array
(
'uid'
,
'UnicaenLdap\\Entity\\Generic'
),
'Group'
=>
array
(
'cn'
,
'UnicaenLdap\\Entity\\Group'
),
'People'
=>
array
(
'uid'
,
'UnicaenLdap\\Entity\\People'
),
'Structure'
=>
array
(
'supannCodeEntite'
,
'UnicaenLdap\\Entity\\Structure'
),
'System'
=>
array
(
'uid'
,
'UnicaenLdap\\Entity\\System'
),
);
if
(
!
isset
(
$params
[
$type
]))
throw
new
Exception
(
'Paramètres de "'
.
$type
.
'" non trouvés'
);
return
$params
[
$type
];
...
...
src/UnicaenLdap/Entity/People.php
View file @
a6d29378
...
...
@@ -2,6 +2,7 @@
namespace
UnicaenLdap\Entity
;
use
UnicaenLdap\Entity\Group
;
use
UnicaenLdap\Entity\Structure
;
use
DateTime
;
...
...
@@ -122,6 +123,82 @@ class People extends Entity
return
0
===
strpos
(
$this
->
uid
,
'i'
);
}
/**
* Retourne les structures auxquelles appartiennent la personne
*
* @return Structure[]
*/
public
function
getEduPersonOrgUnit
()
{
$structure
=
$this
->
getService
()
->
getServiceManager
()
->
get
(
'ldapServiceStructure'
);
$dn
=
$this
->
eduPersonOrgUnitDN
;
if
(
empty
(
$dn
))
return
null
;
return
$structure
->
getAllBy
(
$dn
,
'dn'
);
}
/**
* Retourne la structure principale à laquelle appartient la personne
*
* @return Structure
*/
public
function
getEduPersonPrimaryOrgUnit
()
{
$structure
=
$this
->
getService
()
->
getServiceManager
()
->
get
(
'ldapServiceStructure'
);
$dn
=
$this
->
eduPersonPrimaryOrgUnitDN
;
if
(
empty
(
$dn
))
return
null
;
return
$structure
->
getBy
(
$dn
,
'dn'
);
}
/**
* Retourne la structure d'affectation de la personne
* @todo à terminer
* @return Structure[]
*/
public
function
getEntiteAffectation
()
{
throw
new
\
Exception
(
'Méthode pas finie'
);
$structure
=
$this
->
getService
()
->
getServiceManager
()
->
get
(
'ldapServiceStructure'
);
$codes
=
$this
->
getNode
()
->
getAttribute
(
'supannEntiteAffectation'
);
var_dump
(
$codes
);
return
$structure
->
getBy
(
$dn
,
'dn'
);
}
/**
* Retourne la structure d'affectation de la personne
* @todo à terminer
* @return Structure
*/
public
function
getEntiteAffectationPrincipale
()
{
throw
new
\
Exception
(
'Méthode pas finie'
);
$structure
=
$this
->
getService
()
->
getServiceManager
()
->
get
(
'ldapServiceStructure'
);
$codes
=
array
();
$affectations
=
$this
->
getNode
()
->
getAttribute
(
'supannAffectation'
);
list
(
$code
,
$description
)
=
explode
(
';'
,
$this
->
supannAffectation
);
$code
=
$this
->
supannAffectation
;
if
(
empty
(
$dn
))
return
null
;
return
$structure
->
getBy
(
$dn
,
'dn'
);
}
/**
* Retourne la structure d'affectation de la personne
* @todo à terminer
* @return Structure
*/
public
function
getAffectationDescription
()
{
throw
new
\
Exception
(
'Méthode pas finie'
);
$structure
=
$this
->
getService
()
->
getServiceManager
()
->
get
(
'ldapServiceStructure'
);
list
(
$code
,
$description
)
=
explode
(
';'
,
$this
->
supannAffectation
);
$code
=
$this
->
supannAffectation
;
if
(
empty
(
$dn
))
return
null
;
return
$structure
->
getBy
(
$dn
,
'dn'
);
}
/**
* Retourne true si l'argument est au format "supannRoleEntite".
*
...
...
src/UnicaenLdap/Entity/Structure.php
View file @
a6d29378
<?php
namespace
UnicaenLdap\Entity
;
use
UnicaenLdap\Filter\Filter
;
/**
* Classe mère des structures de l'annuaire LDAP.
*
...
...
@@ -18,4 +20,52 @@ class Structure extends Entity
*/
protected
$dateTimeAttributes
=
array
(
);
/**
* Retourne la structure parente, si elle existe
*
* @return Structure[]
*/
public
function
getParents
()
{
if
(
null
!==
$parentIds
=
$this
->
get
(
'supannCodeEntiteParent'
)){
return
$this
->
service
->
getAll
(
$parentIds
);
}
return
null
;
}
/**
* Retourne la liste des structures filles
*
* @param string|Filter $filter Filtre éventuel
* @param string $orderBy Champ de tri
* @return Structure[]
*/
public
function
getChildren
(
$filter
=
null
,
$orderBy
=
null
)
{
$childrenFilter
=
Filter
::
equals
(
'supannCodeEntiteParent'
,
$this
->
getId
());
if
(
empty
(
$filter
)){
$filter
=
$childrenFilter
;
}
else
{
if
(
is_string
(
$filter
))
$filter
=
Filter
::
string
(
$filter
);
$filter
=
Filter
::
andFilter
(
$childrenFilter
,
$filter
);
}
return
$this
->
service
->
search
(
$filter
,
$orderBy
,
-
1
,
0
);
}
/**
* Retourne le code Harpège
*
* @return string
*/
public
function
getCodeHarpege
()
{
$code
=
$this
->
get
(
'supannCodeEntite'
);
if
(
0
===
strpos
(
$code
,
'HS_'
)){
return
substr
(
$code
,
3
);
}
else
{
return
null
;
// Ne retourne rien si le code ne correspond pas à la nomenclature Harpège
}
}
}
\ No newline at end of file
src/UnicaenLdap/Filter/Structure.php
0 → 100644
View file @
a6d29378
<?php
namespace
UnicaenLdap\Filter
;
/**
* Filtres pour les structures
*
* @author Laurent Lécluse <laurent.lecluse at unicaen.fr>
*/
class
Structure
extends
Filter
{
public
static
function
pedagogique
()
{
return
self
::
orFilter
(
self
::
equals
(
'supannTypeEntite'
,
'{SUPANN}F100'
),
// Diplômes
self
::
equals
(
'supannTypeEntite'
,
'{SUPANN}F200'
),
// ? ?
self
::
equals
(
'supannTypeEntite'
,
'{SUPANN}F300'
)
// Unités
);
}
/**
* Code ou liste de codes Harpège
*
* @param string|array $codes
*/
public
static
function
codeHarpege
(
$codes
)
{
if
(
is_string
(
$codes
)){
return
self
::
equals
(
'supannCodeEntite'
,
'HS_'
.
$codes
);
}
else
{
$filters
=
array
();
foreach
(
$codes
as
$code
){
$filters
[]
=
self
::
codeHarpege
(
$code
);
}
return
call_user_func_array
(
__CLASS__
.
'::orFilter'
,
$filters
);
}
}
}
\ No newline at end of file
src/UnicaenLdap/Service/Service.php
View file @
a6d29378
...
...
@@ -186,8 +186,11 @@ abstract class Service implements ServiceManagerAwareInterface
$i
=
0
;
ErrorHandler
::
start
(
E_WARNING
);
for
(
$entry
=
ldap_first_entry
(
$resource
,
$search
);
$entry
;
$entry
=
ldap_next_entry
(
$resource
,
$entry
))
{
$result
[]
=
ldap_get_values_len
(
$resource
,
$entry
,
$key
)[
0
];
$i
++
;
$value
=
ldap_get_values_len
(
$resource
,
$entry
,
$key
)[
0
];
if
(
null
!==
$value
){
$result
[]
=
$value
;
$i
++
;
}
if
(
$i
>
$limit
+
$offset
-
1
)
break
;
// Pas besoin d'aller plus loin...
}
ErrorHandler
::
stop
();
...
...
@@ -195,6 +198,7 @@ abstract class Service implements ServiceManagerAwareInterface
$result
=
array
();
}
$this
->
__searchEnd
(
$search
);
$this
->
count
=
count
(
$result
);
return
new
Collection
(
$this
,
array_slice
(
$result
,
$offset
,
$limit
)
);
}
...
...
@@ -415,6 +419,19 @@ abstract class Service implements ServiceManagerAwareInterface
}
}
/**
* Retourne un tableau d'entités de format array[ID] = Entite
*
* @param string[] $ids Tableau d'identifiants
* @param string $orderBy Nom d'attribut à trier
* @return Entity[]
*/
public
function
getAll
(
$ids
,
$orderBy
=
null
)
{
$key
=
Entity
::
getNodeParams
(
$this
->
type
)[
0
];
return
$this
->
getAllBy
(
$ids
,
$key
,
$orderBy
);
}
/**
* Retourne un tableau d'entités de format array[ID] = Entite
*
...
...
src/UnicaenLdap/Service/Structure.php
View file @
a6d29378
...
...
@@ -12,4 +12,14 @@ class Structure extends Service
protected
$type
=
'Structure'
;
protected
$ou
=
array
(
'structures'
);
/**
* Retourne la structure mère : Université
*
* @return UnicaenLdap\Entity\Structure
*/
public
function
getUniv
()
{
return
$this
->
get
(
'HS_UNIV'
);
}
}
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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