From 41767dde3d2cb928e3275324eeb6eed23af6eae8 Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Sun, 9 Nov 2008 16:47:55 +0000 Subject: [PATCH] =?UTF-8?q?-=20LSldapObject=20:=20=09->=20Ajout=20de=20la?= =?UTF-8?q?=20m=C3=A9thode=20search()=20effectuant=20une=20recherche=20mul?= =?UTF-8?q?ti-niveau=20dans=20l'annuaire=20=09=09=20et=20retournant=20un?= =?UTF-8?q?=20tableau=20array(dn=20=3D>=20'',=20attrs=20=3D>=20'')=20des?= =?UTF-8?q?=20objets=20correspondants.=20=09=09=20Cette=20m=C3=A9thode=20e?= =?UTF-8?q?st=20plus=20l=C3=A9g=C3=A8re=20=C3=A0=20utiliser=20quand=20on?= =?UTF-8?q?=20cherche=20simplement=20a=20obtenir=20une=20=09=09=20liste=20?= =?UTF-8?q?d'objet=20avec=20quelques=20infos=20plut=C3=B4t=20qu'une=20list?= =?UTF-8?q?e=20d'objet=20instanci=C3=A9.=20=09->=20Utilisation=20de=20la?= =?UTF-8?q?=20m=C3=A9thode=20search()=20dans=20les=20m=C3=A9thodes=20listO?= =?UTF-8?q?bjects()=20=09=09=20et=20listObjectsName()=20plut=C3=B4t=20qu'u?= =?UTF-8?q?ne=20recherche=20autonome.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- trunk/includes/class/class.LSldapObject.php | 92 +++++++++------------ 1 file changed, 41 insertions(+), 51 deletions(-) diff --git a/trunk/includes/class/class.LSldapObject.php b/trunk/includes/class/class.LSldapObject.php index b8501da9..6487dbea 100644 --- a/trunk/includes/class/class.LSldapObject.php +++ b/trunk/includes/class/class.LSldapObject.php @@ -634,7 +634,36 @@ class LSldapObject { * * @retval array Tableau d'objets correspondant au resultat de la recherche */ - function listObjects($filter='',$basedn=NULL,$params=array()) { + function listObjects($filter=NULL,$basedn=NULL,$params=array()) { + $retInfos=array(); + + $ret = $this -> search($filter,$basedn,$params); + + // Création d'un tableau d'objet correspondant au valeur retourné + for($i=0;$i type_name($this -> config); + $retInfos[$i] -> loadData($ret[$i]['dn']); + } + + return $retInfos; + } + + /** + * Recherche les objets du même type dans l'annuaire + * + * Effectue une recherche en fonction des paramètres passé et retourne un + * tableau array(dn => '', attrs => array()) d'objet correspondant au resultat* + * de la recherche. + * + * @author Benjamin Renard + * + * @param[in] $filter array (ou string) Filtre de recherche Ldap / Tableau de filtres de recherche + * @param[in] $basedn string DN de base pour la recherche + * @param[in] $params array Paramètres de recherche au format Net_LDAP2::search() + * + * @retval array Tableau d'objets correspondant au resultat de la recherche + */ + function search($filter='',$basedn=NULL,$params=array()) { $retInfos=array(); $attrs=false; $check_final_dn=false; @@ -716,7 +745,7 @@ class LSldapObject { if ($filter[$i]['attr']) { $sparams['attributes'] = array($filter[$i]['attr']); } - else { + else if (!isset($sparams['attributes'])) { $sparams['attributes'] = array($this -> config['rdn']); } @@ -742,20 +771,10 @@ class LSldapObject { } } } - else { - // vérification de la compatibilité de la compatibilité du DN resultant - // et du basedn de recherche - if (!$this -> isCompatibleDNs($ret[0]['dn'],$basedn)) - continue; - // ajout du DN au resultat finale - $ret_gen[]=$ret[0]['dn']; - } } } // cas du dernier filtre if(!empty($ret_gen)) { - // on quitte la boucle des filtres de la conf - $ret=$ret_gen; break; } // dans le cas d'une suite prévu mais d'un retour nul de la précédente recherche @@ -783,7 +802,9 @@ class LSldapObject { $sfilter.=$sfilter_end; // Attributes - $sparams['attributes'] = array($this -> config['rdn']); + if (!isset($sparams['attributes'])) { + $sparams['attributes'] = array($this -> config['rdn']); + } // Lancement de la recherche $ret=$GLOBALS['LSldap'] -> search ($sfilter,$sbasedn,$sparams); @@ -815,28 +836,14 @@ class LSldapObject { // Si recherche unique else { // préparation du retour finale - if (is_array($ret)) { - $ret_final=array(); - foreach($ret as $obj) { - $ret_final[]=$obj['dn']; - } - $ret=$ret_final; - } - else { + if (!is_array($ret)) { $ret=array(); } break; } } } - - // Création d'un tableau d'objet correspondant au valeur retourné - for($i=0;$i type_name($this -> config); - $retInfos[$i] -> loadData($ret[$i]); - } - - return $retInfos; + return $ret; } /** @@ -860,31 +867,14 @@ class LSldapObject { 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']); + $attrs = getFieldInFormat($displayFormat); + if(!empty($attrs)) { + $sparams['attributes'] = $attrs; } - + // Lancement de la recherche - $ret=$GLOBALS['LSldap'] -> search ($sfilter,$sbasedn,$sparams); + $ret=$this -> search ($filter,$sbasedn,$sparams); if (is_array($ret)) { foreach($ret as $obj) {