1: <?php
2: /**
3: * Return the mail addresses of the KolabInetOrgPersons with the given uid or
4: * mail address and include all alias and delegate addresses.
5: *
6: * PHP version 5
7: *
8: * @category Kolab
9: * @package Kolab_Server
10: * @author Gunnar Wrobel <wrobel@pardus.de>
11: * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
12: * @link http://pear.horde.org/index.php?package=Kolab_Server
13: */
14:
15: /**
16: * Return the mail addresses of the KolabInetOrgPersons with the given uid or
17: * mail address and include all alias and delegate addresses.
18: *
19: * Copyright 2008-2012 Horde LLC (http://www.horde.org/)
20: *
21: * See the enclosed file COPYING for license information (LGPL). If you
22: * did not receive this file, see http://www.horde.org/licenses/lgpl21.
23: *
24: * @category Kolab
25: * @package Kolab_Server
26: * @author Gunnar Wrobel <wrobel@pardus.de>
27: * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
28: * @link http://pear.horde.org/index.php?package=Kolab_Server
29: */
30: class Horde_Kolab_Server_Search_Operation_Addressesforuidormail
31: extends Horde_Kolab_Server_Search_Operation_Base
32: {
33:
34: /**
35: * The basic attribute search.
36: *
37: * @var Horde_Kolab_Server_Search_Operation
38: */
39: private $_search;
40:
41: /**
42: * Constructor
43: *
44: * @param Horde_Kolab_Server_Composite $composite A link to the composite
45: * server handler.
46: */
47: public function __construct(Horde_Kolab_Server_Composite $composite)
48: {
49: $this->_composite = $composite;
50: $this->_search = new Horde_Kolab_Server_Search_Operation_Attributes(
51: $this->getComposite()
52: );
53: }
54:
55: /**
56: * Return the mail addresses of the KolabInetOrgPersons with the given uid
57: * or mail address and include all alias and delegate addresses.
58: *
59: * @param string $uid The uid to search for.
60: * @param string $mail The mail address to search for.
61: *
62: * @return array The GUID(s).
63: *
64: * @throws Horde_Kolab_Server_Exception
65: */
66: public function searchAddressesForUidOrMail($uid, $mail)
67: {
68: $criteria = new Horde_Kolab_Server_Query_Element_And(
69: new Horde_Kolab_Server_Query_Element_Equals(
70: 'Objectclass',
71: Horde_Kolab_Server_Object_Kolabinetorgperson::OBJECTCLASS_KOLABINETORGPERSON
72: ),
73: new Horde_Kolab_Server_Query_Element_Or(
74: new Horde_Kolab_Server_Query_Element_Equals(
75: 'Uid', $uid
76: ),
77: new Horde_Kolab_Server_Query_Element_Equals(
78: 'Mail', $mail
79: )
80: )
81: );
82: $search = new Horde_Kolab_Server_Search_Operation_Constraint_Strict(
83: $this->_search
84: );
85:
86: $data = $search->searchAttributes(
87: $criteria, array('Mail', 'Alias')
88: );
89:
90: if (empty($data)) {
91: return array();
92: }
93:
94: $mail = $this->getComposite()->structure->getAttributeInternal(
95: 'Mail'
96: );
97: $alias = $this->getComposite()->structure->getAttributeInternal(
98: 'Alias'
99: );
100:
101: if (isset($result[$alias])) {
102: $addrs = array_merge($data[$mail], $data[$alias]);
103: } else {
104: $addrs = $data[$mail];
105: }
106:
107: $criteria = new Horde_Kolab_Server_Query_Element_And(
108: new Horde_Kolab_Server_Query_Element_Equals(
109: 'Objectclass',
110: Horde_Kolab_Server_Object_Kolabinetorgperson::OBJECTCLASS_KOLABINETORGPERSON
111: ),
112: new Horde_Kolab_Server_Query_Element_Equals(
113: 'Delegate', $data[$mail][0]
114: )
115: );
116:
117: $data = $this->_search->searchAttributes(
118: $criteria, array('Mail', 'Alias')
119: );
120:
121: if (!empty($data)) {
122: foreach ($data as $adr) {
123: if (isset($adr[$mail])) {
124: $addrs = array_merge($addrs, $adr[$mail]);
125: }
126: if (isset($adr[$alias])) {
127: $addrs = array_merge($addrs, $adr[$alias]);
128: }
129: }
130: }
131:
132: $addrs = array_map('strtolower', $addrs);
133:
134: return $addrs;
135: }
136: }