sort entries from search_units()
This commit is contained in:
parent
d41fd04c95
commit
07f4b26790
|
@ -154,6 +154,7 @@ class Ldap{
|
|||
if (!$found) {
|
||||
$ret[] = $suffix;
|
||||
}
|
||||
usort($ret, array($this,"cmp_array"));
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
@ -221,6 +222,33 @@ class Ldap{
|
|||
return $this->ldapHostAttributes;
|
||||
}
|
||||
|
||||
|
||||
// helper function to sort the unit DNs
|
||||
function cmp_array($a, $b) {
|
||||
// split DNs
|
||||
$array_a = explode(",", $a);
|
||||
$array_b = explode(",", $b);
|
||||
$len_a = sizeof($array_a);
|
||||
$len_b = sizeof($array_b);
|
||||
// check how many parts to compare
|
||||
$len = min($len_a, $len_b);
|
||||
// compare from last part on
|
||||
for ($i = 0; $i < $len; $i++) {
|
||||
// get parts to compare
|
||||
$part_a = strtolower($array_a[$len_a - $i - 1]);
|
||||
$part_b = strtolower($array_b[$len_b - $i - 1]);
|
||||
// compare parts
|
||||
if ($part_a == $part_b) { // part is identical
|
||||
if ($i == ($len - 1)) {
|
||||
if ($len_a > $len_b) return 1;
|
||||
elseif ($len_a < $len_b) return -1;
|
||||
else return 0; // DNs are identical
|
||||
}
|
||||
}
|
||||
elseif ($part_a == max($part_a, $part_b)) return 1;
|
||||
else return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue