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()); } }