status = $status; } public function getTaskOwner(): int { return self::task_owner; } /** * Updates Task's last updated time. * @return void */ public function touch(): void { $this->updatedAt = Carbon::now(); } public function getTitle(): string { return $this->title; } public function setTitle(string $title): self { $this->title = $title; return $this; } public function getDescription(): string { return $this->description; } public function setDescription(string $description): self { $this->description = $description; return $this; } public function getStartDt(): string { return $this->startDt; } public function setStartDt(string $startDt): self { $this->startDt = Carbon::parse($startDt)->toDateTimeString(); return $this; } public function getEndDt(): string { return $this->endDt; } public function setEndDt(string $endDt): self { $this->endDt = Carbon::parse($endDt)->toDateTimeString(); return $this; } public function getStatus(): TaskStatus { return $this->status; } public function setStatus(TaskStatus $status): self { $this->status = $status; return $this; } public function getTaskId(): int { return $this->id; } public function setId(int $id): Task { $this->id = $id; return $this; } public static function fromArray($data): self { $task = new self(); $task->id = $data['id']; // task owner is discarded from input array $task->createdAt = Carbon::parse($data['created_at']); $task->updatedAt = Carbon::parse($data['updated_at']); $task->title = $data['name'] ?? ''; $task->description = $data['description'] ?? ''; $task->startDt = $data['start'] ?? ''; $task->endDt = $data['end'] ?? ''; $task->status = TaskStatus::tryFrom($data['status_id']) ?? TaskStatus::STARTED; return $task; } /** * Returns the array representation of the database entity. * @return array */ public function persist(): array { return [ 'id' => $this->id ?? null, 'task_owner' => 1, // fake hard-coded user for now 'created_at' => Carbon::now()->toDateTimeString(), 'updated_at' => Carbon::now()->toDateTimeString(), 'name' => $this->getTitle(), 'description' => $this->getDescription(), 'start' => $this->getStartDt(), 'end' => $this->getEndDt(), 'status_id' => $this->getStatus()->value ]; } }