src/Entity/Owner.php line 133

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 Ramsey\Uuid\Uuid;
  17. use Ramsey\Uuid\UuidInterface;
  18. #[ORM\Entity]
  19. #[ApiResource(
  20.     iri'Owner',
  21.     itemOperations: [
  22.         'get' => [
  23.             'security' => "
  24.                 is_granted('ROLE_ADMIN') or 
  25.                 is_granted('ROLE_OPERATOR') or
  26.                 is_granted('ROLE_OPERATIONS_COORDINATOR') or 
  27.                 is_granted('ROLE_RESEARCH_ANALYST') or
  28.                 is_granted('ROLE_BROKER') or 
  29.                 is_granted('ROLE_INTERN')
  30.             ",
  31.             'normalization_context' => [
  32.                 'groups' => 'owner:item:get'
  33.                 'enable_max_depth' => true
  34.             ]
  35.         ],
  36.         'put' => [
  37.             'security' => "
  38.                 is_granted('ROLE_ADMIN') or 
  39.                 is_granted('ROLE_OPERATOR') or
  40.                 is_granted('ROLE_OPERATIONS_COORDINATOR') or 
  41.                 is_granted('ROLE_RESEARCH_ANALYST') or 
  42.                 is_granted('ROLE_BROKER')
  43.             ",
  44.             'normalization_context' => [
  45.                 'groups' => 'owner:item:put'
  46.                 'enable_max_depth' => true
  47.             ],
  48.             'denormalization_context' => [
  49.                 'groups' => 'owner:item:put'
  50.                 'enable_max_depth' => true
  51.             ],
  52.         ],
  53.         'delete' => [
  54.             'security' => "
  55.                 is_granted('ROLE_ADMIN') or 
  56.                 is_granted('ROLE_OPERATOR') or
  57.                 is_granted('ROLE_OPERATIONS_COORDINATOR') or 
  58.                 is_granted('ROLE_RESEARCH_ANALYST') or 
  59.                 is_granted('ROLE_BROKER')
  60.             ",
  61.         ],
  62.     ],
  63.     collectionOperations: [
  64.         'get' => [
  65.             'security' => "
  66.                 is_granted('ROLE_ADMIN') or 
  67.                 is_granted('ROLE_OPERATOR') or
  68.                 is_granted('ROLE_OPERATIONS_COORDINATOR') or 
  69.                 is_granted('ROLE_RESEARCH_ANALYST') or
  70.                 is_granted('ROLE_BROKER') or 
  71.                 is_granted('ROLE_INTERN')
  72.             ",
  73.             'normalization_context' => [
  74.                 'groups' => [
  75.                     'owner:collection:get'
  76.                     'createdAt'
  77.                 ],
  78.                 'enable_max_depth' => true,
  79.             ],
  80.         ],
  81.         'post' => [
  82.             'security' => "
  83.                 is_granted('ROLE_ADMIN') or 
  84.                 is_granted('ROLE_OPERATOR') or
  85.                 is_granted('ROLE_OPERATIONS_COORDINATOR') or 
  86.                 is_granted('ROLE_RESEARCH_ANALYST') or 
  87.                 is_granted('ROLE_BROKER')
  88.             ",
  89.             'normalization_context' => [
  90.                 'groups' => 'owner:collection:post'
  91.                 'enable_max_depth' => true
  92.             ],
  93.             'denormalization_context' => [
  94.                 'groups' => 'owner:collection:post'
  95.                 'enable_max_depth' => true
  96.             ],
  97.         ],
  98.     ],
  99. )]
  100. #[ApiFilter(
  101.     SearchFilter::class,
  102.     properties: [
  103.         'companyName' => 'partial',
  104.         'addressLine1' => 'partial',
  105.         'addressLine2' => 'partial',
  106.         'addressLine3' => 'partial',
  107.         'charteringEmail' => 'partial',
  108.         'operationsEmail' => 'partial',
  109.         'accountingEmail' => 'partial',
  110.         'detailedCompanyName' => 'partial',
  111.         'createdAt' => 'start',
  112.     ],
  113. )]
  114. #[ApiFilter(
  115.     OrderFilter::class,
  116.     properties: [
  117.         'companyName',
  118.         'addressLine1',
  119.         'addressLine2',
  120.         'addressLine3',
  121.         'charteringEmail',
  122.         'operationsEmail',
  123.         'accountingEmail',
  124.         'detailedCompanyName',
  125.         'createdAt',
  126.     ],
  127. )]
  128. #[ApiFilter(PropertyFilter::class)]
  129. class Owner
  130. {
  131.     use TimestampableEntity;
  132.     #[ORM\Id]
  133.     #[ORM\GeneratedValue(strategy'NONE')]
  134.     #[ORM\Column(type'uuid'uniquetrue)]
  135.     private ?UuidInterface $id null;
  136.     #[ORM\Column(type'string'nullablefalse)]
  137.     #[ApiProperty()]
  138.     #[Assert\NotNull]
  139.     #[Assert\Type('string')]
  140.     #[Groups([
  141.         'owner:collection:get'
  142.         'owner:collection:post'
  143.         'owner:item:get'
  144.         'owner:item:put'
  145.         'vessel:collection:get'
  146.         'vessel:item:get'
  147.         'vessel:item:put'
  148.         'contract:item:get'
  149.         'contract:item:put'
  150.         'contract:collection:get'
  151.         'contract:collection:post',
  152.         'market_rumor:item:get'
  153.         'market_rumor:item:put'
  154.         'market_rumor:collection:get'
  155.         'market_rumor:collection:post'
  156.     ])]
  157.     private ?string $companyName null;
  158.     #[ORM\Column(type'string'nullabletrue)]
  159.     #[ApiProperty()]
  160.     ##[Assert\NotNull]
  161.     ##[Assert\Type('string')]
  162.     #[Groups([
  163.         'owner:collection:get'
  164.         'owner:collection:post'
  165.         'owner:item:get'
  166.         'owner:item:put'
  167.         'vessel:collection:get'
  168.         'vessel:item:get'
  169.     ])]
  170.     private ?string $detailedCompanyName null;
  171.     #[ORM\Column(type'string'nullabletrue)]
  172.     #[ApiProperty()]
  173.     ##[Assert\Type('string')]
  174.     #[Groups([
  175.         'owner:collection:get'
  176.         'owner:collection:post'
  177.         'owner:item:get'
  178.         'owner:item:put'
  179.     ])]
  180.     private ?string $addressLine1 null;
  181.     #[ORM\Column(type'string'nullabletrue)]
  182.     #[ApiProperty()]
  183.     ##[Assert\Type('string')]
  184.     #[Groups([
  185.         'owner:collection:get'
  186.         'owner:collection:post'
  187.         'owner:item:get'
  188.         'owner:item:put'
  189.     ])]
  190.     private ?string $addressLine2 null;
  191.     #[ORM\Column(type'string'nullabletrue)]
  192.     #[ApiProperty()]
  193.     ##[Assert\Type('string')]
  194.     #[Groups([
  195.         'owner:collection:get'
  196.         'owner:collection:post'
  197.         'owner:item:get'
  198.         'owner:item:put'
  199.     ])]
  200.     private ?string $addressLine3 null;
  201.     #[ORM\Column(type'text'nullabletrue)]
  202.     #[ApiProperty()]
  203.     ##[Assert\Email]
  204.     #[Groups([
  205.         'owner:collection:get'
  206.         'owner:collection:post'
  207.         'owner:item:get'
  208.         'owner:item:put'
  209.     ])]
  210.     private ?string $charteringEmail null;
  211.     #[ORM\Column(type'text'nullabletrue)]
  212.     #[ApiProperty()]
  213.     ##[Assert\Email]
  214.     #[Groups([
  215.         'owner:collection:get'
  216.         'owner:collection:post'
  217.         'owner:item:get'
  218.         'owner:item:put'
  219.     ])]
  220.     private ?string $operationsEmail null;
  221.     #[ORM\Column(type'text'nullabletrue)]
  222.     #[ApiProperty()]
  223.     ##[Assert\Email]
  224.     #[Groups([
  225.         'owner:collection:get'
  226.         'owner:collection:post'
  227.         'owner:item:get'
  228.         'owner:item:put'
  229.     ])]
  230.     private ?string $accountingEmail null;
  231.     #[ORM\OneToMany(
  232.         targetEntityVessel::class, 
  233.         mappedBy'owner'
  234.     )]
  235.     private ?Collection $vessels null;
  236.     #[ORM\OneToMany(
  237.         targetEntityContract::class, 
  238.         mappedBy'owner'
  239.     )]
  240.     private ?Collection $contracts null;
  241.     #[ORM\OneToMany(
  242.         targetEntityMarketRumor::class, 
  243.         mappedBy'owner'
  244.     )]
  245.     private ?Collection $marketRumors null;
  246.     public function __construct()
  247.     {
  248.         $this->id Uuid::uuid4();
  249.         $this->vessels = new ArrayCollection();
  250.         $this->contracts = new ArrayCollection();
  251.         $this->marketRumors = new ArrayCollection();
  252.     }
  253.     public function getId(): ?UuidInterface
  254.     {
  255.         return $this->id;
  256.     }
  257.     public function setCompanyName(?string $companyName): void
  258.     {
  259.         $this->companyName $companyName;
  260.     }
  261.     public function getCompanyName(): ?string
  262.     {
  263.         return $this->companyName;
  264.     }
  265.     public function setDetailedCompanyName(?string $detailedCompanyName): void
  266.     {
  267.         $this->detailedCompanyName $detailedCompanyName;
  268.     }
  269.     public function getDetailedCompanyName(): ?string
  270.     {
  271.         return $this->detailedCompanyName;
  272.     }
  273.     public function setAddressLine1(?string $addressLine1): void
  274.     {
  275.         $this->addressLine1 $addressLine1;
  276.     }
  277.     public function getAddressLine1(): ?string
  278.     {
  279.         return $this->addressLine1;
  280.     }
  281.     public function setAddressLine2(?string $addressLine2): void
  282.     {
  283.         $this->addressLine2 $addressLine2;
  284.     }
  285.     public function getAddressLine2(): ?string
  286.     {
  287.         return $this->addressLine2;
  288.     }
  289.     public function setAddressLine3(?string $addressLine3): void
  290.     {
  291.         $this->addressLine3 $addressLine3;
  292.     }
  293.     public function getAddressLine3(): ?string
  294.     {
  295.         return $this->addressLine3;
  296.     }
  297.     public function setCharteringEmail(?string $charteringEmail): void
  298.     {
  299.         $this->charteringEmail $charteringEmail;
  300.     }
  301.     public function getCharteringEmail(): ?string
  302.     {
  303.         return $this->charteringEmail;
  304.     }
  305.     public function setOperationsEmail(?string $operationsEmail): void
  306.     {
  307.         $this->operationsEmail $operationsEmail;
  308.     }
  309.     public function getOperationsEmail(): ?string
  310.     {
  311.         return $this->operationsEmail;
  312.     }
  313.     public function setAccountingEmail(?string $accountingEmail): void
  314.     {
  315.         $this->accountingEmail $accountingEmail;
  316.     }
  317.     public function getAccountingEmail(): ?string
  318.     {
  319.         return $this->accountingEmail;
  320.     }
  321.     public function addVessel(Vessel $vessel): void
  322.     {
  323.         $this->vessels[] = $vessel;
  324.     }
  325.     public function removeVessel(Vessel $vessel): void
  326.     {
  327.         $this->vessels->removeElement($vessel);
  328.     }
  329.     public function getVessels(): Collection
  330.     {
  331.         return $this->vessels;
  332.     }
  333.     public function getContracts(): Collection
  334.     {
  335.         return $this->contracts;
  336.     }
  337.     public function addContract(Contract $contract): self
  338.     {
  339.         if (!$this->contracts->contains($contract)) {
  340.             $this->contracts[] = $contract;
  341.             $contract->setOwner($this);
  342.         }
  343.         return $this;
  344.     }
  345.     public function removeContract(Contract $contract): self
  346.     {
  347.         if ($this->contracts->removeElement($contract)) {
  348.             if ($contract->getOwner() === $this) {
  349.                 $contract->setOwner(null);
  350.             }
  351.         }
  352.         
  353.         return $this;
  354.     }
  355.     public function getMarketRumors(): Collection
  356.     {
  357.         return $this->marketRumors;
  358.     }
  359.     public function addMarketRumor(MarketRumor $marketRumor): self
  360.     {
  361.         if (!$this->marketRumors->contains($marketRumor)) {
  362.             $this->marketRumors[] = $marketRumor;
  363.             $marketRumor->setOwner($this);
  364.         }
  365.         return $this;
  366.     }
  367.     public function removeMarketRumor(MarketRumor $marketRumor): self
  368.     {
  369.         if ($this->marketRumors->removeElement($marketRumor)) {
  370.             if ($marketRumor->getOwner() === $this) {
  371.                 $marketRumor->setOwner(null);
  372.             }
  373.         }
  374.         
  375.         return $this;
  376.     }
  377. }