clone board func with labels and stacks

Signed-off-by: Jakob <jakob.roehrl@web.de>
This commit is contained in:
Jakob
2019-09-06 09:32:52 +02:00
parent cba7525951
commit 36afac9eff
6 changed files with 98 additions and 0 deletions

View File

@@ -33,6 +33,7 @@ use OCA\Deck\Db\AssignedUsersMapper;
use OCA\Deck\Db\ChangeHelper;
use OCA\Deck\Db\IPermissionMapper;
use OCA\Deck\Db\Label;
use OCA\Deck\Db\Stack;
use OCA\Deck\Db\StackMapper;
use OCA\Deck\NoPermissionException;
use OCA\Deck\Notification\NotificationHelper;
@@ -605,6 +606,49 @@ class BoardService {
return $delete;
}
/**
* @param $id
* @return Board
* @throws DoesNotExistException
* @throws \OCA\Deck\NoPermissionException
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
* @throws BadRequestException
*/
public function clone($id) {
if (is_numeric($id) === false) {
throw new BadRequestException('board id must be a number');
}
$this->permissionService->checkPermission($this->boardMapper, $id, Acl::PERMISSION_READ);
$board = $this->boardMapper->find($id);
$newBoard = new Board();
$newBoard->setTitle($board->getTitle() . ' (copy)');
$newBoard->setOwner($board->getOwner());
$newBoard->setColor($board->getColor());
$this->boardMapper->insert($newBoard);
$labels = $this->labelMapper->findAll($id);
foreach ($labels as $label) {
$newLabel = new Label();
$newLabel->setTitle($label->getTitle());
$newLabel->setColor($label->getColor());
$newLabel->setBoardId($newBoard->getId());
$this->labelMapper->insert($newLabel);
}
$stacks = $this->stackMapper->findAll($id);
foreach ($stacks as $stack) {
$newStack = new Stack();
$newStack->setTitle($stack->getTitle());
$newStack->setBoardId($newBoard->getId());
$this->stackMapper->insert($newStack);
}
return $newBoard;
}
private function enrichWithStacks($board, $since = -1) {
$stacks = $this->stackMapper->findAll($board->getId(), null, null, $since);