This commit is contained in:
Patrick Niebeling
2025-03-12 11:19:44 +01:00
parent 7f683fcec1
commit 9538c99576
15 changed files with 122 additions and 242 deletions

View File

@ -1,61 +0,0 @@
<?php
namespace OCA\Deckflow\Service;
use OCP\IDBConnection;
use OCP\IUserSession;
use OCA\Deck\Service\DeckService;
class WorkflowService {
private $db;
private $userSession;
private $deckService;
public function __construct(IDBConnection $db, IUserSession $userSession, DeckService $deckService) {
$this->db = $db;
$this->userSession = $userSession;
$this->deckService = $deckService;
}
// Speichert die Workflows
public function saveWorkflows($deckId, $sourceStackId, $targetStackId) {
$userId = $this->userSession->getUser()->getUID();
$this->db->executeQuery("INSERT INTO *PREFIX*deckflow_workflows (user_id, deck_id, source_stack_id, target_stack_id)
VALUES (?, ?, ?, ?)", [
$userId,
$deckId,
$sourceStackId,
$targetStackId
]);
}
// Ruft alle Workflows für den aktuellen Benutzer ab
public function getWorkflows() {
$userId = $this->userSession->getUser()->getUID();
$result = $this->db->executeQuery("SELECT * FROM *PREFIX*deckflow_workflows WHERE user_id = ?", [$userId]);
return $result->fetchAll();
}
// Webhook zur Ausführung des Workflows, Karten zu verschieben
public function moveOverdueCards($deckId, $sourceStackId, $targetStackId) {
$deck = $this->deckService->getDeckById($deckId);
$sourceStack = $deck->getStackById($sourceStackId);
$targetStack = $deck->getStackById($targetStackId);
foreach ($sourceStack->getCards() as $card) {
if ($this->isCardOverdue($card)) {
$this->moveCardToTargetStack($card, $targetStack);
}
}
}
private function isCardOverdue($card) {
$dueDate = $card->getDueDate();
return $dueDate && $dueDate < time();
}
private function moveCardToTargetStack($card, $targetStack) {
$this->deckService->moveCardToStack($card, $targetStack);
}
}