diff --git a/README.md b/README.md index 862ad14..9296972 100644 --- a/README.md +++ b/README.md @@ -2470,6 +2470,43 @@ try { } ``` + +#### Get boards +[See Jira API reference](https://developer.atlassian.com/cloud/jira/software/rest/#api-rest-agile-1-0-board-get) + +```php +boardService->getBoards([ + 'startAt' => $startAt, + 'maxResults' => $maxResults + ]); + + $results = [...$results, ...$response->getBoards()]; + + $startAt += $maxResults; + + } while($startAt < $response->total); + + var_dump($results); + +} catch (JiraRestApi\JiraException $e) { + print('Error Occured! ' . $e->getMessage()); +} + +``` + + + #### Get board info [See Jira API reference](https://developer.atlassian.com/cloud/jira/software/rest/#api-rest-agile-1-0-board-boardId-get) diff --git a/src/Board/BoardService.php b/src/Board/BoardService.php index 07a9417..8c7c0ae 100644 --- a/src/Board/BoardService.php +++ b/src/Board/BoardService.php @@ -46,6 +46,29 @@ public function getBoardList($paramArray = []): ?\ArrayObject } } + /** + * Get list of boards with paginated results. + * + * @param array $paramArray + * + * @return PaginatedResult|null array of Board class + *@throws \JiraRestApi\JiraException + * + */ + public function getBoards($paramArray = []): ?PaginatedResult + { + $json = $this->exec($this->uri.$this->toHttpQueryParameter($paramArray), null); + try { + return $this->json_mapper->map( + json_decode($json, false, 512, $this->getJsonOptions()), + new PaginatedResult() + ); + } catch (\JsonException $exception) { + $this->log->error("Response cannot be decoded from json\nException: {$exception->getMessage()}"); + return null; + } + } + public function getBoard($id, $paramArray = []): ?Board { $json = $this->exec($this->uri.'/'.$id.$this->toHttpQueryParameter($paramArray), null); @@ -122,6 +145,30 @@ public function getBoardSprints($boardId, $paramArray = []): ?\ArrayObject } } + /** + * Get list of boards with paginated results. + * + * @param array $paramArray + * + * @throws \JiraRestApi\JiraException + * + * @return PaginatedResult|null array of Board class + */ + public function getSprintsForBoard($boardId, $paramArray = []): ?PaginatedResult + { + $json = $this->exec($this->uri.'/'.$boardId.'/sprint'.$this->toHttpQueryParameter($paramArray), null); + + try { + return $this->json_mapper->map( + json_decode($json, false, 512, $this->getJsonOptions()), + new PaginatedResult() + ); + } catch (\JsonException $exception) { + $this->log->error("Response cannot be decoded from json\nException: {$exception->getMessage()}"); + return null; + } + } + /** * @return \ArrayObject|Epic[]|null */ diff --git a/src/Board/PaginatedResult.php b/src/Board/PaginatedResult.php new file mode 100644 index 0000000..c3339aa --- /dev/null +++ b/src/Board/PaginatedResult.php @@ -0,0 +1,129 @@ +startAt; + } + + /** + * @param int $startAt + */ + public function setStartAt($startAt) + { + $this->startAt = $startAt; + } + + /** + * @return int + */ + public function getMaxResults() + { + return $this->maxResults; + } + + /** + * @param int $maxResults + */ + public function setMaxResults($maxResults) + { + $this->maxResults = $maxResults; + } + + /** + * @return int + */ + public function getTotal() + { + return $this->total; + } + + /** + * @param int $total + */ + public function setTotal($total) + { + $this->total = $total; + } + + /** + * @return array + */ + public function getValues() + { + return $this->values; + } + + /** + * @param array $values + */ + public function setValues($values) + { + $this->values = $values; + } + + /** + * @param int $index + * + * @return mixed + */ + public function getValue($index) + { + return $this->values[$index]; + } + + /** + * @return string + */ + public function getExpand() + { + return $this->expand; + } + + /** + * @param string $expand + */ + public function setExpand($expand) + { + $this->expand = $expand; + } +} diff --git a/tests/BoardTest.php b/tests/BoardTest.php index 4eac930..76aa113 100644 --- a/tests/BoardTest.php +++ b/tests/BoardTest.php @@ -41,6 +41,31 @@ public function get_all_boards() : string return $last_board_id; } + /** + * @test + * + * Test we can obtain the paginated board list. + */ + public function get_boards() : string + { + $board_service = new BoardService(); + + $board_list = $board_service->getBoards(); + $this->assertInstanceOf(BoardResult::class, $board_list, 'We receive a board list.'); + + $last_board_id = null; + foreach ($board_list->getBoards() as $board) { + $this->assertInstanceOf(Board::class, $board, 'Each element of the list is a Board instance.'); + $this->assertNotNull($board->self, 'self must not null'); + $this->assertNotNull($board->name, 'name must not null'); + $this->assertNotNull($board->type, 'type must not null'); + + $last_board_id = $board->id; + } + + return $last_board_id; + } + /** * @test *