addType('id', Types::INTEGER); $this->addType('userId', Types::STRING); $this->addType('title', Types::STRING); $this->addType('boardId', Types::INTEGER); $this->addType('sourceStackId', Types::INTEGER); $this->addType('targetStackId', Types::INTEGER); $this->addType('filterUserIds', Types::STRING); $this->addType('filterLabelIds', Types::STRING); $this->addType('dateField', Types::STRING); $this->addType('notifyEmail', Types::BOOLEAN); $this->addType('enabled', Types::BOOLEAN); $this->addType('lastRun', Types::DATETIME); } /** * The date field to evaluate, never anything else. * * Rows written before the column existed carry 'due' from the schema * default, but a freshly constructed entity holds `null` and a hand-edited * row could hold anything. Falling back to the due date keeps the old * behaviour for every value that is not explicitly the start date — the * safe direction, since 'due' is what every workflow meant before this * choice existed. * * @return self::DATE_FIELD_* */ public function getDateFieldOrDue(): string { $field = $this->getDateField(); return in_array($field, self::DATE_FIELDS, true) ? $field : self::DATE_FIELD_DUE; } /** * @return string[] */ public function getFilterUserIdsArray(): array { return $this->decodeIds($this->getFilterUserIds()); } /** * @return int[] */ public function getFilterLabelIdsArray(): array { return array_map('intval', $this->decodeIds($this->getFilterLabelIds())); } /** * @return string[] */ private function decodeIds(?string $json): array { if ($json === null || $json === '') { return []; } $decoded = json_decode($json, true); return is_array($decoded) ? array_values($decoded) : []; } public function jsonSerialize(): array { return [ 'id' => $this->getId(), 'userId' => $this->getUserId(), 'title' => $this->getTitle(), 'boardId' => $this->getBoardId(), 'sourceStackId' => $this->getSourceStackId(), 'targetStackId' => $this->getTargetStackId(), 'filterUserIds' => $this->getFilterUserIdsArray(), 'filterLabelIds' => $this->getFilterLabelIdsArray(), 'dateField' => $this->getDateFieldOrDue(), 'notifyEmail' => (bool)$this->getNotifyEmail(), 'enabled' => (bool)$this->getEnabled(), 'lastRun' => $this->getLastRun()?->format(\DateTimeInterface::ATOM), ]; } }