-
Notifications
You must be signed in to change notification settings - Fork 323
Expand file tree
/
Copy pathCard.php
More file actions
186 lines (163 loc) · 5.11 KB
/
Card.php
File metadata and controls
186 lines (163 loc) · 5.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Deck\Db;
use DateTime;
use DateTimeZone;
use Sabre\VObject\Component\VCalendar;
/**
* @method string getTitle()
* @method void setTitle(string $title)
* @method string getDescription()
* @method string getDescriptionPrev()
* @method string getColor()
* @method string setColor(string $color)
* @method int getStackId()
* @method void setStackId(int $stackId)
* @method int getOrder()
* @method void setOrder(int $order)
* @method int getLastModified()
* @method int getCreatedAt()
* @method bool getArchived()
* @method string getType()
* @method void setType(string $type)
* @method int getDeletedAt()
* @method void setDeletedAt(int $deletedAt)
* @method bool getNotified()
* @method ?DateTime getDone()
* @method void setDone(?DateTime $done)
*
* @method void setLabels(Label[] $labels)
* @method null|Label[] getLabels()
*
* @method void setAssignedUsers(Assignment[] $users)
* @method null|User[] getAssignedUsers()
*
* @method void setAttachments(Attachment[] $attachments)
* @method null|Attachment[] getAttachments()
*
* @method void setAttachmentCount(int $count)
* @method null|int getAttachmentCount()
*
* @method void setCommentsUnread(int $count)
* @method null|int getCommentsUnread()
*
* @method void setCommentsCount(int $count)
* @method null|int getCommentsCount()
*
* @method void setOwner(string $user)
* @method null|string getOwner()
*
* @method void setRelatedStack(Stack $stack)
* @method null|Stack getRelatedStack()
*
* @method void setRelatedBoard(Board $board)
* @method null|Board getRelatedBoard()
*/
class Card extends RelationalEntity {
public const TITLE_MAX_LENGTH = 255;
protected string $title = '';
protected $description;
protected $color = null;
protected $descriptionPrev;
protected $stackId;
protected $type;
protected $lastModified;
protected $lastEditor;
protected $createdAt;
protected $labels;
protected $assignedUsers;
protected array $attachments = [];
protected int $attachmentCount = 0;
protected $owner;
protected $order;
protected $archived = false;
protected $done = null;
protected $duedate;
protected $notified = false;
protected $deletedAt = 0;
protected $commentsUnread = 0;
protected $commentsCount = 0;
protected $relatedStack = null;
protected $relatedBoard = null;
private $databaseType = 'sqlite';
public const DUEDATE_FUTURE = 0;
public const DUEDATE_NEXT = 1;
public const DUEDATE_NOW = 2;
public const DUEDATE_OVERDUE = 3;
public function __construct() {
$this->addType('id', 'integer');
$this->addType('stackId', 'integer');
$this->addType('order', 'integer');
$this->addType('lastModified', 'integer');
$this->addType('createdAt', 'integer');
$this->addType('archived', 'boolean');
$this->addType('done', 'datetime');
$this->addType('notified', 'boolean');
$this->addType('deletedAt', 'integer');
$this->addType('duedate', 'datetime');
$this->addRelation('labels');
$this->addRelation('assignedUsers');
$this->addRelation('attachments');
$this->addRelation('attachmentCount');
$this->addRelation('participants');
$this->addRelation('commentsUnread');
$this->addRelation('commentsCount');
$this->addResolvable('owner');
$this->addRelation('relatedStack');
$this->addRelation('relatedBoard');
}
public function setDatabaseType($type) {
$this->databaseType = $type;
}
public function getCalendarObject(): VCalendar {
$calendar = new VCalendar();
$event = $calendar->createComponent('VTODO');
$event->UID = 'deck-card-' . $this->getId();
if ($this->getDuedate()) {
$creationDate = new DateTime();
$creationDate->setTimestamp($this->createdAt);
$event->DTSTAMP = $creationDate;
$event->DUE = new DateTime($this->getDuedate()->format('c'), new DateTimeZone('UTC'));
}
$event->add('RELATED-TO', 'deck-stack-' . $this->getStackId());
// FIXME: For write support: CANCELLED / IN-PROCESS handling
if ($this->getDone() || $this->getArchived()) {
$date = new DateTime();
$date->setTimestamp($this->getLastModified());
$event->STATUS = 'COMPLETED';
$event->COMPLETED = $this->getDone() ? $this->getDone() : $this->getArchived();
} else {
$event->STATUS = 'NEEDS-ACTION';
}
// $event->add('PERCENT-COMPLETE', 100);
$labels = $this->getLabels() ?? [];
$event->CATEGORIES = array_map(function ($label): string {
return $label->getTitle();
}, $labels);
$event->SUMMARY = $this->getTitle();
$event->DESCRIPTION = $this->getDescription();
$calendar->add($event);
return $calendar;
}
public function getDaysUntilDue(): ?int {
if ($this->getDuedate() === null) {
return null;
}
$today = new DateTime();
$today->setTime(0, 0);
$matchDate = DateTime::createFromInterface($this->getDuedate());
$matchDate->setTime(0, 0);
$diff = $today->diff($matchDate);
return (int)$diff->format('%R%a'); // Extract days count in interval
}
public function getCalendarPrefix(): string {
return 'card';
}
public function getETag(): string {
return md5((string)$this->getLastModified());
}
}