From 1b4cf508e67a027609bc396552b376bbd896e23e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Wed, 27 Mar 2019 18:32:26 +0100 Subject: [PATCH] Add details paramter to board request MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- lib/Service/BoardService.php | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/lib/Service/BoardService.php b/lib/Service/BoardService.php index 992afcb46..1a47f59f3 100644 --- a/lib/Service/BoardService.php +++ b/lib/Service/BoardService.php @@ -94,7 +94,7 @@ class BoardService { /** * @return array */ - public function findAll($since = 0) { + public function findAll($since = 0, $details = null) { $userInfo = $this->getBoardPrerequisites(); $userBoards = $this->boardMapper->findAllByUser($userInfo['user'], null, null, $since); $groupBoards = $this->boardMapper->findAllByGroups($userInfo['user'], $userInfo['groups'],null, null, $since); @@ -110,7 +110,11 @@ class BoardService { $this->boardMapper->mapAcl($acl); } } - $this->enrichWithStacks($item); + if ($details !== null) { + $this->enrichWithStacks($item); + $this->enrichWithLabels($item); + $this->enrichWithUsers($item); + } $permissions = $this->permissionService->matchPermissions($item); $item->setPermissions([ 'PERMISSION_READ' => $permissions[Acl::PERMISSION_READ], @@ -154,8 +158,7 @@ class BoardService { 'PERMISSION_MANAGE' => $permissions[Acl::PERMISSION_MANAGE], 'PERMISSION_SHARE' => $permissions[Acl::PERMISSION_SHARE] ]); - $boardUsers = $this->permissionService->findUsers($boardId); - $board->setUsers(array_values($boardUsers)); + $this->enrichWithUsers($board); return $board; } @@ -558,4 +561,22 @@ class BoardService { $board->setStacks($stacks); } + private function enrichWithLabels($board, $since = -1) { + $labels = $this->labelMapper->findAll($board->getId(), null, null, $since); + + if(\count($labels) === 0) { + return; + } + + $board->setLabels($labels); + } + + private function enrichWithUsers($board, $since = -1) { + $boardUsers = $this->permissionService->findUsers($board->getId()); + if(\count($boardUsers) === 0) { + return; + } + $board->setUsers(array_values($boardUsers)); + } + }