From a36dfcc14448422da75a5fc8048f74593e4893df Mon Sep 17 00:00:00 2001 From: Ryan Fletcher Date: Tue, 10 Jul 2018 21:16:24 -0400 Subject: [PATCH] first attempt at writing the checkFirstRun() in DefaultBoardService.php Signed-off-by: Ryan Fletcher --- lib/Controller/PageController.php | 7 ++----- lib/Service/DefaultBoardService.php | 27 +++++++++++++++++---------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php index 8670e61ce..7a51bffd5 100644 --- a/lib/Controller/PageController.php +++ b/lib/Controller/PageController.php @@ -57,14 +57,11 @@ class PageController extends Controller { 'user' => $this->userId, 'maxUploadSize' => \OCP\Util::uploadLimit(), ]; - - // run the checkFirstRun() method from OCA\Deck\Service\DefaultBoardService here - // if the board is not created, then run createDefaultBoard() from the defaultBoardService here. - if ($this->defaultBoardService->checkFirstRun($this->userId)) { + + if ($this->defaultBoardService->checkFirstRun($this->userId, $AppName)) { $this->defaultBoardService->createDefaultBoard('Personal', $this->userId, '000000'); } - return new TemplateResponse('deck', 'main', $params); } diff --git a/lib/Service/DefaultBoardService.php b/lib/Service/DefaultBoardService.php index a93a28d7e..33463e958 100644 --- a/lib/Service/DefaultBoardService.php +++ b/lib/Service/DefaultBoardService.php @@ -26,29 +26,36 @@ namespace OCA\Deck\Service; use OCA\Deck\Service\BoardService; use OCA\Deck\Service\StackService; use OCA\Deck\Service\CardService; +use OCP\IConfig; class DefaultBoardService { - protected $boardService; - protected $stackService; - protected $cardService; + private $boardService; + private $stackService; + private $cardService; + private $config; public function __construct( BoardService $boardService, StackService $stackService, - CardService $cardService) { + CardService $cardService, + IConfig $config + ) { $this->boardService = $boardService; $this->stackService = $stackService; $this->cardService = $cardService; + $this->config = $config; } - - public function checkFirstRun($userId) { - // Add a user config value like 'firstrun' to check if the default board - // has already been created for the user + public function checkFirstRun($userId, $appName) { + $firstRun = $this->config->getUserValue($userId,$appName,'firstRun','yes'); + + if ($firstRun == 'yes') { + $this->config->setUserValue($userId,$appName,'firstRun','no'); + return true; + } - // TODO: Remove hardcode once I figure out how to do the config value. return false; } @@ -66,5 +73,5 @@ class DefaultBoardService { $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