src/Entity/Owner.php line 61

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