Files
petriandClaude Opus 5.5 dfe4941f02 Add checklists to tasks on the job page
Tasks get an ordered checklist (spec 8.2, phase 3): items are checked
done with who and when recorded, also by subcontractors attached to the
job; others add, rename, reorder and remove items. Items go with their
task. The spec gets a phase 3 chapter (18.1), and open questions move
to chapter 19.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-24 16:38:08 +02:00

98 lines
2.1 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Modules\Jobs\Domain\Entities;
use App\Modules\Jobs\Domain\ValueObjects\ChecklistItemText;
use DateTimeImmutable;
/**
* One item of a task's checklist (todo), checked done by someone or not.
*/
final class ChecklistItem
{
private function __construct(
private ?int $id,
private int $taskId,
private ChecklistItemText $text,
private int $sortOrder,
private ?DateTimeImmutable $doneAt,
private ?int $doneBy,
) {}
public static function create(int $taskId, ChecklistItemText $text, int $sortOrder): self
{
return new self(null, $taskId, $text, $sortOrder, null, null);
}
public static function reconstitute(int $id, int $taskId, ChecklistItemText $text, int $sortOrder, ?DateTimeImmutable $doneAt, ?int $doneBy): self
{
return new self($id, $taskId, $text, $sortOrder, $doneAt, $doneBy);
}
public function rename(ChecklistItemText $text): void
{
$this->text = $text;
}
/**
* Checking an item that already is done keeps who did it and when.
*/
public function check(int $userId, DateTimeImmutable $at): void
{
if ($this->doneAt !== null) {
return;
}
$this->doneAt = $at;
$this->doneBy = $userId;
}
public function uncheck(): void
{
$this->doneAt = null;
$this->doneBy = null;
}
public function swapOrderWith(self $other): void
{
[$this->sortOrder, $other->sortOrder] = [$other->sortOrder, $this->sortOrder];
}
public function id(): ?int
{
return $this->id;
}
public function taskId(): int
{
return $this->taskId;
}
public function text(): ChecklistItemText
{
return $this->text;
}
public function sortOrder(): int
{
return $this->sortOrder;
}
public function isDone(): bool
{
return $this->doneAt !== null;
}
public function doneAt(): ?DateTimeImmutable
{
return $this->doneAt;
}
public function doneBy(): ?int
{
return $this->doneBy;
}
}