Update Card serialization (jsonSerialize usages) to use CardDetails model

Signed-off-by: Raul <raul@nextcloud.com>
This commit is contained in:
Raul
2022-05-03 12:59:58 +02:00
committed by Julius Härtl
parent 4c729530ce
commit 6ae61368a7

View File

@@ -93,7 +93,7 @@ class OverviewService {
public function findUpcomingCards(string $userId): array {
$userBoards = $this->boardMapper->findAllForUser($userId);
$foundCards = [];
$overview = [];
foreach ($userBoards as $userBoard) {
if (count($userBoard->getAcl()) === 0) {
// private board: get cards with due date
@@ -103,14 +103,27 @@ class OverviewService {
$cards = $this->cardMapper->findToMeOrNotAssignedCards($userBoard->getId(), $userId);
}
$foundCards[] = array_map(
function (Card $card) use ($userBoard, $userId) {
$this->enrich($card, $userId);
return (new CardDetails($card, $userBoard))->jsonSerialize();
},
$cards
);
foreach ($cards as $card) {
$this->enrich($card, $userId);
$diffDays = $card->getDaysUntilDue();
$key = 'later';
if ($card->getDuedate() === null) {
$key = 'nodue';
} elseif ($diffDays < 0) {
$key = 'overdue';
} elseif ($diffDays === 0) {
$key = 'today';
} elseif ($diffDays === 1) {
$key = 'tomorrow';
} elseif ($diffDays <= 7) {
$key = 'nextSevenDays';
}
$card = (new CardDetails($card, $userBoard));
$overview[$key][] = $card->jsonSerialize();
}
}
return array_merge(...$foundCards);
return $overview;
}
}