1+ <?php
2+
3+ namespace Gitlab \Model ;
4+
5+ use Gitlab \Client ;
6+
7+ class Team extends AbstractModel
8+ {
9+ protected static $ _properties = array (
10+ 'id ' ,
11+ 'name ' ,
12+ 'path ' ,
13+ 'owner_id '
14+ );
15+
16+ public static function fromArray (Client $ client , array $ data )
17+ {
18+ $ team = new Team ($ data ['id ' ], $ client );
19+
20+ return $ team ->hydrate ($ data );
21+ }
22+
23+ public static function create (Client $ client , $ name , $ path )
24+ {
25+ $ data = $ client ->api ('teams ' )->create ($ name , $ path );
26+
27+ return Team ::fromArray ($ client , $ data );
28+ }
29+
30+ public function __construct ($ id = null , Client $ client = null )
31+ {
32+ $ this ->setClient ($ client );
33+
34+ $ this ->id = $ id ;
35+ }
36+
37+ public function show ()
38+ {
39+ $ data = $ this ->api ('teams ' )->show ($ this ->id );
40+
41+ return Team ::fromArray ($ this ->getClient (), $ data );
42+ }
43+
44+ public function members ()
45+ {
46+ $ data = $ this ->api ('teams ' )->members ();
47+
48+ $ members = array ();
49+ foreach ($ data as $ member ) {
50+ $ members [] = User ::fromArray ($ this ->getClient (), $ member );
51+ }
52+
53+ return $ members ;
54+ }
55+
56+ public function member ($ user_id )
57+ {
58+ $ data = $ this ->api ('teams ' )->member ($ user_id );
59+
60+ return User ::fromArray ($ this ->getClient (), $ data );
61+ }
62+
63+ public function addMember ($ user_id , $ access_level )
64+ {
65+ $ data = $ this ->api ('teams ' )->addMember ($ user_id , $ access_level );
66+
67+ return User ::fromArray ($ this ->getClient (), $ data );
68+ }
69+
70+ public function removeMember ($ user_id )
71+ {
72+ $ this ->api ('teams ' )->removeMember ($ user_id );
73+
74+ return true ;
75+ }
76+
77+ public function projects ()
78+ {
79+ $ data = $ this ->api ('teams ' )->projects ();
80+
81+ $ projects = array ();
82+ foreach ($ data as $ project ) {
83+ $ projects [] = Project ::fromArray ($ this ->getClient (), $ project );
84+ }
85+
86+ return $ projects ;
87+ }
88+
89+ public function project ($ project_id )
90+ {
91+ $ data = $ this ->api ('teams ' )->project ($ project_id );
92+
93+ return Project ::fromArray ($ this ->getClient (), $ data );
94+ }
95+
96+ public function addProject ($ project_id , $ greatest_access_level )
97+ {
98+ $ data = $ this ->api ('teams ' )->addProject ($ project_id , $ greatest_access_level );
99+
100+ return Project ::fromArray ($ this ->getClient (), $ data );
101+ }
102+
103+ public function removeProject ($ project_id )
104+ {
105+ $ this ->api ('teams ' )->removeProject ($ project_id );
106+
107+ return true ;
108+ }
109+ }
0 commit comments