the user belongs to.
$searches = array(
'gidForMail',
'memberOfGroupAddress',
+ 'getGroupAddresses',
);
return $searches;
}
return !empty($result);
}
+
+ /**
+ * Get the mail addresses for the group of this object.
+ *
+ * @param string $uid The UID of the object to fetch.
+ *
+ * @return array An array of mail addresses.
+ *
+ * @throws Horde_Kolab_Server_Exception
+ */
+ static public function getGroupAddresses($server, $uid)
+ {
+ $criteria = array('AND' =>
+ array(
+ array('field' => self::ATTRIBUTE_OC,
+ 'op' => '=',
+ 'test' => self::OBJECTCLASS_GROUPOFNAMES),
+ array('field' => self::ATTRIBUTE_MEMBER,
+ 'op' => '=',
+ 'test' => $uid),
+ ),
+ );
+
+ $data = self::attrsForSearch($server, $criteria, array(self::ATTRIBUTE_MAIL),
+ self::RESULT_MANY);
+
+ if (empty($data)) {
+ return array();
+ }
+
+ $mails = array();
+ foreach ($data as $element) {
+ if (isset($element[self::ATTRIBUTE_MAIL])) {
+ if (is_array($element[self::ATTRIBUTE_MAIL])) {
+ $mails = array_merge($mails, $element[self::ATTRIBUTE_MAIL]);
+ } else {
+ $mails[] = $element[self::ATTRIBUTE_MAIL];
+ }
+ }
+ }
+ return $mails;
+ }
}
* Added LDAP write support.
* Real LDAP server unit testing.
* Support configurable attribute mapping.
+ * Added getGroupAddresses() to return the mail addresses of groups
+ the user belongs to.
</notes>
<contents>
<dir name="/">
$this->assertNoError($groups);
$this->assertContains('cn=group@example.org,dc=example,dc=org', $groups);
+ $groups = $server->getGroupAddresses($server->uidForIdOrMailOrAlias('g.wrobel@example.org'));
+ $this->assertNoError($groups);
+ $this->assertContains('group@example.org', $groups);
+
$groups = $server->getGroups($server->uidForIdOrMailOrAlias('test@example.org'));
$this->assertNoError($groups);
$this->assertContains('cn=group@example.org,dc=example,dc=org', $groups);
+ $groups = $server->getGroupAddresses($server->uidForIdOrMailOrAlias('test@example.org'));
+ $this->assertNoError($groups);
+ $this->assertContains('group@example.org', $groups);
+
$groups = $server->getGroups('nobody');
$this->assertNoError($groups);
$this->assertTrue(empty($groups));