-
Notifications
You must be signed in to change notification settings - Fork 323
Expand file tree
/
Copy pathCardDetails.php
More file actions
88 lines (69 loc) · 2.11 KB
/
CardDetails.php
File metadata and controls
88 lines (69 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
/**
* SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Deck\Model;
use OCA\Deck\Db\Board;
use OCA\Deck\Db\Card;
use OCP\Collaboration\Reference\Reference;
class CardDetails extends Card {
private Card $card;
private ?Board $board;
private ?Reference $referenceData = null;
/** @psalm-suppress ConstructorSignatureMismatch */
public function __construct(Card $card, ?Board $board = null) {
parent::__construct();
$this->card = $card;
$this->board = $board;
}
public function setBoard(?Board $board): void {
$this->board = $board;
}
public function setReferenceData(?Reference $data): void {
$this->referenceData = $data;
}
public function jsonSerialize(array $extras = []): array {
$array = parent::jsonSerialize();
$array['overdue'] = $this->getDueStatus();
unset($array['notified']);
unset($array['descriptionPrev']);
unset($array['relatedStack']);
unset($array['relatedBoard']);
$array = $this->card->jsonSerialize();
unset($array['notified'], $array['descriptionPrev'], $array['relatedStack'], $array['relatedBoard']);
$array['overdue'] = $this->getDueStatus();
$this->appendBoardDetails($array);
$array['referenceData'] = $this->referenceData?->jsonSerialize();
return $array;
}
private function getDueStatus(): int {
$diffDays = $this->getDaysUntilDue();
if ($diffDays === null || $diffDays > 1) {
return static::DUEDATE_FUTURE;
}
if ($diffDays === 1) {
return static::DUEDATE_NEXT;
}
if ($diffDays === 0) {
return static::DUEDATE_NOW;
}
return static::DUEDATE_OVERDUE;
}
private function appendBoardDetails(&$array): void {
if (!$this->board) {
return;
}
$array['boardId'] = $this->board->id;
$array['board'] = (new BoardSummary($this->board))->jsonSerialize();
}
protected function getter(string $name): mixed {
return $this->card->getter($name);
}
public function __call(string $methodName, array $args) {
return $this->card->__call($methodName, $args);
}
public function getUpdatedFields(): array {
return $this->card->getUpdatedFields();
}
}