src/Entity/Charterer.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'Charterer',
  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' => 'charterer: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' => 'charterer:item:put'
  46.                 'enable_max_depth' => true
  47.             ],
  48.             'denormalization_context' => [
  49.                 'groups' => 'charterer: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.                     'charterer: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' => 'charterer:collection:post'
  91.                 'enable_max_depth' => true
  92.             ],
  93.             'denormalization_context' => [
  94.                 'groups' => 'charterer: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 Charterer
  130. {
  131.     use TimestampableEntity;
  132.     
  133.     #[ORM\Id]
  134.     #[ORM\GeneratedValue(strategy'NONE')]
  135.     #[ORM\Column(type'uuid'uniquetrue)]
  136.     private ?UuidInterface $id null;
  137.     #[ORM\Column(type'string'nullablefalse)]
  138.     #[ApiProperty()]
  139.     #[Assert\NotBlank]
  140.     #[Assert\Type('string')]
  141.     #[Groups([
  142.         'charterer:collection:get'
  143.         'charterer:collection:post'
  144.         'charterer:item:get'
  145.         'charterer:item:put'
  146.         'contract:item:get'
  147.         'contract:item:put'
  148.         'contract:collection:get'
  149.         'contract:collection:post',
  150.         'market_rumor:item:get'
  151.         'market_rumor:item:put'
  152.         'market_rumor:collection:get'
  153.         'market_rumor:collection:post'
  154.     ])]
  155.     private ?string $companyName null;
  156.     #[ORM\Column(type'string'nullabletrue)]
  157.     #[ApiProperty()]
  158.     ##[Assert\Type('string')]
  159.     #[Groups([
  160.         'charterer:collection:get'
  161.         'charterer:collection:post'
  162.         'charterer:item:get'
  163.         'charterer:item:put'
  164.     ])]
  165.     private ?string $addressLine1 null;
  166.     #[ORM\Column(type'string'nullabletrue)]
  167.     #[ApiProperty()]
  168.     ##[Assert\Type('string')]
  169.     #[Groups([
  170.         'charterer:collection:get'
  171.         'charterer:collection:post'
  172.         'charterer:item:get'
  173.         'charterer:item:put'
  174.     ])]
  175.     private ?string $addressLine2 null;
  176.     #[ORM\Column(type'string'nullabletrue)]
  177.     #[ApiProperty()]
  178.     ##[Assert\Type('string')]
  179.     #[Groups([
  180.         'charterer:collection:get'
  181.         'charterer:collection:post'
  182.         'charterer:item:get'
  183.         'charterer:item:put'
  184.     ])]
  185.     private ?string $addressLine3 null;
  186.     #[ORM\Column(type'text'nullabletrue)]
  187.     #[ApiProperty()]
  188.     ##[Assert\Email]
  189.     #[Groups([
  190.         'charterer:collection:get'
  191.         'charterer:collection:post'
  192.         'charterer:item:get'
  193.         'charterer:item:put'
  194.     ])]
  195.     private ?string $charteringEmail null;
  196.     #[ORM\Column(type'text'nullabletrue)]
  197.     #[ApiProperty()]
  198.     ##[Assert\Email]
  199.     #[Groups([
  200.         'charterer:collection:get'
  201.         'charterer:collection:post'
  202.         'charterer:item:get'
  203.         'charterer:item:put'
  204.     ])]
  205.     private ?string $operationsEmail null;
  206.     #[ORM\Column(type'text'nullabletrue)]
  207.     #[ApiProperty()]
  208.     ##[Assert\Email]
  209.     #[Groups([
  210.         'charterer:collection:get'
  211.         'charterer:collection:post'
  212.         'charterer:item:get'
  213.         'charterer:item:put'
  214.     ])]
  215.     private ?string $accountingEmail null;
  216.     #[ORM\Column(type'text'nullabletrue)]
  217.     #[ApiProperty()]
  218.     ##[Assert\Type('string')]
  219.     #[Groups([
  220.         'charterer:collection:get'
  221.         'charterer:collection:post'
  222.         'charterer:item:get'
  223.         'charterer:item:put'
  224.     ])]
  225.     private ?string $observations null;
  226.     #[ORM\OneToMany(
  227.         targetEntityContract::class, 
  228.         mappedBy'charterer'
  229.     )]
  230.     private ?Collection $contracts null;
  231.     #[ORM\OneToMany(
  232.         targetEntityMarketRumor::class, 
  233.         mappedBy'charterer'
  234.     )]
  235.     private ?Collection $marketRumors null;
  236.     #[ORM\OneToMany(
  237.         targetEntityMarketRumor::class, 
  238.         mappedBy'charterer2'
  239.     )]
  240.     private ?Collection $marketRumors2 null;
  241.     public function __construct()
  242.     {
  243.         $this->id Uuid::uuid4();
  244.         $this->contracts = new ArrayCollection();
  245.         $this->marketRumors = new ArrayCollection();
  246.         $this->marketRumors2 = new ArrayCollection();
  247.     }
  248.     public function getId(): ?UuidInterface
  249.     {
  250.         return $this->id;
  251.     }
  252.     public function setCompanyName(?string $companyName): void
  253.     {
  254.         $this->companyName $companyName;
  255.     }
  256.     public function getCompanyName(): ?string
  257.     {
  258.         return $this->companyName;
  259.     }
  260.     public function setAddressLine1(?string $addressLine1): void
  261.     {
  262.         $this->addressLine1 $addressLine1;
  263.     }
  264.     public function getAddressLine1(): ?string
  265.     {
  266.         return $this->addressLine1;
  267.     }
  268.     public function setAddressLine2(?string $addressLine2): void
  269.     {
  270.         $this->addressLine2 $addressLine2;
  271.     }
  272.     public function getAddressLine2(): ?string
  273.     {
  274.         return $this->addressLine2;
  275.     }
  276.     public function setAddressLine3(?string $addressLine3): void
  277.     {
  278.         $this->addressLine3 $addressLine3;
  279.     }
  280.     public function getAddressLine3(): ?string
  281.     {
  282.         return $this->addressLine3;
  283.     }
  284.     public function setCharteringEmail(?string $charteringEmail): void
  285.     {
  286.         $this->charteringEmail $charteringEmail;
  287.     }
  288.     public function getCharteringEmail(): ?string
  289.     {
  290.         return $this->charteringEmail;
  291.     }
  292.     public function setOperationsEmail(?string $operationsEmail): void
  293.     {
  294.         $this->operationsEmail $operationsEmail;
  295.     }
  296.     public function getOperationsEmail(): ?string
  297.     {
  298.         return $this->operationsEmail;
  299.     }
  300.     public function setAccountingEmail(?string $accountingEmail): void
  301.     {
  302.         $this->accountingEmail $accountingEmail;
  303.     }
  304.     public function getAccountingEmail(): ?string
  305.     {
  306.         return $this->accountingEmail;
  307.     }
  308.     public function setObservations(?string $observations): void
  309.     {
  310.         $this->observations $observations;
  311.     }
  312.     public function getObservations(): ?string
  313.     {
  314.         return $this->observations;
  315.     }
  316.     public function getContracts(): Collection
  317.     {
  318.         return $this->contracts;
  319.     }
  320.     public function addContract(Contract $contract): self
  321.     {
  322.         if (!$this->contracts->contains($contract)) {
  323.             $this->contracts[] = $contract;
  324.             $contract->setCharterer($this);
  325.         }
  326.         return $this;
  327.     }
  328.     public function removeContract(Contract $contract): self
  329.     {
  330.         if ($this->contracts->removeElement($contract)) {
  331.             if ($contract->getCharterer() === $this) {
  332.                 $contract->setCharterer(null);
  333.             }
  334.         }
  335.         
  336.         return $this;
  337.     }
  338.     public function getMarketRumors(): Collection
  339.     {
  340.         return $this->marketRumors;
  341.     }
  342.     public function addMarketRumor(MarketRumor $marketRumor): self
  343.     {
  344.         if (!$this->marketRumors->contains($marketRumor)) {
  345.             $this->marketRumors[] = $marketRumor;
  346.             $marketRumor->setCharterer($this);
  347.         }
  348.         return $this;
  349.     }
  350.     public function removeMarketRumor(MarketRumor $marketRumor): self
  351.     {
  352.         if ($this->marketRumors->removeElement($marketRumor)) {
  353.             if ($marketRumor->getCharterer() === $this) {
  354.                 $marketRumor->setCharterer(null);
  355.             }
  356.         }
  357.         
  358.         return $this;
  359.     }
  360.     public function getMarketRumors2(): Collection
  361.     {
  362.         return $this->marketRumors2;
  363.     }
  364.     public function addMarketRumor2(MarketRumor $marketRumor): self
  365.     {
  366.         if (!$this->marketRumors2->contains($marketRumor)) {
  367.             $this->marketRumors2[] = $marketRumor;
  368.             $marketRumor->setCharterer2($this);
  369.         }
  370.         return $this;
  371.     }   
  372.     public function removeMarketRumor2(MarketRumor $marketRumor): self
  373.     {
  374.         if ($this->marketRumors2->removeElement($marketRumor)) {
  375.             if ($marketRumor->getCharterer2() === $this) {
  376.                 $marketRumor->setCharterer2(null);
  377.             }
  378.         }
  379.         
  380.         return $this;
  381.     }
  382. }