Completed checkFirstRun() in DefaultBoardService.php

Signed-off-by: Ryan Fletcher <ryan.fletcher@codepassion.ca>
This commit is contained in:
Ryan Fletcher
2018-07-11 08:02:54 -04:00
parent a36dfcc144
commit 8a8cffc542
2 changed files with 36 additions and 31 deletions

View File

@@ -58,7 +58,7 @@ class PageController extends Controller {
'maxUploadSize' => \OCP\Util::uploadLimit(), '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'); $this->defaultBoardService->createDefaultBoard('Personal', $this->userId, '000000');
} }

View File

@@ -1,6 +1,6 @@
<?php <?php
/** /**
* @copyright Copyright (c) 2016 Julius Härtl <jus@bitgrid.net> * @copyright Copyright (c) 2018 Ryan Fletcher <ryan.fletcher@codepassion.ca>
* *
* @author Ryan Fletcher <ryan.fletcher@codepassion.ca> * @author Ryan Fletcher <ryan.fletcher@codepassion.ca>
* *
@@ -23,6 +23,7 @@
namespace OCA\Deck\Service; namespace OCA\Deck\Service;
use OCA\Deck\Db\BoardMapper;
use OCA\Deck\Service\BoardService; use OCA\Deck\Service\BoardService;
use OCA\Deck\Service\StackService; use OCA\Deck\Service\StackService;
use OCA\Deck\Service\CardService; use OCA\Deck\Service\CardService;
@@ -30,48 +31,52 @@ use OCP\IConfig;
class DefaultBoardService { class DefaultBoardService {
private $boardService; private $boardMapper;
private $stackService; private $boardService;
private $cardService; private $stackService;
private $config; private $cardService;
private $config;
public function __construct( public function __construct(
BoardService $boardService, BoardMapper $boardMapper,
StackService $stackService, BoardService $boardService,
CardService $cardService, StackService $stackService,
IConfig $config CardService $cardService,
) { IConfig $config
) {
$this->boardService = $boardService; $this->boardService = $boardService;
$this->stackService = $stackService; $this->stackService = $stackService;
$this->cardService = $cardService; $this->cardService = $cardService;
$this->config = $config; $this->config = $config;
$this->boardMapper = $boardMapper;
} }
public function checkFirstRun($userId, $appName) { 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') { return false;
$this->config->setUserValue($userId,$appName,'firstRun','no');
return true;
}
return false;
} }
public function createDefaultBoard($title, $userId, $color) { public function createDefaultBoard($title, $userId, $color) {
$defaultBoard = $this->boardService->create($title, $userId, $color); $defaultBoard = $this->boardService->create($title, $userId, $color);
$defaultStacks = []; $defaultStacks = [];
$defaultCards = []; $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(); $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);
$defaultStacks[] = $this->stackService->create('To do', $boardId, 1); $defaultCards[] = $this->cardService->create('Example Task 1', $defaultStacks[2]->getId(), 'text', 0, $userId);
$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);
} }
} }