1: <?php
2: /**
3: * A server list implementation.
4: *
5: * PHP version 5
6: *
7: * @category Kolab
8: * @package Kolab_Server
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_Server
12: */
13:
14: /**
15: * A server list implementation.
16: *
17: * Copyright 2008-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_Server
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_Server
27: */
28: class Horde_Kolab_Server_List_Base
29: implements Horde_Kolab_Server_List_Interface
30: {
31: /**
32: * List all objects of a specific type.
33: *
34: * @param string $type The type of the objects to be listed
35: * @param array $params Additional parameters.
36: *
37: * @return array An array of Kolab objects.
38: *
39: * @throws Horde_Kolab_Server_Exception
40: *
41: * @todo Sorting
42: */
43: public function listObjects($type, $params = null)
44: {
45: $result = Horde_Kolab_Server_Object::loadClass($type);
46: $vars = get_class_vars($type);
47: $criteria = call_user_func(array($type, 'getFilter'));
48: $filter = $this->searchQuery($criteria);
49: $sort = $vars['sort_by'];
50:
51: if (isset($params['sort'])) {
52: $sort = $params['sort'];
53: }
54:
55: $options = array('scope' => 'sub');
56: if (isset($params['attributes'])) {
57: $options['attributes'] = $params['attributes'];
58: } else {
59: $options['attributes'] = $this->getAttributes($type);
60: }
61:
62: $data = $this->search($filter, $options, $base);
63: if (empty($data)) {
64: return array();
65: }
66:
67: if ($sort) {
68: /* @todo: sorting */
69: /* $data = $result->as_sorted_struct(); */
70: /*$this->sort($result, $sort); */
71: }
72:
73: if (isset($params['from'])) {
74: $from = $params['from'];
75: } else {
76: $from = -1;
77: }
78:
79: if (isset($params['to'])) {
80: $sort = $params['to'];
81: } else {
82: $to = -1;
83: }
84:
85: if (!empty($vars['required_group'])) {
86: $required_group = new Horde_Kolab_Server_Object_Kolabgroupofnames(
87: $this,
88: null,
89: $vars['required_group']
90: );
91: }
92:
93: $objects = array();
94: foreach ($data as $uid => $entry) {
95: if (!empty($vars['required_group'])) {
96: if (!$required_group->exists() || !$required_group->isMember($uid)) {
97: continue;
98: }
99: }
100: $objects[$uid] = &Horde_Kolab_Server_Object::factory(
101: $type, $uid, $this, $entry
102: );
103: }
104: return $objects;
105: }
106: }