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
5e14d817
Commit
5e14d817
authored
Oct 01, 2020
by
David Surville
Browse files
[Evolution] Ajout des fonctions de renommage et de suppression d'une entité Ldap
parent
0aa94c78
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/UnicaenLdap/Entity/Entity.php
View file @
5e14d817
...
...
@@ -186,6 +186,20 @@ abstract class Entity
return
$this
->
getNode
()
->
getDnString
();
}
/**
* Retourne l'Organizational Unit (OU) de l'entité
*
* @return string
*/
public
function
getOu
()
{
if
(
$result
=
$this
->
getNode
()
->
getDn
()
->
get
(
1
))
{
return
$result
[
'ou'
];
}
return
null
;
}
/**
* Retourne le nom de la clé primaire correspondant à l'entité
*
...
...
@@ -296,6 +310,9 @@ abstract class Entity
/**
* Affecte une nouvelle valeur à un attribut
*
* This is an offline method.
* Node will be updated on calling update().
*
* @param string $attrName
* @param mixed $value
* @return self
...
...
@@ -339,6 +356,9 @@ abstract class Entity
* Ajoute une valeur à un attribut
* Si l'attribut est monovalué, la valeur actuelle est remplacée par la nouvelle valeur
*
* This is an offline method.
* Node will be updated on calling update().
*
* @param string $attrName
* @param mixed $value
* @return self
...
...
@@ -368,6 +388,9 @@ abstract class Entity
/**
* Retire une valeur à un attribut
*
* This is an offline method.
* Node will be updated on calling update().
*
* @param string $attrName
* @param mixed|array $value
* @return self
...
...
@@ -382,6 +405,9 @@ abstract class Entity
/**
* Ajoute ou affecte une valeur à un attribut Ldap
*
* This is an offline method.
* Node will be updated on calling update().
*
* @param string $attrName
* @param mixed $value
* @param bool $append
...
...
@@ -441,21 +467,54 @@ abstract class Entity
}
/**
*
Mise à jour
de l'entité
*
Déplacement
de l'entité
dans un autre OU (Organizational Unit)
*
* @return self
* @throws LdapException
* This is an offline method.
* Node will be moved on calling update().
*
* @param string | Dn $newDn
* @throws \Zend\Ldap\Exception\LdapException
*/
public
function
update
(
)
public
function
move
(
string
$newOu
)
{
$this
->
getNode
()
->
update
();
$arrayOu
=
$this
->
getService
()
->
getOu
();
if
(
empty
(
$arrayOu
)
||
!
in_array
(
$newOu
,
$arrayOu
))
{
throw
new
Exception
(
sprintf
(
"L'entité ne peut être déplacée dans l'OU '%s'."
,
$newOu
));
}
if
(
$newOu
==
$this
->
getOu
())
{
throw
new
Exception
(
sprintf
(
"L'entité est déjà présente dans l'OU '%s'."
,
$newOu
));
}
$newDn
=
sprintf
(
'%s=%s,ou=%s,%s'
,
$this
->
getKey
(),
$this
->
getId
(),
$newOu
,
$this
->
getNode
()
->
getLdap
()
->
getBaseDn
());
$this
->
getNode
()
->
move
(
$newDn
);
return
$this
;
}
/**
* Renommage de l'entité
*
* This is an offline method. Node will be renamed on calling update().
*
* @param string | Dn $newDn
* @throws \Zend\Ldap\Exception\LdapException
*/
public
function
rename
(
$newId
)
{
$newDn
=
sprintf
(
'%s=%s,ou=%s,%s'
,
$this
->
getKey
(),
$newId
,
$this
->
getOu
(),
$this
->
getNode
()
->
getLdap
()
->
getBaseDn
());
$this
->
getNode
()
->
move
(
$newDn
);
}
/**
* Suppression de l'entité
*
* This is an offline method.
* Node will be deleted on calling update().
*
* @return self
*/
public
function
delete
()
...
...
@@ -465,6 +524,19 @@ abstract class Entity
return
$this
;
}
/**
* Mise à jour de l'entité
*
* @return self
* @throws LdapException
*/
public
function
update
()
{
$this
->
getNode
()
->
update
();
return
$this
;
}
/**
* Attache une connexion
*
...
...
src/UnicaenLdap/Entity/People.php
View file @
5e14d817
...
...
@@ -48,20 +48,6 @@ class People extends BasePeople
return
'blocked'
==
$this
->
getOu
();
}
/**
* Retourne l'Organizational Unit (OU) de l'utilisateur
*
* @return string
*/
public
function
getOu
()
{
if
(
$result
=
$this
->
getNode
()
->
getDn
()
->
get
(
1
))
{
return
$result
[
'ou'
];
}
return
null
;
}
/**
* Retourne le nom complet.
*
...
...
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