summaryrefslogtreecommitdiffstats
path: root/lib/kolab_api_service.php
blob: 06ebbb98203f0bf59da9768a5eb5a0b5a38a83b0 (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
56
57
58
59
<?php

require_once 'SQL.php';

/**
 * Interface class for Kolab Admin Services
 */
abstract class kolab_api_service
{
    protected $controller;
    protected $db;

    /**
     * Class constructor.
     *
     * @param kolab_api_controller Controller
     */
    public function __construct($ctrl)
    {
        $this->db         = SQL::get_instance();
        $this->controller = $ctrl;
    }

    /**
     * Advertise this service's capabilities
     */
    abstract public function capabilities($domain);

    /**
     * Returns attributes of specified user type.
     *
     * @param int  $type_id  User type identifier
     * @param bool $required Throws exception on empty ID
     *
     * @return array User type attributes
     */
    protected function user_type_attributes($type_id, $required = true)
    {
        if (empty($user_id)) {
            if ($required) {
                throw new Exception($this->controller->translate('user.notypeid'), 34);
            }

            return array();
        }

        $sql_result = $this->db->query("SELECT attributes FROM user_types WHERE id = ?", $type_id);
        $user_type  = $this->db->fetch_assoc($sql_result);

        if (empty($user_type)) {
            throw new Exception($this->controller->translate('user.invalidtypeid'), 35);
        }

        $uta = json_decode(unserialize($user_type['attributes']), true);

        return $uta;
    }

}