<?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\Validator\Constraints as Assert;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Serializer\Annotation\MaxDepth;
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidInterface;
#[ORM\Entity]
#[ApiResource(
iri: 'OperationReport',
collectionOperations: [],
itemOperations: [
'get' => [
'security' => "is_granted('ROLE_USER')",
'method' => 'GET',
'path' => '/contracts/operation_reports/{id}',
'openapi_context' => [
'tags' => ['Contract / OperationReport']
]
]
],
attributes: ['pagination_enabled' => false]
)]
class OperationReport
{
use TimestampableEntity;
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'NONE')]
#[ORM\Column(type: 'uuid', unique: true)]
private ?UuidInterface $id = null;
#[ORM\ManyToOne(
targetEntity: Port::class,
inversedBy: 'operationReports')]
#[ORM\JoinColumn(nullable: true)]
#[ApiProperty()]
#[Groups([
'contract:item:get',
'contract:item:put',
'contract:collection:post',
])]
#[MaxDepth(1)]
private ?Port $port = null;
#[ORM\OneToMany(
targetEntity: OperationIncident::class,
mappedBy: 'operationReport',
cascade: ['persist', 'remove'],
orphanRemoval: true
)]
// #[ORM\OrderBy(['taskIndex' => 'ASC'])]
#[Groups([
'contract:item:get',
'contract:item:put',
// 'contract:collection:get',
'contract:collection:post'
])]
#[MaxDepth(1)]
private ?Collection $operationIncidents = null;
#[ORM\Column(type: 'text', nullable: true)]
#[ApiProperty()]
#[Assert\Type('string')]
#[Groups([
'contract:item:get',
'contract:item:put',
// 'contract:collection:get',
'contract:collection:post'
])]
private ?string $description = null;
#[ORM\ManyToOne(
targetEntity: Contract::class,
inversedBy: 'operationReports'
)]
#[ORM\JoinColumn(nullable: true)]
private ?Contract $contract = null;
public function __construct()
{
$this->id = Uuid::uuid4();
$this->operationIncidents = new ArrayCollection();
}
public function getId(): ?UuidInterface
{
return $this->id;
}
public function setPort(?Port $port): void
{
$this->port = $port;
}
public function getPort(): ?Port
{
return $this->port;
}
public function addOperationIncident(OperationIncident $operationIncident): void
{
$operationIncident->setOperationReport($this);
$this->operationIncidents[] = $operationIncident;
}
public function removeOperationIncident(OperationIncident $operationIncident): void
{
$this->operationIncidents->removeElement($operationIncident);
}
public function getOperationIncidents(): Collection
{
return $this->operationIncidents;
}
public function setDescription(?string $description): void
{
$this->description = $description;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setContract(?Contract $contract): void
{
$this->contract = $contract;
}
public function getContract(): ?Contract
{
return $this->contract;
}
}