<?php
declare(strict_types=1);
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiProperty;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Trait\TimestampableEntity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Serializer\Annotation\MaxDepth;
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidInterface;
/**
* @see https://schema.org/Thing
*
* @author Jordi Fernandes Alves <jfadev@gmail.com>
*/
#[ORM\Entity]
#[ApiResource(
iri: 'Task',
itemOperations: [
'get' => ['normalization_context' => ['groups' => 'task:item:get', 'enable_max_depth' => true]],
'put' => [
'normalization_context' => ['groups' => 'task:item:put', 'enable_max_depth' => true],
'denormalization_context' => ['groups' => 'task:item:put', 'enable_max_depth' => true],
],
'delete' => [],
],
collectionOperations: [
'get' => [
'normalization_context' => [
'groups' => ['task:collection:get', 'createdAt'],
'enable_max_depth' => true,
],
],
'post' => [
'normalization_context' => ['groups' => 'task:collection:post', 'enable_max_depth' => true],
'denormalization_context' => ['groups' => 'task:collection:post', 'enable_max_depth' => true],
],
],
)]
class Task
{
use TimestampableEntity;
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'NONE')]
#[ORM\Column(type: 'uuid', unique: true)]
private ?UuidInterface $id = null;
#[ORM\Column(type: 'string', nullable: false)]
#[Assert\NotNull]
#[Assert\Type('string')]
#[Groups(['task:collection:get', 'task:collection:post', 'task:item:get', 'task:item:put', 'checklist:collection:post', 'checklist:item:get', 'checklist:item:put', 'contract:item:get', 'contract:item:put', 'contract:collection:get', 'contract:collection:post'])]
private ?string $taskName = null;
#[ORM\Column(type: 'text', nullable: true)]
#[ApiProperty(iri: 'https://schema.org/description')]
#[Groups(['task:collection:get', 'task:collection:post', 'task:item:get', 'task:item:put'])]
private ?string $description = null;
#[ORM\Column(type: 'integer')]
#[Assert\NotNull]
#[Groups(['task:collection:get', 'task:collection:post', 'task:item:get', 'task:item:put', 'checklist:collection:get', 'checklist:collection:post', 'checklist:item:get', 'checklist:item:put'])]
private ?int $taskIndex = 0;
// #[ORM\Column(type: 'boolean', nullable: false)]
// #[Assert\NotNull]
// #[Groups(['task:collection:get', 'task:collection:post', 'task:item:get', 'task:item:put', 'checklist:collection:post', 'checklist:item:get', 'checklist:item:put', 'contract:item:get', 'contract:item:put', 'contract:collection:get', 'contract:collection:post'])]
// private ?bool $isCompleted = false;
// #[ORM\Column(type: 'datetime', nullable: true)]
// #[Groups(['task:collection:get', 'task:collection:post', 'task:item:get', 'task:item:put'])]
// private ?\DateTime $dueDate = null;
// #[ORM\ManyToOne(targetEntity: User::class)]
// #[Groups(['task:collection:get', 'task:collection:post', 'task:item:get', 'task:item:put'])]
// private ?User $assignedTo = null;
#[ORM\ManyToOne(targetEntity: 'App\Entity\Checklist', inversedBy: 'tasks')]
#[ORM\JoinColumn(nullable: true)]
#[ApiProperty(iri: 'https://schema.org/Checklist')]
#[Groups(['task:collection:get', 'task:collection:post', 'task:item:get', 'task:item:put'])]
#[MaxDepth(1)]
private ?Checklist $checklist = null;
#[ORM\ManyToMany(targetEntity: 'App\Entity\Contract', mappedBy: 'checkedTasks')]
#[Groups(['task:collection:get', 'task:collection:post', 'task:item:get', 'task:item:put'])]
#[MaxDepth(1)]
private ?Collection $contracts = null;
// #[ORM\ManyToMany(targetEntity: 'App\Entity\Lifting', mappedBy: 'checkedTasks')]
// #[Groups(['task:collection:get', 'task:collection:post', 'task:item:get', 'task:item:put'])]
// #[MaxDepth(1)]
// private ?Collection $liftings = null;
public function __construct()
{
$this->id = Uuid::uuid4();
$this->contracts = new ArrayCollection();
// $this->liftings = new ArrayCollection();
}
public function getId(): ?UuidInterface
{
return $this->id;
}
public function setTaskName(?string $taskName): void
{
$this->taskName = $taskName;
}
public function getTaskName(): ?string
{
return $this->taskName;
}
public function setDescription(?string $description): void
{
$this->description = $description;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setTaskIndex(?int $taskIndex): void
{
$this->taskIndex = $taskIndex;
}
public function getTaskIndex(): ?int
{
return $this->taskIndex;
}
// public function setIsCompleted(?bool $isCompleted): void
// {
// $this->isCompleted = $isCompleted;
// }
// public function getIsCompleted(): ?bool
// {
// return $this->isCompleted;
// }
// public function setDueDate(?\DateTime $dueDate): void
// {
// $this->dueDate = $dueDate;
// }
// public function getDueDate(): ?\DateTime
// {
// return $this->dueDate;
// }
// public function setAssignedTo(?User $assignedTo): void
// {
// $this->assignedTo = $assignedTo;
// }
// public function getAssignedTo(): ?User
// {
// return $this->assignedTo;
// }
public function setChecklist(?Checklist $checklist): void
{
$this->checklist = $checklist;
}
public function getChecklist(): ?Checklist
{
return $this->checklist;
}
public function setContracts(?Collection $contracts): void
{
$this->contracts = $contracts;
}
public function getContracts(): ?Collection
{
return $this->contracts;
}
// public function setLiftings(?Collection $liftings): void
// {
// $this->liftings = $liftings;
// }
// public function getLiftings(): ?Collection
// {
// return $this->liftings;
// }
}