1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13:
14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27:
28: class Horde_Kolab_Storage_List_Query_List_Base
29: implements Horde_Kolab_Storage_List_Query_List
30: {
31: 32: 33: 34: 35:
36: private $_list;
37:
38: 39: 40: 41: 42:
43: private $_factory;
44:
45: 46: 47: 48: 49: 50:
51: public function __construct(Horde_Kolab_Storage_List $list,
52: $params)
53: {
54: $this->_list = $list;
55: $this->_factory = $params['factory'];
56: }
57:
58: 59: 60: 61: 62: 63:
64: public function listTypes()
65: {
66: $result = array();
67: foreach ($this->listFolderTypeAnnotations() as $folder => $annotation) {
68: $result[$folder] = $annotation->getType();
69: }
70: return $result;
71: }
72:
73: 74: 75: 76: 77: 78:
79: public function listFolderTypeAnnotations()
80: {
81: $result = array();
82: foreach ($this->_list->listFolderTypes() as $folder => $annotation) {
83: $result[$folder] = $this->_factory->createFolderType($annotation);
84: }
85: return $result;
86: }
87:
88: 89: 90: 91: 92: 93: 94:
95: public function listByType($type)
96: {
97: $result = array();
98: foreach ($this->listTypes() as $folder => $folder_type) {
99: if ($folder_type == $type) {
100: $result[] = $folder;
101: }
102: }
103: return $result;
104: }
105:
106: 107: 108: 109: 110: 111: 112:
113: public function dataByType($type)
114: {
115: $result = array();
116: $namespace = $this->_list->getNamespace();
117: foreach ($this->listFolderTypeAnnotations() as $folder => $folder_type) {
118: if ($folder_type->getType() == $type) {
119: $result[$folder] = array(
120: 'default' => $folder_type->isDefault(),
121: 'owner' => $namespace->getOwner($folder),
122: 'name' => $namespace->getTitle($folder),
123: 'subpath' => $namespace->getSubpath($folder),
124: 'prefix' => $namespace->matchNamespace($folder)->getName(),
125: 'parent' => $namespace->getParent($folder),
126: 'delimiter' => $namespace->matchNamespace($folder)->getDelimiter(),
127: 'folder' => $folder,
128: );
129: }
130: }
131: return $result;
132: }
133:
134: 135: 136: 137: 138: 139: 140:
141: public function folderData($folder)
142: {
143: $list = $this->_list->listFolders();
144: if (!in_array($folder, $list)) {
145: throw new Horde_Kolab_Storage_Exception(
146: sprintf('Folder %s does not exist!', $folder)
147: );
148: }
149: $annotations = $this->listFolderTypeAnnotations();
150: if (!isset($annotations[$folder])) {
151: $type = $this->_factory->createFolderType('mail');
152: } else {
153: $type = $annotations[$folder];
154: }
155: $namespace = $this->_list->getNamespace();
156: return array(
157: 'type' => $type->getType(),
158: 'default' => $type->isDefault(),
159: 'namespace' => $namespace->matchNamespace($folder)->getType(),
160: 'prefix' => $namespace->matchNamespace($folder)->getName(),
161: 'owner' => $namespace->getOwner($folder),
162: 'name' => $namespace->getTitle($folder),
163: 'subpath' => $namespace->getSubpath($folder),
164: 'parent' => $namespace->getParent($folder),
165: 'delimiter' => $namespace->matchNamespace($folder)->getDelimiter(),
166: );
167: }
168:
169: 170: 171: 172: 173: 174:
175: public function listOwners()
176: {
177: $result = array();
178: $namespace = $this->_list->getNamespace();
179: foreach ($this->_list->listFolders() as $folder) {
180: $result[$folder] = $namespace->getOwner($folder);
181: }
182: return $result;
183: }
184:
185: 186: 187: 188: 189: 190:
191: public function listPersonalDefaults()
192: {
193: $result = array();
194: $namespace = $this->_list->getNamespace();
195: foreach ($this->listFolderTypeAnnotations() as $folder => $annotation) {
196: if ($annotation->isDefault()
197: && ($namespace->matchNamespace($folder)->getType()
198: == Horde_Kolab_Storage_Folder_Namespace::PERSONAL)) {
199: $result[$annotation->getType()] = $folder;
200: }
201: }
202: return $result;
203: }
204:
205: 206: 207: 208: 209: 210: 211:
212: public function listDefaults()
213: {
214: $result = array();
215: $namespace = $this->_list->getNamespace();
216: foreach ($this->listFolderTypeAnnotations() as $folder => $annotation) {
217: if ($annotation->isDefault()) {
218: $result[$namespace->getOwner($folder)][$annotation->getType()] = $folder;
219: }
220: }
221: return $result;
222: }
223:
224: 225: 226: 227: 228: 229: 230:
231: public function getDefault($type)
232: {
233: $result = null;
234: $namespace = $this->_list->getNamespace();
235: foreach ($this->listFolderTypeAnnotations() as $folder => $annotation) {
236: if ($annotation->getType() == $type
237: && $annotation->isDefault()
238: && ($namespace->matchNamespace($folder)->getType()
239: == Horde_Kolab_Storage_Folder_Namespace::PERSONAL)) {
240: if ($result === null) {
241: $result = $folder;
242: } else {
243: throw new Horde_Kolab_Storage_Exception(
244: sprintf(
245: 'Both folders %s and %s are marked as default folder of type %s!',
246: $result,
247: $folder,
248: $type
249: )
250: );
251: }
252: }
253: }
254: if ($result === null) {
255: return false;
256: } else {
257: return $result;
258: }
259: }
260:
261: 262: 263: 264: 265: 266: 267: 268:
269: public function getForeignDefault($owner, $type)
270: {
271: $result = null;
272: $namespace = $this->_list->getNamespace();
273: foreach ($this->listFolderTypeAnnotations() as $folder => $annotation) {
274: if ($annotation->getType() == $type
275: && $annotation->isDefault()
276: && ($namespace->getOwner($folder) == $owner)) {
277: if ($result === null) {
278: $result = $folder;
279: } else {
280: throw new Horde_Kolab_Storage_Exception(
281: sprintf(
282: 'Both folders %s and %s are marked as default folder of type %s!',
283: $result,
284: $folder,
285: $type
286: )
287: );
288: }
289: }
290: }
291: if ($result === null) {
292: return false;
293: } else {
294: return $result;
295: }
296: }
297:
298: 299: 300: 301: 302: 303: 304: 305:
306: public function createFolder($folder, $type = null)
307: {
308: }
309:
310: 311: 312: 313: 314: 315: 316:
317: public function deleteFolder($folder)
318: {
319: }
320:
321: 322: 323: 324: 325: 326: 327: 328:
329: public function renameFolder($old, $new)
330: {
331: }
332:
333: 334: 335: 336: 337:
338: public function getStamp()
339: {
340: return $this->_list->getStamp();
341: }
342:
343: 344: 345: 346: 347: 348: 349:
350: public function synchronize($params = array())
351: {
352: }
353: }