Skip to content

Commit

Permalink
first attempt at writing the checkFirstRun() in DefaultBoardService.php
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Fletcher <ryan.fletcher@codepassion.ca>
  • Loading branch information
Ryan Fletcher committed Jul 11, 2018
1 parent 683354d commit a36dfcc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
7 changes: 2 additions & 5 deletions lib/Controller/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,11 @@ public function index() {
'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 comment was marked as resolved.

Copy link
@juliusknorr

juliusknorr Jul 11, 2018

Member

$AppName is undefined, I guess that is the reason that the config value is not persisted properly.

This comment was marked as resolved.

Copy link
@juliusknorr

juliusknorr Jul 11, 2018

Member

Should be $this->appName

$this->defaultBoardService->createDefaultBoard('Personal', $this->userId, '000000');
}


return new TemplateResponse('deck', 'main', $params);
}

Expand Down
27 changes: 17 additions & 10 deletions lib/Service/DefaultBoardService.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,36 @@
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 comment was marked as resolved.

Copy link
@juliusknorr

juliusknorr Jul 11, 2018

Member

There should probably also a check if the user doesn't have any boards. If there are some boards already the user already used deck. That would still create the default board for users after the app gets updated.

This comment was marked as resolved.

Copy link
@juliusknorr

juliusknorr Jul 11, 2018

Member

Please use strict comparison (=== instead of ==)

$this->config->setUserValue($userId,$appName,'firstRun','no');
return true;
}

// TODO: Remove hardcode once I figure out how to do the config value.
return false;
}

Expand All @@ -66,5 +73,5 @@ public function createDefaultBoard($title, $userId, $color) {
$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);
}
}
}

0 comments on commit a36dfcc

Please sign in to comment.