src/Entity/Owner.php line 81

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\Serializer\Annotation\Groups;
  15. use Symfony\Component\Validator\Constraints as Assert;
  16. use Symfony\Component\Serializer\Annotation\MaxDepth;
  17. use Ramsey\Uuid\Uuid;
  18. use Ramsey\Uuid\UuidInterface;
  19. /**
  20.  * @see https://schema.org/Organization
  21.  *
  22.  * @author Jordi Fernandes Alves <jfadev@gmail.com>
  23.  */
  24. #[ORM\Entity]
  25. #[ApiResource(
  26.     iri'Owner',
  27.     itemOperations: [
  28.         'get' => ['normalization_context' => ['groups' => 'owner:item:get''enable_max_depth' => true]],
  29.         'put' => [
  30.             'normalization_context' => ['groups' => 'owner:item:put''enable_max_depth' => true],
  31.             'denormalization_context' => ['groups' => 'owner:item:put''enable_max_depth' => true],
  32.         ],
  33.         'delete' => [],
  34.     ],
  35.     collectionOperations: [
  36.         'get' => [
  37.             'normalization_context' => [
  38.                 'groups' => ['owner:collection:get''createdAt'],
  39.                 'enable_max_depth' => true,
  40.             ],
  41.         ],
  42.         'post' => [
  43.             'normalization_context' => ['groups' => 'owner:collection:post''enable_max_depth' => true],
  44.             'denormalization_context' => ['groups' => 'owner:collection:post''enable_max_depth' => true],
  45.         ],
  46.     ],
  47. )]
  48. #[ApiFilter(
  49.     SearchFilter::class,
  50.     properties: [
  51.         'companyName' => 'partial',
  52.         'addressLine1' => 'partial',
  53.         'addressLine2' => 'partial',
  54.         'addressLine3' => 'partial',
  55.         'charteringEmail' => 'partial',
  56.         'operationsEmail' => 'partial',
  57.         'accountingEmail' => 'partial',
  58.         'createdAt' => 'start',
  59.         'detailedCompanyName' => 'partial',
  60.     ],
  61. )]
  62. #[ApiFilter(
  63.     OrderFilter::class,
  64.     properties: [
  65.         'companyName',
  66.         'addressLine1',
  67.         'addressLine2',
  68.         'addressLine3',
  69.         'charteringEmail',
  70.         'operationsEmail',
  71.         'accountingEmail',
  72.         'createdAt',
  73.         'detailedCompanyName',
  74.     ],
  75. )]
  76. #[ApiFilter(PropertyFilter::class)]
  77. class Owner
  78. {
  79.     use TimestampableEntity;
  80.     #[ORM\Id]
  81.     #[ORM\GeneratedValue(strategy'NONE')]
  82.     #[ORM\Column(type'uuid'uniquetrue)]
  83.     ##[ApiProperty(iri: 'https://schema.org/identifier')]
  84.     ##[Groups(['owner:collection:get', 'owner:item:get'])]
  85.     private ?UuidInterface $id null;
  86.     #[ORM\Column(type'string'nullablefalse)]
  87.     #[ApiProperty(iri'https://schema.org/companyName')]
  88.     #[Assert\NotNull]
  89.     #[Assert\Type('string')]
  90.     #[Groups(['owner:collection:get''owner:collection:post''owner:item:get''owner:item:put''vessel:collection:get''vessel:item:get''vessel:item:put''contract:item:get''contract:item:put''contract:collection:get''contract:collection:post'])]
  91.     private ?string $companyName null;
  92.     #[ORM\Column(type'string'nullablefalse)]
  93.     #[ApiProperty(iri'https://schema.org/detailedCompanyName')]
  94.     #[Assert\NotNull]
  95.     #[Assert\Type('string')]
  96.     #[Groups(['owner:collection:get''owner:collection:post''owner:item:get''owner:item:put''vessel:collection:get''vessel:item:get'])]
  97.     private ?string $detailedCompanyName null;
  98.     #[ORM\Column(type'string'nullabletrue)]
  99.     #[ApiProperty(iri'https://schema.org/addressLine')]
  100.     #[Assert\Type('string')]
  101.     #[Groups(['owner:collection:get''owner:collection:post''owner:item:get''owner:item:put'])]
  102.     private ?string $addressLine1 null;
  103.     #[ORM\Column(type'string'nullabletrue)]
  104.     #[ApiProperty(iri'https://schema.org/addressLine')]
  105.     #[Assert\Type('string')]
  106.     #[Groups(['owner:collection:get''owner:collection:post''owner:item:get''owner:item:put'])]
  107.     private ?string $addressLine2 null;
  108.     #[ORM\Column(type'string'nullabletrue)]
  109.     #[ApiProperty(iri'https://schema.org/addressLine')]
  110.     #[Assert\Type('string')]
  111.     #[Groups(['owner:collection:get''owner:collection:post''owner:item:get''owner:item:put'])]
  112.     private ?string $addressLine3 null;
  113.     #[ORM\Column(type'text'nullabletrue)]
  114.     #[ApiProperty(iri'https://schema.org/email')]
  115.     ##[Assert\Email]
  116.     #[Groups(['owner:collection:get''owner:collection:post''owner:item:get''owner:item:put'])]
  117.     private ?string $charteringEmail null;
  118.     #[ORM\Column(type'text'nullabletrue)]
  119.     #[ApiProperty(iri'https://schema.org/email')]
  120.     ##[Assert\Email]
  121.     #[Groups(['owner:collection:get''owner:collection:post''owner:item:get''owner:item:put'])]
  122.     private ?string $operationsEmail null;
  123.     #[ORM\Column(type'text'nullabletrue)]
  124.     #[ApiProperty(iri'https://schema.org/email')]
  125.     ##[Assert\Email]
  126.     #[Groups(['owner:collection:get''owner:collection:post''owner:item:get''owner:item:put'])]
  127.     private ?string $accountingEmail null;
  128.     #[ORM\ManyToMany(targetEntity'App\Entity\Contact')]
  129.     #[ORM\InverseJoinColumn(uniquetrue)]
  130.     #[ApiProperty(iri'https://schema.org/Contact')]
  131.     #[Groups(['owner:collection:get''owner:collection:post''owner:item:get''owner:item:put'])]
  132.     private Collection $contacts
  133.     #[ORM\OneToOne(targetEntity'App\Entity\Contact')]
  134.     #[ApiProperty(iri'https://schema.org/Contact')]
  135.     #[Groups(['owner:collection:get''owner:collection:post''owner:item:get''owner:item:put'])]
  136.     private ?Contact $primaryContact null;
  137.     #[ORM\OneToMany(targetEntity'App\Entity\Vessel'mappedBy'owner')]
  138.     #[ApiProperty(iri'https://schema.org/Vessel')]
  139.     #[Groups(['owner:collection:get''owner:collection:post''owner:item:get''owner:item:put'])]
  140.     #[MaxDepth(1)]
  141.     private ?Collection $vessels null;
  142.     #[ORM\ManyToMany(targetEntity'App\Entity\Contract')]
  143.     #[ORM\InverseJoinColumn(uniquetrue)]
  144.     #[ApiProperty(iri'https://schema.org/Contract')]
  145.     #[Groups(['owner:collection:get''owner:collection:post''owner:item:get''owner:item:put'])]
  146.     private Collection $transactionHistory;
  147.     #[ORM\OneToMany(targetEntity'App\Entity\Contract'mappedBy'owner')]
  148.     #[ApiProperty(iri'https://schema.org/Contract')]
  149.     #[Groups(['owner:collection:get''owner:collection:post''owner:item:get''owner:item:put'])]
  150.     #[MaxDepth(1)]
  151.     private ?Collection $contracts null;
  152.     public function __construct()
  153.     {
  154.         $this->id Uuid::uuid4();
  155.         $this->contacts = new ArrayCollection();
  156.         $this->vessels = new ArrayCollection();
  157.         $this->transactionHistory = new ArrayCollection();
  158.         $this->contracts = new ArrayCollection();
  159.     }
  160.     public function getId(): ?UuidInterface
  161.     {
  162.         return $this->id;
  163.     }
  164.     public function setCompanyName(?string $companyName): void
  165.     {
  166.         $this->companyName $companyName;
  167.     }
  168.     public function getCompanyName(): ?string
  169.     {
  170.         return $this->companyName;
  171.     }
  172.     public function setDetailedCompanyName(?string $detailedCompanyName): void
  173.     {
  174.         $this->detailedCompanyName $detailedCompanyName;
  175.     }
  176.     public function getDetailedCompanyName(): ?string
  177.     {
  178.         return $this->detailedCompanyName;
  179.     }
  180.     public function setAddressLine1(?string $addressLine1): void
  181.     {
  182.         $this->addressLine1 $addressLine1;
  183.     }
  184.     public function getAddressLine1(): ?string
  185.     {
  186.         return $this->addressLine1;
  187.     }
  188.     public function setAddressLine2(?string $addressLine2): void
  189.     {
  190.         $this->addressLine2 $addressLine2;
  191.     }
  192.     public function getAddressLine2(): ?string
  193.     {
  194.         return $this->addressLine2;
  195.     }
  196.     public function setAddressLine3(?string $addressLine3): void
  197.     {
  198.         $this->addressLine3 $addressLine3;
  199.     }
  200.     public function getAddressLine3(): ?string
  201.     {
  202.         return $this->addressLine3;
  203.     }
  204.     public function setCharteringEmail(?string $charteringEmail): void
  205.     {
  206.         $this->charteringEmail $charteringEmail;
  207.     }
  208.     public function getCharteringEmail(): ?string
  209.     {
  210.         return $this->charteringEmail;
  211.     }
  212.     public function setOperationsEmail(?string $operationsEmail): void
  213.     {
  214.         $this->operationsEmail $operationsEmail;
  215.     }
  216.     public function getOperationsEmail(): ?string
  217.     {
  218.         return $this->operationsEmail;
  219.     }
  220.     public function setAccountingEmail(?string $accountingEmail): void
  221.     {
  222.         $this->accountingEmail $accountingEmail;
  223.     }
  224.     public function getAccountingEmail(): ?string
  225.     {
  226.         return $this->accountingEmail;
  227.     }
  228.     public function addContact(Contact $contact): void
  229.     {
  230.         $this->contacts[] = $contact;
  231.     }
  232.     public function removeContact(Contact $contact): void
  233.     {
  234.         $this->contacts->removeElement($contact);
  235.     }
  236.     public function getContacts(): Collection
  237.     {
  238.         return $this->contacts;
  239.     }
  240.     public function setPrimaryContact(?Contact $primaryContact): void
  241.     {
  242.         $this->primaryContact $primaryContact;
  243.     }
  244.     public function getPrimaryContact(): ?Contact
  245.     {
  246.         return $this->primaryContact;
  247.     }
  248.     public function addVessel(Vessel $vessel): void
  249.     {
  250.         $this->vessels[] = $vessel;
  251.     }
  252.     public function removeVessel(Vessel $vessel): void
  253.     {
  254.         $this->vessels->removeElement($vessel);
  255.     }
  256.     public function getVessels(): Collection
  257.     {
  258.         return $this->vessels;
  259.     }
  260.     public function addTransactionHistory(Contract $transactionHistory): void
  261.     {
  262.         $this->transactionHistory[] = $transactionHistory;
  263.     }
  264.     public function removeTransactionHistory(Contract $transactionHistory): void
  265.     {
  266.         $this->transactionHistory->removeElement($transactionHistory);
  267.     }
  268.     public function getTransactionHistory(): Collection
  269.     {
  270.         return $this->transactionHistory;
  271.     }
  272.     public function getContracts(): Collection
  273.     {
  274.         return $this->contracts;
  275.     }
  276.     public function addContract(Contract $contract): self
  277.     {
  278.         if (!$this->contracts->contains($contract)) {
  279.             $this->contracts[] = $contract;
  280.             $contract->setOwner($this);
  281.         }
  282.         return $this;
  283.     }
  284.     public function removeContract(Contract $contract): self
  285.     {
  286.         if ($this->contracts->removeElement($contract)) {
  287.             if ($contract->getOwner() === $this) {
  288.                 $contract->setOwner(null);
  289.             }
  290.         }
  291.         
  292.         return $this;
  293.     }
  294. }