First commit

This commit is contained in:
Patrick Niebeling
2025-03-12 10:33:41 +01:00
commit 05f50ea068
5 changed files with 168 additions and 0 deletions

View File

@ -0,0 +1,47 @@
<?php
namespace OCA\DeckFlow\BackgroundJobs;
use OCP\BackgroundJob\TimedJob;
use OCA\Deck\Service\CardService;
use OCP\IConfig;
use OCP\ILogger;
use OCP\IUserManager;
use DateTime;
use DateTimeZone;
class CheckOverdueCards extends TimedJob {
private CardService $cardService;
private IConfig $config;
private IUserManager $userManager;
private ILogger $logger;
public function __construct(CardService $cardService, IConfig $config, IUserManager $userManager, ILogger $logger) {
parent::__construct();
$this->cardService = $cardService;
$this->config = $config;
$this->userManager = $userManager;
$this->logger = $logger;
$this->setInterval(3600);
}
protected function run($argument) {
$users = $this->userManager->search('');
foreach ($users as $user) {
$userId = $user->getUID();
$rules = json_decode($this->config->getUserValue($userId, 'deckflow', 'rules', '[]'), true);
foreach ($rules as $rule) {
$sourceStack = $rule['source_stack'];
$targetStack = $rule['target_stack'];
$cards = $this->cardService->findAllCardsInStack($sourceStack);
$now = new DateTime('now', new DateTimeZone('UTC'));
foreach ($cards as $card) {
if (isset($card['duedate']) && new DateTime($card['duedate'], new DateTimeZone('UTC')) < $now) {
$this->cardService->updateCard($card['id'], ['stackId' => $targetStack]);
}
}
}
}
}
}

44
lib/Settings/Personal.php Normal file
View File

@ -0,0 +1,44 @@
<?php
namespace OCA\DeckFlow\Settings;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\Settings\ISettings;
use OCP\IConfig;
use OCP\IUserSession;
use OCA\Deck\Service\BoardService;
use OCA\Deck\Service\StackService;
class Personal implements ISettings {
private IConfig $config;
private IUserSession $userSession;
private BoardService $boardService;
private StackService $stackService;
public function __construct(IConfig $config, IUserSession $userSession, BoardService $boardService, StackService $stackService) {
$this->config = $config;
$this->userSession = $userSession;
$this->boardService = $boardService;
$this->stackService = $stackService;
}
public function getForm() {
$userId = $this->userSession->getUser()->getUID();
$rules = json_decode($this->config->getUserValue($userId, 'deckflow', 'rules', '[]'), true);
$boards = $this->boardService->findAllBoards();
$stacks = [];
foreach ($boards as $board) {
$stacks[$board['id']] = $this->stackService->findAllStacksInBoard($board['id']);
}
return new TemplateResponse('deckflow', 'personal', [
'rules' => $rules,
'boards' => $boards,
'stacks' => $stacks
]);
}
public function getSection() { return 'deckflow'; }
public function getPriority() { return 50; }
}