Backup #1380
| ID | 1380 |
| Dateipfad | /var/www/dev.campus.systemische-tools.de/src/Domain/Entity/Task.php |
| Version | 3 |
| Typ |
modified |
| Größe | 8.2 KB |
| Hash | 22356e36580f170d298cc61c594a7bf5460ccc10ea3b8180b28fd3aae7c1db07 |
| Datum | 2025-12-25 16:56:58 |
| Geändert von | claude-code-hook |
| Grund | Claude Code Pre-Hook Backup vor Edit-Operation |
| Datei existiert |
Ja
|
Dateiinhalt
<?php
declare(strict_types=1);
namespace Domain\Entity;
// @responsibility: Task-Entität - Rich Domain Model mit Business-Logik
use Domain\ValueObject\TaskStatus;
use Domain\ValueObject\TaskType;
class Task
{
private ?int $id = null;
private string $uuid;
private string $title;
private ?string $description = null;
private TaskType $type;
private TaskStatus $status;
private string $createdBy;
private string $createdByType = 'human';
private ?int $parentTaskId = null;
private ?\DateTimeImmutable $dueDate = null;
private \DateTimeImmutable $createdAt;
private \DateTimeImmutable $updatedAt;
private ?\DateTimeImmutable $completedAt = null;
private array $metadata = [];
private function __construct()
{
$this->uuid = $this->generateUuid();
$this->status = TaskStatus::PENDING;
$this->type = TaskType::HUMAN_TASK;
$this->createdAt = new \DateTimeImmutable();
$this->updatedAt = new \DateTimeImmutable();
}
public static function create(
string $title,
string $createdBy,
?string $description = null,
?TaskType $type = null,
?int $parentTaskId = null,
?\DateTimeImmutable $dueDate = null
): self {
$task = new self();
$task->title = $title;
$task->createdBy = $createdBy;
$task->description = $description;
if ($type !== null) {
$task->type = $type;
}
if ($parentTaskId !== null) {
$task->parentTaskId = $parentTaskId;
}
if ($dueDate !== null) {
$task->dueDate = $dueDate;
}
return $task;
}
private function generateUuid(): string
{
return sprintf(
'%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
mt_rand(0, 0xffff),
mt_rand(0, 0xffff),
mt_rand(0, 0xffff),
mt_rand(0, 0x0fff) | 0x4000,
mt_rand(0, 0x3fff) | 0x8000,
mt_rand(0, 0xffff),
mt_rand(0, 0xffff),
mt_rand(0, 0xffff)
);
}
// Getters
public function getId(): ?int
{
return $this->id;
}
public function getUuid(): string
{
return $this->uuid;
}
public function getTitle(): string
{
return $this->title;
}
public function getDescription(): ?string
{
return $this->description;
}
public function getType(): string
{
return $this->type;
}
public function getStatus(): TaskStatus
{
return $this->status;
}
public function getCreatedBy(): string
{
return $this->createdBy;
}
public function getCreatedByType(): string
{
return $this->createdByType;
}
public function getParentTaskId(): ?int
{
return $this->parentTaskId;
}
public function getDueDate(): ?\DateTimeImmutable
{
return $this->dueDate;
}
public function getCreatedAt(): \DateTimeImmutable
{
return $this->createdAt;
}
public function getUpdatedAt(): \DateTimeImmutable
{
return $this->updatedAt;
}
public function getCompletedAt(): ?\DateTimeImmutable
{
return $this->completedAt;
}
public function getMetadata(): array
{
return $this->metadata;
}
// Setters
public function setId(int $id): self
{
$this->id = $id;
return $this;
}
public function setUuid(string $uuid): self
{
$this->uuid = $uuid;
return $this;
}
public function setTitle(string $title): self
{
$this->title = $title;
$this->updatedAt = new \DateTimeImmutable();
return $this;
}
public function setDescription(?string $description): self
{
$this->description = $description;
$this->updatedAt = new \DateTimeImmutable();
return $this;
}
public function setType(string $type): self
{
$this->type = $type;
$this->updatedAt = new \DateTimeImmutable();
return $this;
}
public function setStatus(TaskStatus $status): self
{
if ($this->status->canTransitionTo($status) || $this->id === null) {
$this->status = $status;
$this->updatedAt = new \DateTimeImmutable();
if ($status->isTerminal()) {
$this->completedAt = new \DateTimeImmutable();
}
}
return $this;
}
public function setCreatedBy(string $createdBy): self
{
$this->createdBy = $createdBy;
return $this;
}
public function setCreatedByType(string $createdByType): self
{
$this->createdByType = $createdByType;
return $this;
}
public function setParentTaskId(?int $parentTaskId): self
{
$this->parentTaskId = $parentTaskId;
$this->updatedAt = new \DateTimeImmutable();
return $this;
}
public function setDueDate(?\DateTimeImmutable $dueDate): self
{
$this->dueDate = $dueDate;
$this->updatedAt = new \DateTimeImmutable();
return $this;
}
public function setCreatedAt(\DateTimeImmutable $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function setUpdatedAt(\DateTimeImmutable $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
public function setCompletedAt(?\DateTimeImmutable $completedAt): self
{
$this->completedAt = $completedAt;
return $this;
}
public function setMetadata(array $metadata): self
{
$this->metadata = $metadata;
$this->updatedAt = new \DateTimeImmutable();
return $this;
}
public function toArray(): array
{
return [
'id' => $this->id,
'uuid' => $this->uuid,
'title' => $this->title,
'description' => $this->description,
'type' => $this->type,
'status' => $this->status->value,
'created_by' => $this->createdBy,
'created_by_type' => $this->createdByType,
'parent_task_id' => $this->parentTaskId,
'due_date' => $this->dueDate?->format('Y-m-d H:i:s'),
'created_at' => $this->createdAt->format('Y-m-d H:i:s.u'),
'updated_at' => $this->updatedAt->format('Y-m-d H:i:s.u'),
'completed_at' => $this->completedAt?->format('Y-m-d H:i:s.u'),
'metadata' => $this->metadata,
];
}
public static function fromArray(array $data): self
{
$task = new self();
if (isset($data['id'])) {
$task->setId((int) $data['id']);
}
if (isset($data['uuid'])) {
$task->setUuid($data['uuid']);
}
if (isset($data['title'])) {
$task->setTitle($data['title']);
}
if (isset($data['description'])) {
$task->setDescription($data['description']);
}
if (isset($data['type'])) {
$task->setType($data['type']);
}
if (isset($data['status'])) {
$task->status = TaskStatus::from($data['status']);
}
if (isset($data['created_by'])) {
$task->setCreatedBy($data['created_by']);
}
if (isset($data['created_by_type'])) {
$task->setCreatedByType($data['created_by_type']);
}
if (isset($data['parent_task_id'])) {
$task->setParentTaskId((int) $data['parent_task_id']);
}
if (isset($data['due_date'])) {
$task->setDueDate(new \DateTimeImmutable($data['due_date']));
}
if (isset($data['created_at'])) {
$task->setCreatedAt(new \DateTimeImmutable($data['created_at']));
}
if (isset($data['updated_at'])) {
$task->setUpdatedAt(new \DateTimeImmutable($data['updated_at']));
}
if (isset($data['completed_at'])) {
$task->setCompletedAt(new \DateTimeImmutable($data['completed_at']));
}
if (isset($data['metadata'])) {
$metadata = is_string($data['metadata']) ? json_decode($data['metadata'], true) : $data['metadata'];
$task->setMetadata($metadata ?? []);
}
return $task;
}
}
Vollständig herunterladen
Aktionen
Andere Versionen dieser Datei
| ID |
Version |
Typ |
Größe |
Datum |
| 2012 |
28 |
modified |
7.4 KB |
2025-12-28 14:21 |
| 2010 |
27 |
modified |
7.5 KB |
2025-12-28 14:20 |
| 2009 |
26 |
modified |
7.7 KB |
2025-12-28 14:19 |
| 2008 |
25 |
modified |
7.8 KB |
2025-12-28 14:19 |
| 2007 |
24 |
modified |
8.1 KB |
2025-12-28 14:18 |
| 2005 |
23 |
modified |
8.2 KB |
2025-12-28 14:18 |
| 2004 |
22 |
modified |
8.1 KB |
2025-12-28 14:18 |
| 1951 |
21 |
modified |
8.5 KB |
2025-12-28 02:25 |
| 1950 |
20 |
modified |
8.8 KB |
2025-12-28 02:24 |
| 1473 |
19 |
modified |
8.7 KB |
2025-12-25 17:02 |
| 1472 |
18 |
modified |
8.7 KB |
2025-12-25 17:02 |
| 1471 |
17 |
modified |
8.6 KB |
2025-12-25 17:02 |
| 1470 |
16 |
modified |
8.6 KB |
2025-12-25 17:02 |
| 1468 |
15 |
modified |
8.5 KB |
2025-12-25 17:02 |
| 1467 |
14 |
modified |
8.5 KB |
2025-12-25 17:02 |
| 1440 |
13 |
modified |
8.1 KB |
2025-12-25 17:00 |
| 1433 |
12 |
modified |
8.2 KB |
2025-12-25 16:59 |
| 1427 |
11 |
modified |
8.4 KB |
2025-12-25 16:59 |
| 1420 |
10 |
modified |
8.5 KB |
2025-12-25 16:59 |
| 1413 |
9 |
modified |
8.5 KB |
2025-12-25 16:58 |
| 1412 |
8 |
modified |
8.6 KB |
2025-12-25 16:58 |
| 1405 |
7 |
modified |
8.9 KB |
2025-12-25 16:58 |
| 1396 |
6 |
modified |
9.2 KB |
2025-12-25 16:58 |
| 1390 |
5 |
modified |
10.7 KB |
2025-12-25 16:57 |
| 1384 |
4 |
modified |
8.2 KB |
2025-12-25 16:57 |
| 1380 |
3 |
modified |
8.2 KB |
2025-12-25 16:56 |
| 1378 |
2 |
modified |
7.5 KB |
2025-12-25 16:56 |
| 807 |
1 |
modified |
7.4 KB |
2025-12-23 08:07 |
← Zurück zur Übersicht