Repository navigation
Expand file tree
/
Copy pathUser.php
More file actions
189 lines (164 loc) · 4.01 KB
/
Copy pathUser.php
File metadata and controls
189 lines (164 loc) · 4.01 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
<?php namespace Gitlab\Model;
use Gitlab\Client;
/**
* Class User
*
* @property-read int $id
* @property-read string $email
* @property-read string $password
* @property-read string $username
* @property-read string $name
* @property-read string $bio
* @property-read string $skype
* @property-read string $linkedin
* @property-read string $twitter
* @property-read bool $dark_scheme
* @property-read int $theme_id
* @property-read int $color_scheme_id
* @property-read bool $blocked
* @property-read int $access_level
* @property-read string $created_at
* @property-read string $extern_uid
* @property-read string $provider
* @property-read string $state
* @property-read bool $is_admin
* @property-read bool $can_create_group
* @property-read bool $can_create_project
*/
class User extends AbstractModel
{
/**
* @var array
*/
protected static $properties = array(
'id',
'email',
'password',
'username',
'name',
'bio',
'skype',
'linkedin',
'twitter',
'dark_scheme',
'theme_id',
'color_scheme_id',
'blocked',
'projects_limit',
'access_level',
'created_at',
'extern_uid',
'provider',
'state',
'is_admin',
'can_create_group',
'can_create_project'
);
/**
* @param Client $client
* @param array $data
* @return User
*/
public static function fromArray(Client $client, array $data)
{
$id = isset($data['id']) ? $data['id'] : 0;
$user = new static($id, $client);
return $user->hydrate($data);
}
/**
* @param Client $client
* @param string $email
* @param string $password
* @param array $params
* @return User
*/
public static function create(Client $client, $email, $password, array $params = array())
{
$data = $client->api('users')->create($email, $password, $params);
return static::fromArray($client, $data);
}
/**
* @param int $id
* @param Client $client
*/
public function __construct($id = null, Client $client = null)
{
$this->setClient($client);
$this->setData('id', $id);
}
/**
* @return User
*/
public function show()
{
$data = $this->api('users')->show($this->id);
return static::fromArray($this->getClient(), $data);
}
/**
* @param array $params
* @return User
*/
public function update(array $params)
{
$data = $this->api('users')->update($this->id, $params);
return static::fromArray($this->getClient(), $data);
}
/**
* @return bool
*/
public function remove()
{
$this->api('users')->remove($this->id);
return true;
}
/**
* @return Key[]
*/
public function keys()
{
$data = $this->api('users')->keys();
$keys = array();
foreach ($data as $key) {
$keys[] = Key::fromArray($this->getClient(), $key);
}
return $keys;
}
/**
* @param string $title
* @param string $key
* @return Key
*/
public function createKey($title, $key)
{
$data = $this->api('users')->createKey($title, $key);
return Key::fromArray($this->getClient(), $data);
}
/**
* @param int $id
* @return bool
*/
public function removeKey($id)
{
$this->api('users')->removeKey($id);
return true;
}
/**
* @param int $group_id
* @param int $access_level
* @return User
*/
public function addToGroup($group_id, $access_level)
{
$group = new Group($group_id, $this->getClient());
return $group->addMember($this->id, $access_level);
}
/**
* @param int $group_id
* @return bool
*/
public function removeFromGroup($group_id)
{
$group = new Group($group_id, $this->getClient());
return $group->removeMember($this->id);
}
}