diff --git a/src/Entity/Task.php b/src/Entity/Task.php index 5956b3c..1a6828c 100644 --- a/src/Entity/Task.php +++ b/src/Entity/Task.php @@ -99,9 +99,15 @@ class Task #[Groups(['task:read', 'task:write'])] private bool $archived = false; + /** @var Collection */ + #[ORM\OneToMany(targetEntity: TaskDocument::class, mappedBy: 'task', cascade: ['remove'])] + #[Groups(['task:read'])] + private Collection $documents; + public function __construct() { - $this->tags = new ArrayCollection(); + $this->tags = new ArrayCollection(); + $this->documents = new ArrayCollection(); } public function getId(): ?int @@ -250,4 +256,10 @@ class Task return $this; } + + /** @return Collection */ + public function getDocuments(): Collection + { + return $this->documents; + } } diff --git a/src/Entity/TaskDocument.php b/src/Entity/TaskDocument.php new file mode 100644 index 0000000..9cced98 --- /dev/null +++ b/src/Entity/TaskDocument.php @@ -0,0 +1,164 @@ + ['task_document:read']], + denormalizationContext: ['groups' => ['task_document:write']], + order: ['id' => 'DESC'], +)] +#[ApiFilter(SearchFilter::class, properties: ['task' => 'exact'])] +#[ORM\Entity] +#[ORM\EntityListeners([TaskDocumentListener::class])] +class TaskDocument +{ + #[ORM\Id] + #[ORM\GeneratedValue] + #[ORM\Column] + #[Groups(['task_document:read', 'task:read'])] + private ?int $id = null; + + #[ORM\ManyToOne(targetEntity: Task::class, inversedBy: 'documents')] + #[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')] + #[Groups(['task_document:read', 'task_document:write'])] + private ?Task $task = null; + + #[ORM\Column(length: 255)] + #[Groups(['task_document:read', 'task:read'])] + private ?string $originalName = null; + + #[ORM\Column(length: 255)] + #[Groups(['task_document:read', 'task:read'])] + private ?string $fileName = null; + + #[ORM\Column(length: 100)] + #[Groups(['task_document:read', 'task:read'])] + private ?string $mimeType = null; + + #[ORM\Column] + #[Groups(['task_document:read', 'task:read'])] + private ?int $size = null; + + #[ORM\Column(type: 'datetime_immutable')] + #[Groups(['task_document:read', 'task:read'])] + private ?DateTimeImmutable $createdAt = null; + + #[ORM\ManyToOne(targetEntity: User::class)] + #[ORM\JoinColumn(nullable: true, onDelete: 'SET NULL')] + #[Groups(['task_document:read', 'task:read'])] + private ?User $uploadedBy = null; + + public function getId(): ?int + { + return $this->id; + } + + public function getTask(): ?Task + { + return $this->task; + } + + public function setTask(?Task $task): static + { + $this->task = $task; + + return $this; + } + + public function getOriginalName(): ?string + { + return $this->originalName; + } + + public function setOriginalName(string $originalName): static + { + $this->originalName = $originalName; + + return $this; + } + + public function getFileName(): ?string + { + return $this->fileName; + } + + public function setFileName(string $fileName): static + { + $this->fileName = $fileName; + + return $this; + } + + public function getMimeType(): ?string + { + return $this->mimeType; + } + + public function setMimeType(string $mimeType): static + { + $this->mimeType = $mimeType; + + return $this; + } + + public function getSize(): ?int + { + return $this->size; + } + + public function setSize(int $size): static + { + $this->size = $size; + + return $this; + } + + public function getCreatedAt(): ?DateTimeImmutable + { + return $this->createdAt; + } + + public function setCreatedAt(DateTimeImmutable $createdAt): static + { + $this->createdAt = $createdAt; + + return $this; + } + + public function getUploadedBy(): ?User + { + return $this->uploadedBy; + } + + public function setUploadedBy(?User $uploadedBy): static + { + $this->uploadedBy = $uploadedBy; + + return $this; + } +}