public function getEntry($dn, $attributes = array())
{
if (!is_array($attributes)) {
$attributes = array($attributes);
}
$result = $this->search($dn, '(objectClass=*)', array('scope' => 'base', 'attributes' => $attributes));
if (!$result->count()) {
throw new Horde_Exception_NotFound(sprintf('Could not fetch entry %s: no entry found', $dn));
}
$entry = $result->shiftEntry();
if (!$entry) {
throw new Horde_Ldap_Exception('Could not fetch entry (error retrieving entry from search result)');
}
return $entry;
}
/** * Returns entries sorted as objects. * * This returns a array with sorted Horde_Ldap_Entry objects. The sorting * is actually done with {@link sortedAsArray()}. * * Please note that attribute names are case sensitive! * * Also note that it is (depending on server capabilities) possible to let * the server sort your results. This happens through search controls and * is described in detail at {@link http://www.ietf.org/rfc/rfc2891.txt} * * Usage example: * <code> * // To sort entries first by location, then by surname, but descending: * $entries = $search->sorted(array('locality', 'sn'), SORT_DESC); * </code> * * @todo Entry object construction could be faster. Maybe we could use one * of the factories instead of fetching the entry again. * * @param array $attrs Attribute names as sort criteria. * @param integer $order Ordering direction, either constant SORT_ASC or * SORT_DESC * * @return array Sorted entries. * @throws Horde_Ldap_Exception */ public function sorted($attrs = array('cn'), $order = SORT_ASC) { $return = array(); $sorted = $this->sortedAsArray($attrs, $order); foreach ($sorted as $row) { $entry = $this->_ldap->getEntry($row['dn'], $this->searchedAttributes()); $return[] = $entry; } return $return; }