From 8a8cffc54227a38dabaf2ea3522f97f9d6a89fef Mon Sep 17 00:00:00 2001 From: Ryan Fletcher Date: Wed, 11 Jul 2018 08:02:54 -0400 Subject: [PATCH] Completed checkFirstRun() in DefaultBoardService.php Signed-off-by: Ryan Fletcher --- lib/Controller/PageController.php | 2 +- lib/Service/DefaultBoardService.php | 65 ++++++++++++++++------------- 2 files changed, 36 insertions(+), 31 deletions(-) diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php index 7a51bffd5..0f5234bd4 100644 --- a/lib/Controller/PageController.php +++ b/lib/Controller/PageController.php @@ -58,7 +58,7 @@ class PageController extends Controller { 'maxUploadSize' => \OCP\Util::uploadLimit(), ]; - if ($this->defaultBoardService->checkFirstRun($this->userId, $AppName)) { + if ($this->defaultBoardService->checkFirstRun($this->userId, $this->appName)) { $this->defaultBoardService->createDefaultBoard('Personal', $this->userId, '000000'); } diff --git a/lib/Service/DefaultBoardService.php b/lib/Service/DefaultBoardService.php index 33463e958..59192b444 100644 --- a/lib/Service/DefaultBoardService.php +++ b/lib/Service/DefaultBoardService.php @@ -1,6 +1,6 @@ + * @copyright Copyright (c) 2018 Ryan Fletcher * * @author Ryan Fletcher * @@ -23,6 +23,7 @@ namespace OCA\Deck\Service; +use OCA\Deck\Db\BoardMapper; use OCA\Deck\Service\BoardService; use OCA\Deck\Service\StackService; use OCA\Deck\Service\CardService; @@ -30,48 +31,52 @@ use OCP\IConfig; class DefaultBoardService { - private $boardService; - private $stackService; - private $cardService; - private $config; + private $boardMapper; + private $boardService; + private $stackService; + private $cardService; + private $config; public function __construct( - BoardService $boardService, - StackService $stackService, - CardService $cardService, - IConfig $config - ) { + BoardMapper $boardMapper, + BoardService $boardService, + StackService $stackService, + CardService $cardService, + IConfig $config + ) { - $this->boardService = $boardService; - $this->stackService = $stackService; - $this->cardService = $cardService; - $this->config = $config; + $this->boardService = $boardService; + $this->stackService = $stackService; + $this->cardService = $cardService; + $this->config = $config; + $this->boardMapper = $boardMapper; } public function checkFirstRun($userId, $appName) { - $firstRun = $this->config->getUserValue($userId,$appName,'firstRun','yes'); + $firstRun = $this->config->getUserValue($userId,$appName,'firstRun','yes'); + $userBoards = $this->boardMapper->findAllByUser($userId); + + if ($firstRun === 'yes' && count($userBoards) === 0) { + $this->config->setUserValue($userId,$appName,'firstRun','no'); + return true; + } - if ($firstRun == 'yes') { - $this->config->setUserValue($userId,$appName,'firstRun','no'); - return true; - } - - return false; + return false; } public function createDefaultBoard($title, $userId, $color) { $defaultBoard = $this->boardService->create($title, $userId, $color); $defaultStacks = []; $defaultCards = []; + + $boardId = $defaultBoard->getId(); + + $defaultStacks[] = $this->stackService->create('To do', $boardId, 1); + $defaultStacks[] = $this->stackService->create('Doing', $boardId, 1); + $defaultStacks[] = $this->stackService->create('Done', $boardId, 1); - $boardId = $defaultBoard->getId(); - - $defaultStacks[] = $this->stackService->create('To do', $boardId, 1); - $defaultStacks[] = $this->stackService->create('Doing', $boardId, 1); - $defaultStacks[] = $this->stackService->create('Done', $boardId, 1); - - $defaultCards[] = $this->cardService->create('Example Task 3', $defaultStacks[0]->getId(), 'text', 0, $userId); - $defaultCards[] = $this->cardService->create('Example Task 2', $defaultStacks[1]->getId(), 'text', 0, $userId); - $defaultCards[] = $this->cardService->create('Example Task 1', $defaultStacks[2]->getId(), 'text', 0, $userId); + $defaultCards[] = $this->cardService->create('Example Task 3', $defaultStacks[0]->getId(), 'text', 0, $userId); + $defaultCards[] = $this->cardService->create('Example Task 2', $defaultStacks[1]->getId(), 'text', 0, $userId); + $defaultCards[] = $this->cardService->create('Example Task 1', $defaultStacks[2]->getId(), 'text', 0, $userId); } } \ No newline at end of file