Repository navigation
Expand file tree
/
Copy pathGroup.php
More file actions
128 lines (109 loc) · 2.71 KB
/
Copy pathGroup.php
File metadata and controls
128 lines (109 loc) · 2.71 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
<?php namespace Gitlab\Model;
use Gitlab\Client;
/**
* Class Group
*
* @property-read int $id
* @property-read string $name
* @property-read string $path
* @property-read string $description
* @property-read Project[] $projects
*/
class Group extends AbstractModel
{
/**
* @var array
*/
protected static $properties = array(
'id',
'name',
'path',
'description',
'projects'
);
/**
* @param Client $client
* @param array $data
* @return Group
*/
public static function fromArray(Client $client, array $data)
{
$group = new static($data['id'], $client);
if (isset($data['projects'])) {
$projects = array();
foreach ($data['projects'] as $project) {
$projects[] = Project::fromArray($client, $project);
}
$data['projects'] = $projects;
}
return $group->hydrate($data);
}
/**
* @param Client $client
* @param string $name
* @param string $path
* @return Group
*/
public static function create(Client $client, $name, $path)
{
$data = $client->api('groups')->create($name, $path);
return static::fromArray($client, $data);
}
/**
* @param int $id
* @param Client $client
*/
public function __construct($id, Client $client = null)
{
$this->setClient($client);
$this->setData('id', $id);
}
/**
* @return Group
*/
public function show()
{
$data = $this->api('groups')->show($this->id);
return Group::fromArray($this->getClient(), $data);
}
/**
* @param int $project_id
* @return Group
*/
public function transfer($project_id)
{
$data = $this->api('groups')->transfer($this->id, $project_id);
return Group::fromArray($this->getClient(), $data);
}
/**
* @return User[]
*/
public function members()
{
$data = $this->api('groups')->members($this->id);
$members = array();
foreach ($data as $member) {
$members[] = User::fromArray($this->getClient(), $member);
}
return $members;
}
/**
* @param int $user_id
* @param int $access_level
* @return User
*/
public function addMember($user_id, $access_level)
{
$data = $this->api('groups')->addMember($this->id, $user_id, $access_level);
return User::fromArray($this->getClient(), $data);
}
/**
* @param int $user_id
* @return bool
*/
public function removeMember($user_id)
{
$this->api('groups')->removeMember($this->id, $user_id);
return true;
}
}