src/Entity/Task.php line 38

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 Ramsey\Uuid\Uuid;
  13. use Ramsey\Uuid\UuidInterface;
  14. #[ORM\Entity]
  15. #[ApiResource(
  16.     iri'Task',
  17.     collectionOperations: [],
  18.     itemOperations: [
  19.         'get' => [
  20.             'security' => "
  21.                 is_granted('ROLE_ADMIN') or 
  22.                 is_granted('ROLE_OPERATOR') or
  23.                 is_granted('ROLE_OPERATIONS_COORDINATOR')
  24.             ",
  25.             "method" => "GET",
  26.             "path" => "/checklists/tasks/{id}",
  27.             "openapi_context" => [
  28.                 "tags" => ["Checklist / Task"]
  29.             ]
  30.         ]
  31.     ],
  32.     attributes: ["pagination_enabled" => false]
  33. )]
  34. class Task
  35. {
  36.     use TimestampableEntity;
  37.     
  38.     #[ORM\Id]
  39.     #[ORM\GeneratedValue(strategy'NONE')]
  40.     #[ORM\Column(type'uuid'uniquetrue)]
  41.     private ?UuidInterface $id null;
  42.     #[ORM\Column(type'string'nullablefalse)]
  43.     #[Assert\NotNull]
  44.     #[Assert\Type('string')]
  45.     #[ApiProperty()]
  46.     #[Groups([
  47.         'checklist:collection:get',
  48.         'checklist:collection:post'
  49.         'checklist:item:get'
  50.         'checklist:item:put'
  51.         'contract:item:get'
  52.         'contract:item:put'
  53.         'contract:collection:get'
  54.         'contract:collection:post'
  55.     ])]
  56.     private ?string $taskName null;
  57.     #[ORM\Column(type'integer')]
  58.     #[Assert\NotNull]
  59.     #[ApiProperty()]
  60.     #[Groups([
  61.         'checklist:collection:get'
  62.         'checklist:collection:post'
  63.         'checklist:item:get'
  64.         'checklist:item:put'
  65.     ])]
  66.     private ?int $taskIndex 0;
  67.     #[ORM\ManyToOne(targetEntityChecklist::class, inversedBy'tasks')]
  68.     #[ORM\JoinColumn(nullabletrue)]
  69.     private ?Checklist $checklist null;
  70.     
  71.     #[ORM\ManyToMany(targetEntityContract::class, mappedBy'checkedTasks')]
  72.     private ?Collection $contracts null;
  73.     public function __construct()
  74.     {
  75.         $this->id Uuid::uuid4();
  76.         $this->contracts = new ArrayCollection();
  77.     }
  78.     public function getId(): ?UuidInterface
  79.     {
  80.         return $this->id;
  81.     }
  82.     public function setTaskName(?string $taskName): void
  83.     {
  84.         $this->taskName $taskName;
  85.     }
  86.     public function getTaskName(): ?string
  87.     {
  88.         return $this->taskName;
  89.     }
  90.     public function setTaskIndex(?int $taskIndex): void
  91.     {
  92.         $this->taskIndex $taskIndex;
  93.     }
  94.     public function getTaskIndex(): ?int
  95.     {
  96.         return $this->taskIndex;
  97.     }
  98.     public function setChecklist(?Checklist $checklist): void
  99.     {
  100.         $this->checklist $checklist;
  101.     }
  102.     public function getChecklist(): ?Checklist
  103.     {
  104.         return $this->checklist;
  105.     }
  106.     public function setContracts(?Collection $contracts): void
  107.     {
  108.         $this->contracts $contracts;
  109.     }
  110.     public function getContracts(): ?Collection
  111.     {
  112.         return $this->contracts;
  113.     }
  114. }