<?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 Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidInterface;
#[ORM\Entity]
#[ApiResource(
iri: 'Task',
collectionOperations: [],
itemOperations: [
'get' => [
'security' => "
is_granted('ROLE_ADMIN') or
is_granted('ROLE_OPERATOR') or
is_granted('ROLE_OPERATIONS_COORDINATOR')
",
"method" => "GET",
"path" => "/checklists/tasks/{id}",
"openapi_context" => [
"tags" => ["Checklist / Task"]
]
]
],
attributes: ["pagination_enabled" => false]
)]
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')]
#[ApiProperty()]
#[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'
])]
private ?string $taskName = null;
#[ORM\Column(type: 'integer')]
#[Assert\NotNull]
#[ApiProperty()]
#[Groups([
'checklist:collection:get',
'checklist:collection:post',
'checklist:item:get',
'checklist:item:put'
])]
private ?int $taskIndex = 0;
#[ORM\ManyToOne(targetEntity: Checklist::class, inversedBy: 'tasks')]
#[ORM\JoinColumn(nullable: true)]
private ?Checklist $checklist = null;
#[ORM\ManyToMany(targetEntity: Contract::class, mappedBy: 'checkedTasks')]
private ?Collection $contracts = null;
public function __construct()
{
$this->id = Uuid::uuid4();
$this->contracts = 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 setTaskIndex(?int $taskIndex): void
{
$this->taskIndex = $taskIndex;
}
public function getTaskIndex(): ?int
{
return $this->taskIndex;
}
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;
}
}