diff --git a/src/Models/Task.php b/src/Models/Task.php index ee0ebee..d848001 100644 --- a/src/Models/Task.php +++ b/src/Models/Task.php @@ -10,6 +10,16 @@ class Task private int $id; + + // NOTE: This ID is hardcoded for now because we haven't implemented users yet! Specific logic will be required later on. + private const task_owner = 1; + + private Carbon $createdAt; + + private Carbon $updatedAt; + + + // NOTE: This is actually the "name" in the db. private string $title; private string $description; @@ -27,6 +37,22 @@ class Task } + + 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; @@ -94,16 +120,19 @@ class Task return $this; } - public static function fromArray($taskData): self + public static function fromArray($data): self { $task = new self(); - $task->id = $taskData['id'] ?? null; - $task->title = $taskData['name'] ?? ''; - $task->description = $taskData['description'] ?? ''; - $task->status = $taskData['status'] ?? 'started'; - $task->startDt = $taskData['start'] ?? ''; - $task->endDt = $taskData['end'] ?? ''; + $task->id = $data['id'] ?? null; + // 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; }