first commit
This commit is contained in:
124
src/Models/Task.php
Normal file
124
src/Models/Task.php
Normal file
@@ -0,0 +1,124 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Utils\Enums\TaskStatus;
|
||||
|
||||
class Task
|
||||
{
|
||||
|
||||
private int $id;
|
||||
|
||||
private string $title;
|
||||
|
||||
private string $description;
|
||||
|
||||
private TaskStatus $status;
|
||||
|
||||
private string $endDt;
|
||||
|
||||
private string $startDt;
|
||||
|
||||
|
||||
public function __construct($status = TaskStatus::STARTED)
|
||||
{
|
||||
$this->status = $status;
|
||||
|
||||
}
|
||||
|
||||
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 static function fromArray($taskData): Task
|
||||
{
|
||||
$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'] ?? '';
|
||||
|
||||
return $task;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the array representation of the database entity.
|
||||
* @return array
|
||||
*/
|
||||
public function persist(): array
|
||||
{
|
||||
return [
|
||||
'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
|
||||
|
||||
];
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user