src/Entity/OperationReport.php line 35

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\Validator\Constraints as Assert;
  11. use Symfony\Component\Serializer\Annotation\Groups;
  12. use Symfony\Component\Serializer\Annotation\MaxDepth;
  13. use Ramsey\Uuid\Uuid;
  14. use Ramsey\Uuid\UuidInterface;
  15. #[ORM\Entity]
  16. #[ApiResource(
  17.     iri'OperationReport',
  18.     collectionOperations: [],
  19.     itemOperations: [
  20.         'get' => [
  21.             'security' => "is_granted('ROLE_USER')",
  22.             'method' => 'GET',
  23.             'path' => '/contracts/operation_reports/{id}',
  24.             'openapi_context' => [
  25.                 'tags' => ['Contract / OperationReport']
  26.             ]
  27.         ]
  28.     ],
  29.     attributes: ['pagination_enabled' => false]
  30. )]
  31. class OperationReport
  32. {
  33.     use TimestampableEntity;
  34.     
  35.     #[ORM\Id]
  36.     #[ORM\GeneratedValue(strategy'NONE')]
  37.     #[ORM\Column(type'uuid'uniquetrue)]
  38.     private ?UuidInterface $id null;
  39.     #[ORM\ManyToOne(
  40.         targetEntityPort::class, 
  41.         inversedBy'operationReports')]
  42.     #[ORM\JoinColumn(nullabletrue)]
  43.     #[ApiProperty()]
  44.     #[Groups([
  45.         'contract:item:get'
  46.         'contract:item:put',
  47.         'contract:collection:post'
  48.     ])]
  49.     #[MaxDepth(1)]
  50.     private ?Port $port null;
  51.     #[ORM\OneToMany(
  52.         targetEntityOperationIncident::class, 
  53.         mappedBy'operationReport'
  54.         cascade: ['persist''remove'], 
  55.         orphanRemovaltrue
  56.     )]
  57.     // #[ORM\OrderBy(['taskIndex' => 'ASC'])]
  58.     #[Groups([
  59.         'contract:item:get'
  60.         'contract:item:put'
  61.         // 'contract:collection:get', 
  62.         'contract:collection:post'
  63.     ])]
  64.     #[MaxDepth(1)]
  65.     private ?Collection $operationIncidents null;
  66.     #[ORM\Column(type'text'nullabletrue)]
  67.     #[ApiProperty()]
  68.     #[Assert\Type('string')]
  69.     #[Groups([
  70.         'contract:item:get'
  71.         'contract:item:put'
  72.         // 'contract:collection:get', 
  73.         'contract:collection:post'
  74.     ])]
  75.     private ?string $description null;
  76.     #[ORM\ManyToOne(
  77.         targetEntityContract::class, 
  78.         inversedBy'operationReports'
  79.     )]
  80.     #[ORM\JoinColumn(nullabletrue)]
  81.     private ?Contract $contract null;
  82.     public function __construct()
  83.     {
  84.         $this->id Uuid::uuid4();
  85.         $this->operationIncidents = new ArrayCollection();
  86.     }
  87.     public function getId(): ?UuidInterface
  88.     {
  89.         return $this->id;
  90.     }
  91.     public function setPort(?Port $port): void
  92.     {
  93.         $this->port $port;
  94.     }
  95.     public function getPort(): ?Port
  96.     {
  97.         return $this->port;
  98.     }
  99.     public function addOperationIncident(OperationIncident $operationIncident): void
  100.     {
  101.         $operationIncident->setOperationReport($this);
  102.         $this->operationIncidents[] = $operationIncident;
  103.     }
  104.     public function removeOperationIncident(OperationIncident $operationIncident): void
  105.     {
  106.         $this->operationIncidents->removeElement($operationIncident);
  107.     }
  108.     public function getOperationIncidents(): Collection
  109.     {
  110.         return $this->operationIncidents;
  111.     }
  112.     public function setDescription(?string $description): void
  113.     {
  114.         $this->description $description;
  115.     }
  116.     public function getDescription(): ?string
  117.     {
  118.         return $this->description;
  119.     }
  120.     public function setContract(?Contract $contract): void
  121.     {
  122.         $this->contract $contract;
  123.     }
  124.     public function getContract(): ?Contract
  125.     {
  126.         return $this->contract;
  127.     }
  128. }