src/Entity/Insured.php line 81

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 ApiPlatform\Core\Annotation\ApiFilter;
  7. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  8. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
  9. use App\Trait\TimestampableEntity;
  10. use Doctrine\Common\Collections\ArrayCollection;
  11. use Doctrine\Common\Collections\Collection;
  12. use Doctrine\ORM\Mapping as ORM;
  13. use Symfony\Component\Validator\Constraints as Assert;
  14. use Symfony\Component\Serializer\Annotation\Groups;
  15. use Symfony\Component\Serializer\Annotation\MaxDepth;
  16. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  17. #[ORM\Entity]
  18. #[UniqueEntity('taxID')]
  19. #[ApiResource(
  20.     iri'Insured',
  21.     itemOperations: [
  22.         'get' => [
  23.             // 'security' => "is_granted('ROLE_ADMIN')",
  24.             'normalization_context' => [
  25.                 'groups' => 'insured:item:get',
  26.                 'enable_max_depth' => true
  27.             ]
  28.         ],
  29.         'put' => [
  30.             // 'security' => "is_granted('ROLE_USER')",
  31.             'normalization_context' => [
  32.                 'groups' => 'insured:item:put',
  33.                 'enable_max_depth' => true
  34.             ],
  35.             'denormalization_context' => [
  36.                 'groups' => 'insured:item:put',
  37.                 'enable_max_depth' => true
  38.             ]
  39.         ],
  40.         'delete' => [
  41.             // 'security' => "is_granted('ROLE_USER')",
  42.         ]
  43.     ],
  44.     collectionOperations: [
  45.         'get' => [
  46.             // 'security' => "is_granted('ROLE_USER')",
  47.             'normalization_context' => [
  48.                 'groups' => ['insured:collection:get''createdAt'],
  49.                 'enable_max_depth' => true
  50.             ]
  51.         ],
  52.         'post' => [
  53.             // 'security' => "is_granted('ROLE_USER')",
  54.             'normalization_context' => [
  55.                 'groups' => 'insured:collection:post',
  56.                 'enable_max_depth' => true
  57.             ],
  58.             'denormalization_context' => [
  59.                 'groups' => 'insured:collection:post',
  60.                 'enable_max_depth' => true
  61.             ]
  62.         ],
  63.     ]
  64. )]
  65. #[ApiFilter(SearchFilter::class, properties: [
  66.     'broker' => 'exact',
  67.     'taxID' => 'start'
  68.     'name' => 'partial',
  69.     'legalName' => 'partial',
  70.     'createdAt' => 'start',
  71. ])]
  72. #[ApiFilter(OrderFilter::class, properties: [
  73.     'name',
  74.     'taxID',
  75.     'createdAt'
  76. ])]
  77. class Insured
  78. {
  79.     use TimestampableEntity;
  80.     
  81.     #[ORM\Id]
  82.     #[ORM\GeneratedValue(strategy'AUTO')]
  83.     #[ORM\Column(type'integer')]
  84.     #[Groups([
  85.         'insured:collection:get',
  86.         'insured:item:get',
  87.         'demand:item:put',
  88.         'user:collection:post',
  89.         'user:item:put',
  90.     ])]
  91.     private ?int $id null;
  92.     /**
  93.      * The name of the item.
  94.      *
  95.      * @see https://schema.org/name
  96.      */
  97.     #[ORM\Column(type'string')]
  98.     #[ApiProperty(iri'https://schema.org/name')]
  99.     #[Assert\Type('string')]
  100.     #[Groups([
  101.         'import:insured',
  102.         'insured:collection:get',
  103.         'insured:collection:post',
  104.         'insured:item:get',
  105.         'insured:item:put',
  106.         'policy:collection:post',
  107.         'policy:item:get',
  108.         'policy:item:put',
  109.         'demand:collection:get',
  110.         'demand:item:get',
  111.         'insured_insurer:collection:get',
  112.         'insured_insurer:item:get',
  113.         'insured_insurer:item:put',
  114.         'policy:collection:get',
  115.         'user:item:get',
  116.         'broker:item:get',
  117.     ])]
  118.     private ?string $name null;
  119.     #[ORM\Column(type'string')]
  120.     #[ApiProperty()]
  121.     #[Assert\Type('string')]
  122.     #[Groups([
  123.         'import:insured',
  124.         'insured:collection:post',
  125.         'insured:item:get',
  126.         'insured:item:put',
  127.     ])]
  128.     private ?string $zipcode null;
  129.     #[ORM\Column(type'string'nullabletrue)]
  130.     #[ApiProperty()]
  131.     #[Assert\Type('string')]
  132.     #[Groups([
  133.         'import:insured',
  134.         'insured:collection:post',
  135.         'insured:item:get',
  136.         'insured:item:put',
  137.     ])]
  138.     private ?string $address null;
  139.     #[ORM\Column(type'string'nullabletrue)]
  140.     #[ApiProperty()]
  141.     #[Assert\Type('string')]
  142.     #[Groups([
  143.         'import:insured',
  144.         'insured:collection:post',
  145.         'insured:item:get',
  146.         'insured:item:put',
  147.     ])]
  148.     private ?string $complement null;
  149.     #[ORM\Column(type'string'nullabletrue)]
  150.     #[ApiProperty()]
  151.     #[Assert\Type('string')]
  152.     #[Groups([
  153.         'import:insured',
  154.         'insured:collection:post',
  155.         'insured:item:get',
  156.         'insured:item:put',
  157.     ])]
  158.     private ?string $neighborhood null;
  159.     #[ORM\Column(type'string'nullabletrue)]
  160.     #[ApiProperty()]
  161.     #[Assert\Type('string')]
  162.     #[Groups([
  163.         'import:insured',
  164.         'insured:collection:post',
  165.         'insured:item:get',
  166.         'insured:item:put',
  167.     ])]
  168.     private ?string $city null;
  169.     #[ORM\Column(type'string'nullabletrue)]
  170.     #[ApiProperty()]
  171.     #[Assert\Type('string')]
  172.     #[Groups([
  173.         'import:insured',
  174.         'insured:collection:post',
  175.         'insured:item:get',
  176.         'insured:item:put',
  177.     ])]
  178.     private ?string $state null;
  179.     /**
  180.      * Email address.
  181.      *
  182.      * @see https://schema.org/email
  183.      */
  184.     #[ORM\Column(type'string')]
  185.     #[ApiProperty(iri'https://schema.org/email')]
  186.     #[Assert\Email]
  187.     #[Groups([
  188.         'import:insured',
  189.         'insured:collection:post',
  190.         'insured:item:get',
  191.         'insured:item:put',
  192.     ])]
  193.     private ?string $email null;
  194.     /**
  195.      * The official name of the organization, e.g. the registered company name.
  196.      *
  197.      * @see https://schema.org/legalName
  198.      */
  199.     #[ORM\Column(type'string')]
  200.     #[ApiProperty(iri'https://schema.org/legalName')]
  201.     #[Assert\Type('string')]
  202.     #[Groups([
  203.         'import:insured',
  204.         'insured:collection:get',
  205.         'insured:collection:post',
  206.         'insured:item:get',
  207.         'insured:item:put',
  208.     ])]
  209.     private ?string $legalName null;
  210.     /**
  211.      * The Tax / Fiscal ID of the organization or person, e.g. the TIN in the US or the CIF/NIF in Spain.
  212.      *
  213.      * @see https://schema.org/taxID
  214.      */
  215.     #[ORM\Column(type'string'uniquetrue)]
  216.     #[ApiProperty(iri'https://schema.org/taxID')]
  217.     #[Assert\Type('string')]
  218.     #[Groups([
  219.         'import:insured',
  220.         'insured:collection:get',
  221.         'insured:collection:post',
  222.         'insured:item:get',
  223.         'insured:item:put',
  224.         'demand:item:get',
  225.         'policy:item:get',
  226.         'demand:collection:get',
  227.         'policy:collection:get',
  228.         'user:item:get',
  229.         'broker:item:get',
  230.     ])]
  231.     private ?string $taxID null;
  232.     /**
  233.      * The telephone number.
  234.      *
  235.      * @see https://schema.org/telephone
  236.      */
  237.     #[ORM\Column(type'string'nullabletrue)]
  238.     #[ApiProperty(iri'https://schema.org/telephone')]
  239.     #[Assert\Type('string')]
  240.     #[Groups([
  241.         'import:insured',
  242.         'insured:collection:post',
  243.         'insured:item:get',
  244.         'insured:item:put',
  245.     ])]
  246.     private ?string $telephone null;
  247.     /**
  248.      * @var string|null the larger organization that this organization is a \[\[subOrganization\]\] of, if any
  249.      *
  250.      * @see https://schema.org/parentOrganization
  251.      */
  252.     #[ORM\Column(type'string'nullabletrue)]
  253.     #[ApiProperty(iri'https://schema.org/parentOrganization')]
  254.     #[Groups([
  255.         'import:insured',
  256.         'insured:collection:post',
  257.         'insured:item:get',
  258.         'insured:item:put',
  259.     ])]
  260.     private ?string $parentOrganization null;
  261.     #[ORM\OneToMany(mappedBy'insured'targetEntityInsuredUpload::class, cascade: ["remove"], orphanRemovaltrue)]
  262.     #[Groups([
  263.         'insured:item:get',
  264.     ])]
  265.     #[MaxDepth(1)]
  266.     private $uploads;
  267.     #[ORM\OneToMany(mappedBy'insured'targetEntityDemand::class, cascade: ["remove"], orphanRemovaltrue)]
  268.     private $demands;
  269.     #[ORM\OneToMany(mappedBy'insured'targetEntityPolicy::class, cascade: ["remove"], orphanRemovaltrue)]
  270.     private $policies;
  271.     #[ORM\OneToMany(mappedBy'insured'targetEntityInsuredInsurer::class, cascade: ["persist""remove"], orphanRemovaltrue)]
  272.     #[ORM\OrderBy(["name" => "ASC"])]
  273.     #[Groups([
  274.         // 'import:insured',
  275.         'insured:item:put',
  276.     ])]
  277.     #[MaxDepth(1)]
  278.     private $insurers;
  279.     #[ORM\OneToMany(mappedBy'insured'targetEntityInsuredInsurerGlobal::class, cascade: ["persist""remove"], orphanRemovaltrue)]
  280.     #[ORM\OrderBy(["name" => "ASC"])]
  281.     #[Groups([
  282.         // 'import:insured',
  283.         'insured:item:get',
  284.         'insured:item:put',
  285.     ])]
  286.     #[MaxDepth(1)]
  287.     private $insurerGlobals;
  288.     #[ORM\OneToMany(mappedBy'insured'targetEntityInsuredUser::class, cascade: ["remove"], orphanRemovaltrue)]
  289.     #[Groups([
  290.         'import:insured',
  291.         'insured:item:get',
  292.     ])]
  293.     #[MaxDepth(1)]
  294.     private $users;
  295.     #[ORM\OneToMany(mappedBy'insured'targetEntityInsuredEmission::class, cascade: ["persist""remove"], orphanRemovaltrue)]
  296.     #[Groups([
  297.         'insured:collection:post',
  298.         'insured:item:get',
  299.         'insured:item:put',
  300.     ])]
  301.     #[MaxDepth(1)]
  302.     private $emissions;
  303.     #[ORM\ManyToOne(targetEntityBroker::class, inversedBy'insureds')]
  304.     #[ApiProperty()]
  305.     #[Groups([
  306.         'insured:collection:post',
  307.         'insured:item:get',
  308.         'insured:item:put',
  309.     ])]
  310.     #[MaxDepth(1)]
  311.     private $broker;
  312.     public function __construct()
  313.     {
  314.         $this->uploads = new ArrayCollection();
  315.         $this->demands = new ArrayCollection();
  316.         $this->policies = new ArrayCollection();
  317.         $this->insurers = new ArrayCollection();
  318.         $this->insurerGlobals = new ArrayCollection();
  319.         $this->users = new ArrayCollection();
  320.         $this->emissions = new ArrayCollection();
  321.     }
  322.     public function getId(): ?int
  323.     {
  324.         return $this->id;
  325.     }
  326.     public function setName(?string $name): void
  327.     {
  328.         $this->name $name;
  329.     }
  330.     public function getName(): ?string
  331.     {
  332.         return $this->name;
  333.     }
  334.     public function getZipcode(): ?string
  335.     {
  336.         return $this->zipcode;
  337.     }
  338.     public function setZipcode(?string $zipcode): self
  339.     {
  340.         $this->zipcode $zipcode;
  341.         return $this;
  342.     }
  343.     public function setAddress(?string $address): void
  344.     {
  345.         $this->address $address;
  346.     }
  347.     public function getAddress(): ?string
  348.     {
  349.         return $this->address;
  350.     }
  351.     public function getComplement(): ?string
  352.     {
  353.         return $this->complement;
  354.     }
  355.     public function setComplement(?string $complement): self
  356.     {
  357.         $this->complement $complement;
  358.         return $this;
  359.     }
  360.     public function getNeighborhood(): ?string
  361.     {
  362.         return $this->neighborhood;
  363.     }
  364.     public function setNeighborhood(?string $neighborhood): self
  365.     {
  366.         $this->neighborhood $neighborhood;
  367.         return $this;
  368.     }
  369.     public function getCity(): ?string
  370.     {
  371.         return $this->city;
  372.     }
  373.     public function setCity(?string $city): self
  374.     {
  375.         $this->city $city;
  376.         return $this;
  377.     }
  378.     public function getState(): ?string
  379.     {
  380.         return $this->state;
  381.     }
  382.     public function setState(?string $state): self
  383.     {
  384.         $this->state $state;
  385.         return $this;
  386.     }
  387.     public function setEmail(?string $email): void
  388.     {
  389.         $this->email $email;
  390.     }
  391.     public function getEmail(): ?string
  392.     {
  393.         return $this->email;
  394.     }
  395.     public function setLegalName(?string $legalName): void
  396.     {
  397.         $this->legalName $legalName;
  398.     }
  399.     public function getLegalName(): ?string
  400.     {
  401.         return $this->legalName;
  402.     }
  403.     public function setTaxID(?string $taxID): void
  404.     {
  405.         $this->taxID $taxID;
  406.     }
  407.     public function getTaxID(): ?string
  408.     {
  409.         return $this->taxID;
  410.     }
  411.     public function setTelephone(?string $telephone): void
  412.     {
  413.         $this->telephone $telephone;
  414.     }
  415.     public function getTelephone(): ?string
  416.     {
  417.         return $this->telephone;
  418.     }
  419.     /**
  420.      * @param string|null $parentOrganization
  421.      */
  422.     public function setParentOrganization(?string $parentOrganization): void
  423.     {
  424.         $this->parentOrganization $parentOrganization;
  425.     }
  426.     public function getParentOrganization(): ?string
  427.     {
  428.         return $this->parentOrganization;
  429.     }
  430.     /**
  431.      * @return Collection|InsuredUpload[]
  432.      */
  433.     public function getUploads(): Collection
  434.     {
  435.         return $this->uploads;
  436.     }
  437.     public function addUpload(InsuredUpload $upload): self
  438.     {
  439.         if (!$this->uploads->contains($upload)) {
  440.             $this->uploads[] = $upload;
  441.             $upload->setInsured($this);
  442.         }
  443.         return $this;
  444.     }
  445.     public function removeUpload(InsuredUpload $upload): self
  446.     {
  447.         if ($this->uploads->removeElement($upload)) {
  448.             // set the owning side to null (unless already changed)
  449.             if ($upload->getInsured() === $this) {
  450.                 $upload->setInsured(null);
  451.             }
  452.         }
  453.         return $this;
  454.     }
  455.     /**
  456.      * @return Collection|Demand[]
  457.      */
  458.     public function getDemands(): Collection
  459.     {
  460.         return $this->demands;
  461.     }
  462.     public function addDemand(Demand $demand): self
  463.     {
  464.         if (!$this->demands->contains($demand)) {
  465.             $this->demands[] = $demand;
  466.             $demand->setInsured($this);
  467.         }
  468.         return $this;
  469.     }
  470.     public function removeDemand(Demand $demand): self
  471.     {
  472.         if ($this->demands->removeElement($demand)) {
  473.             // set the owning side to null (unless already changed)
  474.             if ($demand->getInsured() === $this) {
  475.                 $demand->setInsured(null);
  476.             }
  477.         }
  478.         return $this;
  479.     }
  480.     /**
  481.      * @return Collection|Policy[]
  482.      */
  483.     public function getPolicies(): Collection
  484.     {
  485.         return $this->policies;
  486.     }
  487.     public function addPolicy(Policy $policy): self
  488.     {
  489.         if (!$this->policies->contains($policy)) {
  490.             $this->policies[] = $policy;
  491.             $policy->setInsured($this);
  492.         }
  493.         return $this;
  494.     }
  495.     public function removePolicy(Policy $policy): self
  496.     {
  497.         if ($this->policies->removeElement($policy)) {
  498.             // set the owning side to null (unless already changed)
  499.             if ($policy->getInsured() === $this) {
  500.                 $policy->setInsured(null);
  501.             }
  502.         }
  503.         return $this;
  504.     }
  505.     /**
  506.      * @return Collection|InsuredInsurer[]
  507.      */
  508.     public function getInsurers(): Collection
  509.     {
  510.         return $this->insurers;
  511.     }
  512.     public function addInsurer(InsuredInsurer $insurer): self
  513.     {
  514.         if (!$this->insurers->contains($insurer)) {
  515.             $this->insurers[] = $insurer;
  516.             $insurer->setInsured($this);
  517.         }
  518.         return $this;
  519.     }
  520.     public function removeInsurer(InsuredInsurer $insurer): self
  521.     {
  522.         if ($this->insurers->removeElement($insurer)) {
  523.             // set the owning side to null (unless already changed)
  524.             if ($insurer->getInsured() === $this) {
  525.                 $insurer->setInsured(null);
  526.             }
  527.         }
  528.         return $this;
  529.     }
  530.     /**
  531.      * @return Collection|InsuredInsurerGlobal[]
  532.      */
  533.     public function getInsurerGlobals(): Collection
  534.     {
  535.         return $this->insurerGlobals;
  536.     }
  537.     public function addInsurerGlobal(InsuredInsurerGlobal $insurerGlobal): self
  538.     {
  539.         if (!$this->insurerGlobals->contains($insurerGlobal)) {
  540.             $this->insurerGlobals[] = $insurerGlobal;
  541.             $insurerGlobal->setInsured($this);
  542.         }
  543.         return $this;
  544.     }
  545.     public function removeInsurerGlobal(InsuredInsurerGlobal $insurerGlobal): self
  546.     {
  547.         if ($this->insurerGlobals->removeElement($insurerGlobal)) {
  548.             // set the owning side to null (unless already changed)
  549.             if ($insurerGlobal->getInsured() === $this) {
  550.                 $insurerGlobal->setInsured(null);
  551.             }
  552.         }
  553.         return $this;
  554.     }
  555.     /**
  556.      * @return Collection|InsuredUser[]
  557.      */
  558.     public function getUsers(): Collection
  559.     {
  560.         return $this->users;
  561.     }
  562.     public function addUser(InsuredUser $user): self
  563.     {
  564.         if (!$this->users->contains($user)) {
  565.             $this->users[] = $user;
  566.             $user->setInsured($this);
  567.         }
  568.         return $this;
  569.     }
  570.     public function removeUser(InsuredUser $user): self
  571.     {
  572.         if ($this->users->removeElement($user)) {
  573.             // set the owning side to null (unless already changed)
  574.             if ($user->getInsured() === $this) {
  575.                 $user->setInsured(null);
  576.             }
  577.         }
  578.         return $this;
  579.     }
  580.     /**
  581.      * @return Collection|InsuredEmission[]
  582.      */
  583.     public function getEmissions(): Collection
  584.     {
  585.         return $this->emissions;
  586.     }
  587.     public function addEmission(InsuredEmission $emission): self
  588.     {
  589.         if (!$this->emissions->contains($emission)) {
  590.             $this->emissions[] = $emission;
  591.             $emission->setInsured($this);
  592.         }
  593.         return $this;
  594.     }
  595.     public function removeEmission(InsuredEmission $emission): self
  596.     {
  597.         if ($this->emissions->removeElement($emission)) {
  598.             // set the owning side to null (unless already changed)
  599.             if ($emission->getInsured() === $this) {
  600.                 $emission->setInsured(null);
  601.             }
  602.         }
  603.         return $this;
  604.     }
  605.     public function getBroker(): ?Broker
  606.     {
  607.         return $this->broker;
  608.     }
  609.     public function setBroker(?Broker $broker): self
  610.     {
  611.         $this->broker $broker;
  612.         return $this;
  613.     }
  614. }