1: <?php
2: /**
3: * A cleanup decoration for Kolab Servers that allows to remove all added
4: * objects.
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: * A cleanup decoration for Kolab Servers that allows to remove all added
17: * objects.
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_Decorator_Clean
31: implements Horde_Kolab_Server_Interface
32: {
33: /**
34: * The server we delegate to.
35: *
36: * @var Horde_Kolab_Server
37: */
38: private $_server;
39:
40: /**
41: * The objects added.
42: *
43: * @var array
44: */
45: private $_added = array();
46:
47: /**
48: * Constructor.
49: *
50: * @param Horde_Kolab_Server $server The base server connection.
51: */
52: public function __construct(
53: Horde_Kolab_Server_Interface $server
54: ) {
55: $this->_server = $server;
56: }
57:
58: /**
59: * Connect to the server.
60: *
61: * @param string $guid The global unique id of the user.
62: * @param string $pass The password.
63: *
64: * @return NULL.
65: *
66: * @throws Horde_Kolab_Server_Exception If the connection failed.
67: */
68: public function connectGuid($guid = null, $pass = null)
69: {
70: $this->_server->connectGuid($guid, $pass);
71: }
72:
73: /**
74: * Get the current GUID
75: *
76: * @return string The GUID of the connected user.
77: */
78: public function getGuid()
79: {
80: return $this->_server->getGuid();
81: }
82:
83: /**
84: * Get the base GUID of this server
85: *
86: * @return string The base GUID of this server.
87: */
88: public function getBaseGuid()
89: {
90: return $this->_server->getBaseGuid();
91: }
92:
93: /**
94: * Low level access to reading object data.
95: *
96: * @param string $guid The object to retrieve.
97: * @param array $attrs Restrict to these attributes.
98: *
99: * @return array An array of attributes.
100: *
101: * @throws Horde_Kolab_Server_Exception If the search operation hit an error
102: * or returned no result.
103: */
104: public function read($guid, array $attrs = array())
105: {
106: return $this->_server->read($guid);
107: }
108:
109: /**
110: * Low level access to reading some object attributes.
111: *
112: * @param string $guid The object to retrieve.
113: * @param string $attrs Restrict to these attributes.
114: *
115: * @return array An array of attributes.
116: *
117: * @throws Horde_Kolab_Server_Exception
118: *
119: * @see Horde_Kolab_Server::read
120: */
121: public function readAttributes($guid, array $attrs)
122: {
123: return $this->_server->readAttributes($guid, $attrs);
124: }
125:
126: /**
127: * Finds object data matching a given set of criteria.
128: *
129: * @param string $query The LDAP search query
130: * @param array $params Additional search parameters.
131: *
132: * @return Horde_Kolab_Server_Result The result object.
133: *
134: * @throws Horde_Kolab_Server_Exception
135: */
136: public function find($query, array $params = array())
137: {
138: return $this->_server->find($query, $params);
139: }
140:
141: /**
142: * Finds all object data below a parent matching a given set of criteria.
143: *
144: * @param string $query The LDAP search query
145: * @param string $parent The parent to search below.
146: * @param array $params Additional search parameters.
147: *
148: * @return Horde_Kolab_Server_Result The result object.
149: *
150: * @throws Horde_Kolab_Server_Exception
151: */
152: public function findBelow($query, $parent, array $params = array())
153: {
154: return $this->_server->findBelow($query, $parent, $params);
155: }
156:
157: /**
158: * Modify existing object data.
159: *
160: * @param Horde_Kolab_Server_Object $object The object to be modified.
161: * @param array $data The attributes of the object
162: * to be stored.
163: *
164: * @return NULL
165: *
166: * @throws Horde_Kolab_Server_Exception
167: */
168: public function save(
169: Horde_Kolab_Server_Object_Interface $object,
170: array $data
171: ) {
172: $this->_server->save($object, $data);
173: }
174:
175: /**
176: * Add new object data.
177: *
178: * @param Horde_Kolab_Server_Object $object The object to be added.
179: * @param array $data The attributes of the object
180: * to be added.
181: *
182: * @return NULL
183: *
184: * @throws Horde_Kolab_Server_Exception
185: */
186: public function add(
187: Horde_Kolab_Server_Object_Interface $object,
188: array $data
189: ) {
190: $this->_server->add($object, $data);
191: $this->_added[] = $object->getGuid();
192: }
193:
194: /**
195: * Delete an object.
196: *
197: * @param string $guid The GUID of the object to be deleted.
198: *
199: * @return NULL
200: *
201: * @throws Horde_Kolab_Server_Exception
202: */
203: public function delete($guid)
204: {
205: $this->_server->delete($guid);
206: if (in_array($guid, $this->_added)) {
207: $this->_added = array_diff($this->_added, array($guid));
208: }
209: }
210:
211: /**
212: * Rename an object.
213: *
214: * @param string $guid The GUID of the object to be renamed.
215: * @param string $new The new GUID of the object.
216: *
217: * @return NULL
218: *
219: * @throws Horde_Kolab_Server_Exception
220: */
221: public function rename($guid, $new)
222: {
223: $this->_server->rename($guid, $new);
224: }
225:
226: /**
227: * Return the ldap schema.
228: *
229: * @return Horde_Ldap_Schema The LDAP schema.
230: *
231: * @throws Horde_Kolab_Server_Exception If retrieval of the schema failed.
232: */
233: public function getSchema()
234: {
235: return $this->_server->getSchema();
236: }
237:
238: /**
239: * Get the parent GUID of this object.
240: *
241: * @param string $guid The GUID of the child.
242: *
243: * @return string the parent GUID of this object.
244: */
245: public function getParentGuid($guid)
246: {
247: return $this->_server->getParentGuid($guid);
248: }
249:
250: /**
251: * Cleanup the server.
252: *
253: * @return NULL
254: */
255: public function cleanup()
256: {
257: foreach ($this->_added as $guid) {
258: $this->delete($guid);
259: }
260: }
261:
262: /**
263: * Destructor.
264: */
265: public function __destruct()
266: {
267: $this->cleanup();
268: }
269: }
270: