Methods

Source

LineCode
1
<?php
2
3
namespace AuthStack\UserDirectory\Service;
4
5
use AuthStack\UserDirectory\Model\Group as GroupModel;
6
use AuthStack\UserDirectory\Exceptions\GroupException;
7
8
class Group extends RESTService
9
{
10
    /**
11
     * @param array $model
12
     * @return mixed
13
     */
14
    public function create(array $model)
15
    {
16
        return $this->remote(function() use (&$model): GroupModel
17
        {
18
            $result = $this->json('create', $model);
19
20
            return new GroupModel($result);
21
22
        }, GroupException::class);
23
    }
24
25
    /**
26
     * @param int $id
27
     * @return GroupModel
28
     */
29
    public function read(int $id): GroupModel
30
    {
31
        return $this->remote(function() use ($id)
32
        {
33
            $result = $this->json('read', [], [$id]);
34
35
            return new GroupModel($result);
36
37
        }, GroupException::class);
38
    }
39
40
    /**
41
     * @param int $id
42
     * @param array $model
43
     * @return bool
44
     */
45
    public function update(int $id, array $model): bool
46
    {
47
        return $this->remote(function() use ($id, &$model)
48
        {
49
            $result = $this->json('update', $model, [$id]);
50
51
            return $result['result'];
52
53
        }, GroupException::class);
54
    }
55
56
    /**
57
     * @param int $id
58
     * @return bool
59
     */
60
    public function delete(int $id): bool
61
    {
62
        return $this->remote(function() use ($id)
63
        {
64
            $result = $this->json('delete', [], [$id]);
65
66
            return $result['result'];
67
68
        }, GroupException::class);
69
    }
70
71
    /**
72
     * @param int $id
73
     * @param int $parent_id
74
     * @return bool
75
     */
76
    public function setParent(int $id, int $parent_id): bool
77
    {
78
        return $this->remote(function() use ($id, $parent_id)
79
        {
80
            $result = $this->json('change_parent', ['parent_id' => $parent_id], [$id]);
81
82
            return $result['result'];
83
84
        }, GroupException::class);
85
    }
86
87
    /**
88
     * @param array $options
89
     * @return array
90
     */
91
    public function listing(array $options = []): array
92
    {
93
        return $this->remote(function() use (&$options)
94
        {
95
            return $this->json('listing', null, null, $options);
96
        });
97
    }
98
99
    /**
100
     * @todo - not implemented! Implement @ server first
101
     * @param int $id
102
     * @param array $get_params
103
     * @return mixed
104
     */
105
    public function getMembers(int $id, array $get_params = []): array
106
    {
107
        return $this->remote(function() use ($id, $get_params)
108
        {
109
            return $this->json('change_parent', [], [$id], $get_params);
110
111
        }, GroupException::class);
112
    }
113
}