Methods

Source

LineCode
1
<?php
2
3
namespace AuthStack\UserDirectory\Service;
4
5
use AuthStack\UserDirectory\Exceptions\OrganizationException;
6
use AuthStack\UserDirectory\Model\Organization as OrganizationModel;
7
8
class Organization 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)
17
        {
18
            return new OrganizationModel($this->json('create', $model));
19
20
        }, OrganizationException::class);
21
    }
22
23
    /**
24
     * @param array $model
25
     * @return mixed
26
     */
27
    public function createForAccount(array $model, int $id)
28
    {
29
        return $this->remote(function() use (&$model, $id)
30
        {
31
            return new OrganizationModel($this->json('create_for_account', array_merge($model, ['account_id' => $id])));
32
33
        }, OrganizationException::class);
34
    }
35
36
    /**
37
     * @param int $id
38
     * @return mixed
39
     */
40
    public function read(int $id)
41
    {
42
        return $this->remote(function() use ($id)
43
        {
44
            return new OrganizationModel($this->json('read', [], [$id]));
45
46
        }, OrganizationException::class);
47
    }
48
49
    /**
50
     * @param int $id
51
     * @param array $data
52
     * @return bool
53
     */
54
    public function update(int $id, array $data): bool
55
    {
56
        return $this->remote(function() use ($id, &$data)
57
        {
58
            $response = $this->json('update', $data, [$id]);
59
60
            return $response['result'];
61
62
        }, OrganizationException::class);
63
    }
64
65
    /**
66
     * @param int $id
67
     * @return bool
68
     */
69
    public function delete(int $id): bool
70
    {
71
        return $this->remote(function() use ($id)
72
        {
73
            $response = $this->json('delete', [], [$id]);
74
75
            return $response['result'];
76
77
        }, OrganizationException::class);
78
    }
79
80
    /**
81
     * @param array $options
82
     * @return array
83
     */
84
    public function listing(array $options = []): array
85
    {
86
        return $this->remote(function() use (&$options)
87
        {
88
            $response = $this->json('listing', null, null, $options);
89
90
            return $response;
91
92
        }, OrganizationException::class);
93
    }
94
95
    /**
96
     * @param int $id
97
     * @return bool
98
     */
99
    public function deactivate(int $id): bool
100
    {
101
        return $this->remote(function() use ($id)
102
        {
103
            $response = $this->json('deactivate', null, [$id]);
104
105
            return $response['result'];
106
107
        }, OrganizationException::class);
108
    }
109
110
    /**
111
     * @param int $id
112
     * @param array $options
113
     * @return mixed
114
     */
115
    public function members(int $id, array $options = [])
116
    {
117
        return $this->remote(function() use ($id, &$options)
118
        {
119
            $response = $this->json('members', null, [$id], $options);
120
121
            return $response;
122
123
        }, OrganizationException::class);
124
    }
125
126
    /**
127
     * @param int $id
128
     * @return array
129
     */
130
    public function groups(int $id): array
131
    {
132
        return $this->remote(function() use ($id)
133
        {
134
            $response = $this->json('members', null, [$id]);
135
136
            return $response;
137
138
        }, OrganizationException::class);
139
    }
140
141
    /**
142
     * @param int $id
143
     * @return array
144
     */
145
    public function children(int $id): array
146
    {
147
        return $this->remote(function() use ($id)
148
        {
149
            $response = $this->json('children', null, [$id]);
150
151
            return $response;
152
153
        }, OrganizationException::class);
154
    }
155
}