src/Entity/Checklist.php line 61

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Entity;
  4. use ApiPlatform\Core\Annotation\ApiFilter;
  5. use ApiPlatform\Core\Annotation\ApiProperty;
  6. use ApiPlatform\Core\Annotation\ApiResource;
  7. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
  8. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  9. use ApiPlatform\Core\Serializer\Filter\PropertyFilter;
  10. use App\Trait\TimestampableEntity;
  11. use Doctrine\Common\Collections\ArrayCollection;
  12. use Doctrine\Common\Collections\Collection;
  13. use Doctrine\ORM\Mapping as ORM;
  14. use Symfony\Component\Validator\Constraints as Assert;
  15. use Symfony\Component\Serializer\Annotation\Groups;
  16. use Symfony\Component\Serializer\Annotation\MaxDepth;
  17. use Ramsey\Uuid\Uuid;
  18. use Ramsey\Uuid\UuidInterface;
  19. /**
  20.  * @see https://schema.org/Thing
  21.  *
  22.  * @author Jordi Fernandes Alves <jfadev@gmail.com>
  23.  */
  24. #[ORM\Entity]
  25. #[ApiResource(
  26.     iri'Checklist',
  27.     itemOperations: [
  28.         'get' => ['normalization_context' => ['groups' => 'checklist:item:get''enable_max_depth' => true]],
  29.         'put' => [
  30.             'normalization_context' => ['groups' => 'checklist:item:put''enable_max_depth' => true],
  31.             'denormalization_context' => ['groups' => 'checklist:item:put''enable_max_depth' => true],
  32.         ],
  33.         'delete' => [],
  34.     ],
  35.     collectionOperations: [
  36.         'get' => [
  37.             'normalization_context' => [
  38.                 'groups' => ['checklist:collection:get''createdAt'],
  39.                 'enable_max_depth' => true,
  40.             ],
  41.         ],
  42.         'post' => [
  43.             'normalization_context' => ['groups' => 'checklist:collection:post''enable_max_depth' => true],
  44.             'denormalization_context' => ['groups' => 'checklist:collection:post''enable_max_depth' => true],
  45.         ],
  46.     ],
  47. )]
  48. #[ApiFilter(
  49.     SearchFilter::class,
  50.     properties: ['checklistName' => 'partial''createdAt' => 'start'],
  51. )]
  52. #[ApiFilter(
  53.     OrderFilter::class,
  54.     properties: ['checklistName''createdAt'],
  55. )]
  56. #[ApiFilter(PropertyFilter::class)]
  57. class Checklist
  58. {
  59.     use TimestampableEntity;
  60.     
  61.     #[ORM\Id]
  62.     #[ORM\GeneratedValue(strategy'NONE')]
  63.     #[ORM\Column(type'uuid'uniquetrue)]
  64.     private ?UuidInterface $id null;
  65.     #[ORM\Column(type'string'nullablefalse)]
  66.     #[ApiProperty(iri'https://schema.org/name')]
  67.     #[Assert\NotBlank]
  68.     #[Assert\Type('string')]
  69.     #[Groups(['checklist:collection:get''checklist:collection:post''checklist:item:get''checklist:item:put''contract:item:get''contract:item:put''contract:collection:get''contract:collection:post'])]
  70.     private ?string $checklistName null;
  71.     #[ORM\OneToMany(targetEntity'App\Entity\Task'mappedBy'checklist'cascade: ['persist''remove'], orphanRemovaltrue)]
  72.     #[ORM\OrderBy(['taskIndex' => 'ASC'])]
  73.     #[Groups(['checklist:collection:get''checklist:collection:post''checklist:item:get''checklist:item:put''contract:item:get''contract:item:put''contract:collection:get''contract:collection:post'])]
  74.     #[MaxDepth(1)]
  75.     private ?Collection $tasks null;
  76.     #[ORM\Column(type'text'nullabletrue)]
  77.     #[ApiProperty(iri'https://schema.org/observation')]
  78.     #[Assert\Type('string')]
  79.     #[Groups(['checklist:collection:get''checklist:collection:post''checklist:item:get''checklist:item:put''contract:item:get''contract:item:put''contract:collection:get''contract:collection:post'])]
  80.     private ?string $notes null;
  81.     #[ORM\OneToMany(targetEntity'App\Entity\Contract'mappedBy'checklist')]
  82.     #[ApiProperty(iri'https://schema.org/Contract')]
  83.     #[Groups(['checklist:collection:get''checklist:collection:post''checklist:item:get''checklist:item:put'])]
  84.     #[MaxDepth(1)]
  85.     private ?Collection $contracts null;
  86.     // #[ORM\OneToMany(targetEntity: 'App\Entity\Lifting', mappedBy: 'checklist')]
  87.     // #[ApiProperty(iri: 'https://schema.org/Lifting')]
  88.     // #[Groups(['checklist:collection:get', 'checklist:collection:post', 'checklist:item:get', 'checklist:item:put'])]
  89.     // #[MaxDepth(1)]
  90.     // private ?Collection $liftings = null;
  91.     public function __construct()
  92.     {
  93.         $this->id Uuid::uuid4();
  94.         $this->tasks = new ArrayCollection();
  95.         $this->contracts = new ArrayCollection();
  96.         // $this->liftings = new ArrayCollection();
  97.     }
  98.     public function getId(): ?UuidInterface
  99.     {
  100.         return $this->id;
  101.     }
  102.     public function setChecklistName(?string $checklistName): void
  103.     {
  104.         $this->checklistName $checklistName;
  105.     }
  106.     public function getChecklistName(): ?string
  107.     {
  108.         return $this->checklistName;
  109.     }
  110.     public function setNotes(?string $notes): void
  111.     {
  112.         $this->notes $notes;
  113.     }
  114.     public function getNotes(): ?string
  115.     {
  116.         return $this->notes;
  117.     }
  118.     public function addTask(Task $task): void
  119.     {
  120.         $task->setChecklist($this);
  121.         $this->tasks[] = $task;
  122.     }
  123.     public function removeTask(Task $task): void
  124.     {
  125.         $this->tasks->removeElement($task);
  126.     }
  127.     public function getTasks(): Collection
  128.     {
  129.         return $this->tasks;
  130.     }
  131.     public function getContracts(): Collection
  132.     {
  133.         return $this->contracts;
  134.     }
  135.     public function addContract(Contract $contract): self
  136.     {
  137.         if (!$this->contracts->contains($contract)) {
  138.             $this->contracts[] = $contract;
  139.             $contract->setChecklist($this);
  140.         }
  141.         return $this;
  142.     }
  143.     public function removeContract(Contract $contract): self
  144.     {
  145.         if ($this->contracts->removeElement($contract)) {
  146.             if ($contract->getChecklist() === $this) {
  147.                 $contract->setChecklist(null);
  148.             }
  149.         }
  150.         
  151.         return $this;
  152.     }
  153.     // public function getLiftings(): Collection
  154.     // {
  155.     //     return $this->liftings;
  156.     // }
  157.     // public function addLifting(Lifting $lifting): self
  158.     // {
  159.     //     if (!$this->liftings->contains($lifting)) {
  160.     //         $this->liftings[] = $lifting;
  161.     //         $lifting->setChecklist($this);
  162.     //     }
  163.     //     return $this;
  164.     // }
  165.     // public function removeLifting(Lifting $lifting): self
  166.     // {
  167.     //     if ($this->liftings->removeElement($lifting)) {
  168.     //         if ($lifting->getChecklist() === $this) {
  169.     //             $lifting->setChecklist(null);
  170.     //         }
  171.     //     }
  172.         
  173.     //     return $this;
  174.     // }
  175. }