mirror of
https://gitlab.easter-eggs.com/ee/ldapsaisie.git
synced 2024-11-01 00:03:18 +01:00
- LSldapObject :
-> listObjects() : Optimisation dans les requetes a l'annuaire -> listObjectsName() : Ajout d'une methode specialise/optimise dans le retour d'un couple dn -> name - view.php : Utilisatation de LSldapObject :: listObjectsName() plutot que LSldapObject :: listObjects()
This commit is contained in:
parent
6db507ba6c
commit
0e51b76a0b
3 changed files with 99 additions and 21 deletions
|
@ -712,6 +712,14 @@ class LSldapObject {
|
||||||
$sfilter_for.=$sfilter_end;
|
$sfilter_for.=$sfilter_end;
|
||||||
|
|
||||||
|
|
||||||
|
// Attributes
|
||||||
|
if ($filter[$i]['attr']) {
|
||||||
|
$sparams['attributes'] = array($filter[$i]['attr']);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$sparams['attributes'] = array($this -> config['rdn']);
|
||||||
|
}
|
||||||
|
|
||||||
// Execution de la recherche
|
// Execution de la recherche
|
||||||
$ret=$GLOBALS['LSldap'] -> search ($sfilter_for,$sbasedn,$sparams);
|
$ret=$GLOBALS['LSldap'] -> search ($sfilter_for,$sbasedn,$sparams);
|
||||||
|
|
||||||
|
@ -774,6 +782,9 @@ class LSldapObject {
|
||||||
// fermeture du filtre
|
// fermeture du filtre
|
||||||
$sfilter.=$sfilter_end;
|
$sfilter.=$sfilter_end;
|
||||||
|
|
||||||
|
// Attributes
|
||||||
|
$sparams['attributes'] = array($this -> config['rdn']);
|
||||||
|
|
||||||
// Lancement de la recherche
|
// Lancement de la recherche
|
||||||
$ret=$GLOBALS['LSldap'] -> search ($sfilter,$sbasedn,$sparams);
|
$ret=$GLOBALS['LSldap'] -> search ($sfilter,$sbasedn,$sparams);
|
||||||
|
|
||||||
|
@ -806,8 +817,9 @@ class LSldapObject {
|
||||||
// préparation du retour finale
|
// préparation du retour finale
|
||||||
if (is_array($ret)) {
|
if (is_array($ret)) {
|
||||||
$ret_final=array();
|
$ret_final=array();
|
||||||
foreach($ret as $obj)
|
foreach($ret as $obj) {
|
||||||
$ret_final[]=$obj['dn'];
|
$ret_final[]=$obj['dn'];
|
||||||
|
}
|
||||||
$ret=$ret_final;
|
$ret=$ret_final;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -826,6 +838,62 @@ class LSldapObject {
|
||||||
|
|
||||||
return $retInfos;
|
return $retInfos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retourne une liste d'objet du même type et retourne leur noms
|
||||||
|
*
|
||||||
|
* Effectue une recherche en fonction des paramètres passé et retourne un
|
||||||
|
* tableau (dn => nom) correspondant au resultat de la recherche.
|
||||||
|
*
|
||||||
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
||||||
|
*
|
||||||
|
* @param[in] $filter string Filtre de recherche Ldap
|
||||||
|
* @param[in] $basedn string DN de base pour la recherche
|
||||||
|
* @param[in] $params array Paramètres de recherche au format Net_LDAP2::search()
|
||||||
|
* @param[in] $displayFormat string Format d'affichage du nom des objets
|
||||||
|
*
|
||||||
|
* @retval array Tableau dn => name correspondant au resultat de la recherche
|
||||||
|
*/
|
||||||
|
function listObjectsName($filter=NULL,$sbasedn=NULL,$sparams=array(),$displayFormat=false) {
|
||||||
|
$retInfos=array();
|
||||||
|
|
||||||
|
if (!$displayFormat) {
|
||||||
|
$displayFormat = $this -> getDisplayAttributes();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Filtre sur l'objet souhaité
|
||||||
|
$sfilter='(&';
|
||||||
|
$sfilter.=$this -> getObjectFilter();
|
||||||
|
$sfilter_end=')';
|
||||||
|
|
||||||
|
if(($filter)&&(!empty($filter))) {
|
||||||
|
if(substr($filter,0,1)=='(') {
|
||||||
|
$sfilter.=$filter;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$sfilter.='('.$filter.')';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// fermeture du filtre
|
||||||
|
$sfilter.=$sfilter_end;
|
||||||
|
|
||||||
|
// Attributes
|
||||||
|
$sparams['attributes'] = getFieldInFormat($displayFormat);
|
||||||
|
if(empty($sparams['attributes'])) {
|
||||||
|
$sparams['attributes'] = array($this -> config['rdn']);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Lancement de la recherche
|
||||||
|
$ret=$GLOBALS['LSldap'] -> search ($sfilter,$sbasedn,$sparams);
|
||||||
|
|
||||||
|
if (is_array($ret)) {
|
||||||
|
foreach($ret as $obj) {
|
||||||
|
$retInfos[$obj['dn']] = getFData($displayFormat,$obj['attrs']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $retInfos;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -912,12 +980,7 @@ class LSldapObject {
|
||||||
else {
|
else {
|
||||||
$filter=NULL;
|
$filter=NULL;
|
||||||
}
|
}
|
||||||
$list = $this -> listObjects($filter,$topDn);
|
return $this -> listObjectsName($filter,$topDn,array(),$displayFormat);
|
||||||
$return=array();
|
|
||||||
foreach($list as $object) {
|
|
||||||
$return[$object -> getDn()] = $object -> getDisplayValue($displayFormat);
|
|
||||||
}
|
|
||||||
return $return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1025,13 +1088,17 @@ class LSldapObject {
|
||||||
/**
|
/**
|
||||||
* Retourne la valeur (DN) du subDn de l'objet
|
* Retourne la valeur (DN) du subDn de l'objet
|
||||||
*
|
*
|
||||||
|
* @parram[in] $dn string Un DN
|
||||||
|
*
|
||||||
* @return string La valeur du subDn de l'object
|
* @return string La valeur du subDn de l'object
|
||||||
*/
|
*/
|
||||||
function getSubDnValue() {
|
function getSubDnValue($dn=NULL) {
|
||||||
if ($this -> _subDn_value) {
|
if (!$dn) {
|
||||||
return $this -> _subDn_value;
|
$dn = $this -> getValue('dn');
|
||||||
|
}
|
||||||
|
if ($this -> _subDn_value[$dn]) {
|
||||||
|
return $this -> _subDn_value[$dn];
|
||||||
}
|
}
|
||||||
$dn = $this -> getValue('dn');
|
|
||||||
$subDn_value='';
|
$subDn_value='';
|
||||||
$subDnLdapServer = $GLOBALS['LSsession'] -> getSortSubDnLdapServer();
|
$subDnLdapServer = $GLOBALS['LSsession'] -> getSortSubDnLdapServer();
|
||||||
foreach ($subDnLdapServer as $subDn => $subDn_name) {
|
foreach ($subDnLdapServer as $subDn => $subDn_name) {
|
||||||
|
@ -1040,18 +1107,20 @@ class LSldapObject {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this -> _subDn_value = $subDn_value;
|
$this -> _subDn_value[$dn] = $subDn_value;
|
||||||
return $subDn_value;
|
return $subDn_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retourne la nom du subDn de l'objet
|
* Retourne la nom du subDn de l'objet
|
||||||
*
|
*
|
||||||
|
* @parram[in] $dn string Un DN
|
||||||
|
*
|
||||||
* @return string Le nom du subDn de l'object
|
* @return string Le nom du subDn de l'object
|
||||||
*/
|
*/
|
||||||
function getSubDnName() {
|
function getSubDnName($dn=NULL) {
|
||||||
$subDnLdapServer = $GLOBALS['LSsession'] -> getSortSubDnLdapServer();
|
$subDnLdapServer = $GLOBALS['LSsession'] -> getSortSubDnLdapServer();
|
||||||
return $subDnLdapServer[$this -> getSubDnValue()];
|
return $subDnLdapServer[$this -> getSubDnValue($dn)];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -146,6 +146,16 @@ function getFData($format,$data,$meth=NULL) {
|
||||||
return $format;
|
return $format;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getFieldInFormat($format) {
|
||||||
|
$fields=array();
|
||||||
|
$expr="%{([A-Za-z0-9]+)(\:(-?[0-9])+)?(\:(-?[0-9])+)?}";
|
||||||
|
while (ereg($expr,$format,$ch)) {
|
||||||
|
$fields[]=$ch[1];
|
||||||
|
$format=ereg_replace($ch[0],'',$format);
|
||||||
|
}
|
||||||
|
return $fields;
|
||||||
|
}
|
||||||
|
|
||||||
function loadDir($dir,$regexpr='^.*\.php$') {
|
function loadDir($dir,$regexpr='^.*\.php$') {
|
||||||
if ($handle = opendir($dir)) {
|
if ($handle = opendir($dir)) {
|
||||||
while (false !== ($file = readdir($handle))) {
|
while (false !== ($file = readdir($handle))) {
|
||||||
|
|
|
@ -318,22 +318,21 @@ if($LSsession -> startLSsession()) {
|
||||||
'action' => 'refresh'
|
'action' => 'refresh'
|
||||||
);
|
);
|
||||||
|
|
||||||
$list=$object -> listObjects($filter,$topDn,$params);
|
$list=$object -> listObjectsName($filter,$topDn,$params);
|
||||||
|
|
||||||
|
|
||||||
$nbObjects=0;
|
$nbObjects=0;
|
||||||
foreach($list as $thisObject) {
|
foreach($list as $objDn => $objName) {
|
||||||
if ($GLOBALS['LSsession'] -> canAccess($LSobject,$thisObject->getValue('dn'))) {
|
if ($GLOBALS['LSsession'] -> canAccess($LSobject,$objDn)) {
|
||||||
$subDn_name=false;
|
$subDn_name=false;
|
||||||
if ($doSubDn) {
|
if ($doSubDn) {
|
||||||
$subDn_name = $thisObject -> getSubDnName();
|
$subDn_name = $object -> getSubDnName($objDn);
|
||||||
}
|
}
|
||||||
$nbObjects++;
|
$nbObjects++;
|
||||||
|
|
||||||
|
|
||||||
$objectList[]=array(
|
$objectList[]=array(
|
||||||
'dn' => $thisObject->getValue('dn'),
|
'dn' => $objDn,
|
||||||
'displayValue' => $thisObject->getDisplayValue(),
|
'displayValue' => $objName,
|
||||||
'subDn' => $subDn_name
|
'subDn' => $subDn_name
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue