summaryrefslogtreecommitdiffstats
path: root/lib/api/kolab_api_service_groups.php
blob: 116df8b514938b0f23a3f9a34b4bc713cdd30015 (plain)
1
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php

/**
 *
 */
class kolab_api_service_groups extends kolab_api_service
{
    public $list_attribs = array(
        'cn',
        'gidnumber',
        'objectclass',
        'mail',
    );

    public function capabilities($domain)
    {
        return array(
            'list' => 'r',
            );
    }

    public function groups_list($get, $post)
    {
        $auth = Auth::get_instance();

        // returned attributes
        if (!empty($post['attributes']) && is_array($post['attributes'])) {
            // get only supported attributes
            $attributes = array_intersect($this->list_attribs, $post['attributes']);
            // need to fix array keys
            $attributes = array_values($attributes);
        }
        if (empty($attributes)) {
            $attributes = (array)$this->list_attribs[0];
        }

        $groups = $auth->list_groups();
        $count  = count($groups);

        // pagination
        if (!empty($post['page_size']) && $count) {
            $size   = (int) $post['page_size'];
            $page   = !empty($post['page']) ? $post['page'] : 1;
            $page   = max(1, (int) $page);
            $offset = ($page - 1) * $size;

            $groups = array_slice($groups, $offset, $size, true);
        }

        return array(
            'list'  => $groups,
            'count' => $count,
        );
    }
}