From 6ae61368a7a686e85ebb7df44237fd62587c1ced Mon Sep 17 00:00:00 2001 From: Raul Date: Tue, 3 May 2022 12:59:58 +0200 Subject: [PATCH] Update Card serialization (`jsonSerialize` usages) to use CardDetails model Signed-off-by: Raul --- lib/Service/OverviewService.php | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/lib/Service/OverviewService.php b/lib/Service/OverviewService.php index 0d883141c..f45f22f33 100644 --- a/lib/Service/OverviewService.php +++ b/lib/Service/OverviewService.php @@ -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; } }