|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace JiraRestApi\Group; |
| 4 | + |
| 5 | +/** |
| 6 | + * Class to perform all groups related queries. |
| 7 | + * @package JiraRestApi\Group |
| 8 | + */ |
| 9 | +class GroupService extends \JiraRestApi\JiraClient |
| 10 | +{ |
| 11 | + private $uri = '/group'; |
| 12 | + |
| 13 | + /** |
| 14 | + * Function to get group. |
| 15 | + * |
| 16 | + * @param array $paramArray Possible values for $paramArray 'username', 'key'. |
| 17 | + * "Either the 'username' or the 'key' query parameters need to be provided". |
| 18 | + * |
| 19 | + * @return Group class |
| 20 | + */ |
| 21 | + public function get($paramArray) |
| 22 | + { |
| 23 | + $queryParam = '?'.http_build_query($paramArray); |
| 24 | + |
| 25 | + $ret = $this->exec($this->uri.$queryParam, null); |
| 26 | + |
| 27 | + $this->log->addInfo("Result=\n".$ret); |
| 28 | + |
| 29 | + return $this->json_mapper->map( |
| 30 | + json_decode($ret), new User() |
| 31 | + ); |
| 32 | + } |
| 33 | + |
| 34 | + /** |
| 35 | + * Get users from group |
| 36 | + * |
| 37 | + * @param $paramArray groupname, includeInactiveUsers, startAt, maxResults |
| 38 | + * @return GroupSearchResult |
| 39 | + * @throws \JiraRestApi\JiraException |
| 40 | + * @throws \JsonMapper_Exception |
| 41 | + */ |
| 42 | + public function getMembers($paramArray) |
| 43 | + { |
| 44 | + $queryParam = '?' . http_build_query($paramArray); |
| 45 | + |
| 46 | + $ret = $this->exec($this->uri . '/member'.$queryParam, null); |
| 47 | + |
| 48 | + $this->log->addInfo("Result=\n".$ret); |
| 49 | + |
| 50 | + $userData = json_decode($ret); |
| 51 | + |
| 52 | + $res = $this->json_mapper->map($userData, new GroupSearchResult()); |
| 53 | + |
| 54 | + return $res; |
| 55 | + } |
| 56 | + |
| 57 | + /** |
| 58 | + * Creates a group by given group parameter |
| 59 | + * |
| 60 | + * @param $group \JiraRestApi\Group\Group |
| 61 | + * @return array |
| 62 | + * @throws \JiraRestApi\JiraException |
| 63 | + * @throws \JsonMapper_Exception |
| 64 | + */ |
| 65 | + public function createGroup($group) |
| 66 | + { |
| 67 | + $data = json_encode($group); |
| 68 | + |
| 69 | + $ret = $this->exec($this->uri, $data); |
| 70 | + |
| 71 | + $this->log->addInfo("Result=\n".$ret); |
| 72 | + |
| 73 | + $groupData = json_decode($ret); |
| 74 | + $groups = []; |
| 75 | + |
| 76 | + $group = $this->json_mapper->map( |
| 77 | + json_decode($ret), new Group() |
| 78 | + ); |
| 79 | + |
| 80 | + return $group; |
| 81 | + } |
| 82 | +} |
0 commit comments