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