1: <?php
2: /**
3: * The log decorator for folder lists from Kolab storage.
4: *
5: * PHP version 5
6: *
7: * @category Kolab
8: * @package Kolab_Storage
9: * @author Gunnar Wrobel <wrobel@pardus.de>
10: * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
11: * @link http://pear.horde.org/index.php?package=Kolab_Storage
12: */
13:
14: /**
15: * The log decorator for folder lists from Kolab storage.
16: *
17: * Copyright 2010-2012 Horde LLC (http://www.horde.org/)
18: *
19: * See the enclosed file COPYING for license information (LGPL). If you
20: * did not receive this file, see http://www.horde.org/licenses/lgpl21.
21: *
22: * @category Kolab
23: * @package Kolab_Storage
24: * @author Gunnar Wrobel <wrobel@pardus.de>
25: * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
26: * @link http://pear.horde.org/index.php?package=Kolab_Storage
27: */
28: class Horde_Kolab_Storage_List_Decorator_Log
29: implements Horde_Kolab_Storage_List, Horde_Kolab_Storage_List_Query
30: {
31: /**
32: * Decorated list handler.
33: *
34: * @var Horde_Kolab_Storage_List
35: */
36: private $_list;
37:
38: /**
39: * A log handler.
40: *
41: * @var mixed
42: */
43: private $_logger;
44:
45: /**
46: * Constructor.
47: *
48: * @param Horde_Kolab_Storage_List $list The original list handler.
49: * @param mixed $logger The log handler. This instance
50: * must provide the debug()
51: * and info() methods.
52: */
53: public function __construct(Horde_Kolab_Storage_List $list,
54: $logger)
55: {
56: $this->_list = $list;
57: $this->_logger = $logger;
58: }
59:
60: /**
61: * Return the list driver.
62: *
63: * @return Horde_Kolab_Storage_Driver The driver.
64: */
65: public function getDriver()
66: {
67: return $this->_list->getDriver();
68: }
69:
70: /**
71: * Return the ID of the underlying connection.
72: *
73: * @return string The connection ID.
74: */
75: public function getId()
76: {
77: return $this->_list->getId();
78: }
79:
80: /**
81: * Return the connection parameters.
82: *
83: * @return array The connection parameters.
84: */
85: public function getIdParameters()
86: {
87: return $this->_list->getIdParameters();
88: }
89:
90: /**
91: * Create a new folder.
92: *
93: * @param string $folder The path of the folder to create.
94: * @param string $type An optional type for the folder.
95: *
96: * @return NULL
97: */
98: public function createFolder($folder, $type = null)
99: {
100: $this->_logger->info(sprintf('Creating folder %s.', $folder));
101: $result = $this->_list->createFolder($folder, $type);
102: $this->_logger->info(
103: sprintf('Successfully created folder %s [type: %s].', $folder, $type)
104: );
105: }
106:
107: /**
108: * Delete a folder.
109: *
110: * @param string $folder The path of the folder to delete.
111: *
112: * @return NULL
113: */
114: public function deleteFolder($folder)
115: {
116: $this->_logger->info(sprintf('Deleting folder %s.', $folder));
117: $result = $this->_list->deleteFolder($folder);
118: $this->_logger->info(
119: sprintf('Successfully deleted folder %s.', $folder)
120: );
121: }
122:
123: /**
124: * Rename a folder.
125: *
126: * @param string $old The old path of the folder.
127: * @param string $new The new path of the folder.
128: *
129: * @return NULL
130: */
131: public function renameFolder($old, $new)
132: {
133: $this->_logger->info(sprintf('Renaming folder %s.', $old));
134: $result = $this->_list->renameFolder($old, $new);
135: $this->_logger->info(
136: sprintf('Successfully renamed folder %s to %s.', $old, $new)
137: );
138: }
139:
140: /**
141: * Returns a representation for the requested folder.
142: *
143: * @param string $folder The path of the folder to return.
144: *
145: * @return Horde_Kolab_Storage_Folder The folder representation.
146: */
147: public function getFolder($folder)
148: {
149: return $this->_list->getFolder($folder);
150: }
151:
152: /**
153: * Mark the specified folder as the default folder of this type.
154: *
155: * @param string $folder The path of the folder to mark as default.
156: *
157: * @return NULL
158: */
159: public function setDefault($folder)
160: {
161: $this->_list->setDefault($folder);
162: }
163:
164: /**
165: * Returns the list of folders visible to the current user.
166: *
167: * @return array The list of folders, represented as a list of strings.
168: */
169: public function listFolders()
170: {
171: $this->_logger->debug(
172: sprintf(
173: 'Listing folders for %s.',
174: $this->getId()
175: )
176: );
177: $result = $this->_list->listFolders();
178: $this->_logger->debug(
179: sprintf(
180: 'List for %s contained %s folders.',
181: $this->getId(),
182: count($result)
183: )
184: );
185: return $result;
186: }
187:
188: /**
189: * Returns the folder type annotation as associative array.
190: *
191: * @return array The list folder types with the folder names as key and the
192: * folder type as values.
193: */
194: public function listFolderTypes()
195: {
196: $this->_logger->debug(
197: sprintf(
198: 'Listing folder type annotations for %s.',
199: $this->getId()
200: )
201: );
202: $result = $this->_list->listFolderTypes();
203: $this->_logger->debug(
204: sprintf(
205: 'List for %s contained %s folders and annotations.',
206: $this->getId(),
207: count($result)
208: )
209: );
210: return $result;
211: }
212:
213: /**
214: * Returns the namespace for the list.
215: *
216: * @return Horde_Kolab_Storage_Folder_Namespace The namespace handler.
217: */
218: public function getNamespace()
219: {
220: return $this->_list->getNamespace();
221: }
222:
223: /**
224: * Return the last sync stamp.
225: *
226: * @return string The stamp.
227: */
228: public function getStamp()
229: {
230: return $this->_list->getStamp();
231: }
232:
233: /**
234: * Synchronize the list information with the information from the backend.
235: *
236: * @param array $params Additional parameters.
237: *
238: * @return NULL
239: */
240: public function synchronize($params = array())
241: {
242: $this->_list->synchronize();
243: $this->_logger->debug(
244: sprintf(
245: 'Synchronized folder list for %s.',
246: $this->getId()
247: )
248: );
249: }
250:
251: /**
252: * Register a query to be updated if the underlying data changes.
253: *
254: * @param string $name The query name.
255: * @param Horde_Kolab_Storage_Query $query The query to register.
256: *
257: * @return NULL
258: */
259: public function registerQuery($name, Horde_Kolab_Storage_Query $query)
260: {
261: $this->_list->registerQuery($name, $query);
262: }
263:
264: /**
265: * Return a registered query.
266: *
267: * @param string $name The query name.
268: *
269: * @return Horde_Kolab_Storage_Query The requested query.
270: *
271: * @throws Horde_Kolab_Storage_Exception In case the requested query does
272: * not exist.
273: */
274: public function getQuery($name = null)
275: {
276: return $this->_list->getQuery($name);
277: }
278: }