src/Entity/Task.php line 48

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Entity;
  4. use ApiPlatform\Core\Annotation\ApiProperty;
  5. use ApiPlatform\Core\Annotation\ApiResource;
  6. use App\Trait\TimestampableEntity;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Doctrine\Common\Collections\Collection;
  9. use Doctrine\ORM\Mapping as ORM;
  10. use Symfony\Component\Serializer\Annotation\Groups;
  11. use Symfony\Component\Validator\Constraints as Assert;
  12. use Symfony\Component\Serializer\Annotation\MaxDepth;
  13. use Ramsey\Uuid\Uuid;
  14. use Ramsey\Uuid\UuidInterface;
  15. /**
  16.  * @see https://schema.org/Thing
  17.  *
  18.  * @author Jordi Fernandes Alves <jfadev@gmail.com>
  19.  */
  20. #[ORM\Entity]
  21. #[ApiResource(
  22.     iri'Task',
  23.     itemOperations: [
  24.         'get' => ['normalization_context' => ['groups' => 'task:item:get''enable_max_depth' => true]],
  25.         'put' => [
  26.             'normalization_context' => ['groups' => 'task:item:put''enable_max_depth' => true],
  27.             'denormalization_context' => ['groups' => 'task:item:put''enable_max_depth' => true],
  28.         ],
  29.         'delete' => [],
  30.     ],
  31.     collectionOperations: [
  32.         'get' => [
  33.             'normalization_context' => [
  34.                 'groups' => ['task:collection:get''createdAt'],
  35.                 'enable_max_depth' => true,
  36.             ],
  37.         ],
  38.         'post' => [
  39.             'normalization_context' => ['groups' => 'task:collection:post''enable_max_depth' => true],
  40.             'denormalization_context' => ['groups' => 'task:collection:post''enable_max_depth' => true],
  41.         ],
  42.     ],
  43. )]
  44. class Task
  45. {
  46.     use TimestampableEntity;
  47.     
  48.     #[ORM\Id]
  49.     #[ORM\GeneratedValue(strategy'NONE')]
  50.     #[ORM\Column(type'uuid'uniquetrue)]
  51.     private ?UuidInterface $id null;
  52.     #[ORM\Column(type'string'nullablefalse)]
  53.     #[Assert\NotNull]
  54.     #[Assert\Type('string')]
  55.     #[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'])]
  56.     private ?string $taskName null;
  57.     #[ORM\Column(type'text'nullabletrue)]
  58.     #[ApiProperty(iri'https://schema.org/description')]
  59.     #[Groups(['task:collection:get''task:collection:post''task:item:get''task:item:put'])]
  60.     private ?string $description null;
  61.     #[ORM\Column(type'integer')]
  62.     #[Assert\NotNull]
  63.     #[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'])]
  64.     private ?int $taskIndex 0;
  65.     // #[ORM\Column(type: 'boolean', nullable: false)]
  66.     // #[Assert\NotNull]
  67.     // #[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'])]
  68.     // private ?bool $isCompleted = false;
  69.     // #[ORM\Column(type: 'datetime', nullable: true)]
  70.     // #[Groups(['task:collection:get', 'task:collection:post', 'task:item:get', 'task:item:put'])]
  71.     // private ?\DateTime $dueDate = null;
  72.     // #[ORM\ManyToOne(targetEntity: User::class)]
  73.     // #[Groups(['task:collection:get', 'task:collection:post', 'task:item:get', 'task:item:put'])]
  74.     // private ?User $assignedTo = null;
  75.     #[ORM\ManyToOne(targetEntity'App\Entity\Checklist'inversedBy'tasks')]
  76.     #[ORM\JoinColumn(nullabletrue)]
  77.     #[ApiProperty(iri'https://schema.org/Checklist')]
  78.     #[Groups(['task:collection:get''task:collection:post''task:item:get''task:item:put'])]
  79.     #[MaxDepth(1)]
  80.     private ?Checklist $checklist null;
  81.     
  82.     #[ORM\ManyToMany(targetEntity'App\Entity\Contract'mappedBy'checkedTasks')]
  83.     #[Groups(['task:collection:get''task:collection:post''task:item:get''task:item:put'])]
  84.     #[MaxDepth(1)]
  85.     private ?Collection $contracts null;
  86.     // #[ORM\ManyToMany(targetEntity: 'App\Entity\Lifting', mappedBy: 'checkedTasks')]
  87.     // #[Groups(['task:collection:get', 'task:collection:post', 'task:item:get', 'task:item:put'])]
  88.     // #[MaxDepth(1)]
  89.     // private ?Collection $liftings = null;
  90.     public function __construct()
  91.     {
  92.         $this->id Uuid::uuid4();
  93.         $this->contracts = new ArrayCollection();
  94.         // $this->liftings = new ArrayCollection();
  95.     }
  96.     public function getId(): ?UuidInterface
  97.     {
  98.         return $this->id;
  99.     }
  100.     public function setTaskName(?string $taskName): void
  101.     {
  102.         $this->taskName $taskName;
  103.     }
  104.     public function getTaskName(): ?string
  105.     {
  106.         return $this->taskName;
  107.     }
  108.     public function setDescription(?string $description): void
  109.     {
  110.         $this->description $description;
  111.     }
  112.     public function getDescription(): ?string
  113.     {
  114.         return $this->description;
  115.     }
  116.     public function setTaskIndex(?int $taskIndex): void
  117.     {
  118.         $this->taskIndex $taskIndex;
  119.     }
  120.     public function getTaskIndex(): ?int
  121.     {
  122.         return $this->taskIndex;
  123.     }
  124.     // public function setIsCompleted(?bool $isCompleted): void
  125.     // {
  126.     //     $this->isCompleted = $isCompleted;
  127.     // }
  128.     // public function getIsCompleted(): ?bool
  129.     // {
  130.     //     return $this->isCompleted;
  131.     // }
  132.     // public function setDueDate(?\DateTime $dueDate): void
  133.     // {
  134.     //     $this->dueDate = $dueDate;
  135.     // }
  136.     // public function getDueDate(): ?\DateTime
  137.     // {
  138.     //     return $this->dueDate;
  139.     // }
  140.     // public function setAssignedTo(?User $assignedTo): void
  141.     // {
  142.     //     $this->assignedTo = $assignedTo;
  143.     // }
  144.     // public function getAssignedTo(): ?User
  145.     // {
  146.     //     return $this->assignedTo;
  147.     // }
  148.     public function setChecklist(?Checklist $checklist): void
  149.     {
  150.         $this->checklist $checklist;
  151.     }
  152.     public function getChecklist(): ?Checklist
  153.     {
  154.         return $this->checklist;
  155.     }
  156.     public function setContracts(?Collection $contracts): void
  157.     {
  158.         $this->contracts $contracts;
  159.     }
  160.     public function getContracts(): ?Collection
  161.     {
  162.         return $this->contracts;
  163.     }
  164.     // public function setLiftings(?Collection $liftings): void
  165.     // {
  166.     //     $this->liftings = $liftings;
  167.     // }
  168.     // public function getLiftings(): ?Collection
  169.     // {
  170.     //     return $this->liftings;
  171.     // }
  172. }