src/Entity/Insurer.php line 80

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. #[ORM\Entity]
  17. #[ApiResource(
  18.     iri'Insurer',
  19.     itemOperations: [
  20.         'get' => [
  21.             // 'security' => "is_granted('ROLE_USER')",
  22.             'normalization_context' => [
  23.                 'groups' => 'insurer:item:get',
  24.                 'enable_max_depth' => true
  25.             ]
  26.         ],
  27.         'put' => [
  28.             // 'security' => "is_granted('ROLE_USER')",
  29.             'normalization_context' => [
  30.                 'groups' => 'insurer:item:put',
  31.                 'enable_max_depth' => true
  32.             ],
  33.             'denormalization_context' => [
  34.                 'groups' => 'insurer:item:put',
  35.                 'enable_max_depth' => true
  36.             ]
  37.         ],
  38.         'delete' => [
  39.             // 'security' => "is_granted('ROLE_USER')",
  40.         ]
  41.     ],
  42.     collectionOperations: [
  43.         'get' => [
  44.             // 'security' => "is_granted('ROLE_USER')",
  45.             'normalization_context' => [
  46.                 'groups' => ['insurer:collection:get''createdAt'],
  47.                 'enable_max_depth' => true
  48.             ]
  49.         ],
  50.         'post' => [
  51.             // 'security' => "is_granted('ROLE_USER')",
  52.             'normalization_context' => [
  53.                 'groups' => 'insurer:collection:post',
  54.                 'enable_max_depth' => true
  55.             ],
  56.             'denormalization_context' => [
  57.                 'groups' => 'insurer:collection:post',
  58.                 'enable_max_depth' => true
  59.             ]
  60.         ],
  61.     ]
  62. )]
  63. #[ApiFilter(SearchFilter::class, properties: [
  64.     'insureds.insured' => 'exact',
  65.     'taxID' => 'start',
  66.     'name' => 'partial',
  67.     'legalName' => 'partial',
  68.     'createdAt' => 'start',
  69. ])]
  70. #[ApiFilter(OrderFilter::class, properties: [
  71.     'name',
  72.     'taxID',
  73.     'legalName',
  74.     'createdAt'
  75. ])]
  76. class Insurer
  77. {
  78.     use TimestampableEntity;
  79.     
  80.     #[ORM\Id]
  81.     #[ORM\GeneratedValue(strategy'AUTO')]
  82.     #[ORM\Column(type'integer')]
  83.     #[Groups([
  84.         'insurer:collection:get',
  85.         'insurer:item:get',
  86.         'user:collection:post',
  87.         'user:item:put',
  88.     ])]
  89.     private ?int $id null;
  90.     /**
  91.      * The name of the item.
  92.      *
  93.      * @see https://schema.org/name
  94.      */
  95.     #[ORM\Column(type'string')]
  96.     #[ApiProperty(iri'https://schema.org/name')]
  97.     #[Assert\Type('string')]
  98.     #[Groups([
  99.         'import:insurer',
  100.         'insurer:collection:get',
  101.         'insurer:collection:post',
  102.         'insurer:item:get',
  103.         'insurer:item:put',
  104.         'demand:collection:post',
  105.         'demand:item:get',
  106.         'demand:item:put',
  107.         'insured_insurer:collection:get',
  108.         'insured_insurer:item:get',
  109.         'insured_insurer:item:put',
  110.         'policy:collection:get',
  111.         'user:item:get',
  112.     ])]
  113.     private ?string $name null;
  114.     /**
  115.      * The official name of the organization, e.g. the registered company name.
  116.      *
  117.      * @see https://schema.org/legalName
  118.      */
  119.     #[ORM\Column(type'string')]
  120.     #[ApiProperty(iri'https://schema.org/legalName')]
  121.     #[Assert\Type('string')]
  122.     #[Groups([
  123.         'import:insurer',
  124.         'insurer:collection:get',
  125.         'insurer:collection:post',
  126.         'insurer:item:get',
  127.         'insurer:item:put',
  128.     ])]
  129.     private ?string $legalName null;
  130.     /**
  131.      * The Tax / Fiscal ID of the organization or person, e.g. the TIN in the US or the CIF/NIF in Spain.
  132.      *
  133.      * @see https://schema.org/taxID
  134.      */
  135.     #[ORM\Column(type'string')]
  136.     #[ApiProperty(iri'https://schema.org/taxID')]
  137.     #[Assert\Type('string')]
  138.     #[Groups([
  139.         'import:insurer',
  140.         'insurer:collection:get',
  141.         'insurer:collection:post',
  142.         'insurer:item:get',
  143.         'insurer:item:put',
  144.         'demand:item:get',
  145.         'policy:collection:get',
  146.         'user:item:get',
  147.     ])]
  148.     private ?string $taxID null;
  149.     /**
  150.      * A description of the item.
  151.      *
  152.      * @see https://schema.org/description
  153.      */
  154.     #[ORM\Column(type'text'nullabletrue)]
  155.     #[ApiProperty(iri'https://schema.org/description')]
  156.     #[Assert\Type('string')]
  157.     #[Groups([
  158.         'import:insurer',
  159.         'insurer:collection:post',
  160.         'insurer:item:get',
  161.         'insurer:item:put',
  162.     ])]
  163.     private ?string $description null;
  164.     // #[ORM\ManyToMany(targetEntity: Policy::class, mappedBy: 'insurers')]
  165.     // private $policies;
  166.     #[ORM\OneToMany(mappedBy'insurer'targetEntityPolicyInsurer::class, cascade: ["persist""remove"], orphanRemovaltrue)]
  167.     private $policies;
  168.     #[ORM\ManyToMany(targetEntityDemand::class, mappedBy'insurers')]
  169.     #[MaxDepth(1)]
  170.     private $demands;
  171.     #[ORM\OneToMany(mappedBy'insurer'targetEntityInsuredInsurer::class, cascade: ["persist""remove"], orphanRemovaltrue)]
  172.     // #[Groups([
  173.     //     'import:insurer'
  174.     // ])]
  175.     // #[MaxDepth(1)]
  176.     private $insureds;
  177.     #[ORM\OneToMany(mappedBy'insurer'targetEntityInsuredInsurerGlobal::class, cascade: ["persist""remove"], orphanRemovaltrue)]
  178.     // #[Groups([
  179.     //     'import:insurer'
  180.     // ])]
  181.     #[MaxDepth(1)]
  182.     private $insuredGlobals;
  183.     #[ORM\OneToMany(mappedBy'insurer'targetEntityInsurerUser::class, cascade: ["persist""remove"], orphanRemovaltrue)]
  184.     #[Groups([
  185.         'import:insurer',
  186.         'insurer:item:get'
  187.     ])]
  188.     #[MaxDepth(1)]
  189.     private $users;
  190.     #[ORM\OneToMany(mappedBy'insurer'targetEntityInsurerSubmodality::class, cascade: ["persist""remove"], orphanRemovaltrue)]
  191.     #[Groups([
  192.         'import:insurer',
  193.         'insurer:item:get',
  194.         'insurer:item:put',
  195.     ])]
  196.     #[MaxDepth(1)]
  197.     private $submodalities;
  198.     #[ORM\OneToMany(mappedBy'insurer'targetEntityInsurerModality::class, cascade: ["persist""remove"], orphanRemovaltrue)]
  199.     #[Groups([
  200.         'import:insurer',
  201.         'insurer:item:get',
  202.         'insurer:item:put',
  203.     ])]
  204.     #[MaxDepth(1)]
  205.     private $modalities;
  206.     #[ApiProperty()]
  207.     #[Groups([
  208.         'import:demand',
  209.     ])]
  210.     private $insurerTaxID;
  211.     #[ORM\Column(type'float'nullabletrue)]
  212.     #[Groups([
  213.         'import:insurer',
  214.         'insurer:collection:get',
  215.         'insurer:collection:post',
  216.         'insurer:item:get',
  217.         'insurer:item:put',
  218.     ])]
  219.     private ?float $defaultLimitValue null;
  220.     #[ORM\Column(type'float'nullabletrue)]
  221.     #[ApiProperty(iri'https://schema.org/Number')]
  222.     #[Groups([
  223.         'import:insurer',
  224.         'insurer:collection:get',
  225.         'insurer:collection:post',
  226.         'insurer:item:get',
  227.         'insurer:item:put',
  228.     ])]
  229.     private ?float $defaultComissionRate null;
  230.     #[ORM\Column(type'float'nullabletrue)]
  231.     #[ApiProperty(iri'https://schema.org/Number')]
  232.     #[Groups([
  233.         'import:insurer',
  234.         'insurer:collection:get',
  235.         'insurer:collection:post',
  236.         'insurer:item:get',
  237.         'insurer:item:put',
  238.     ])]
  239.     private ?float $defaultApprovedValue null;
  240.     #[ORM\Column(type'datetime'nullabletrue)]
  241.     #[Groups([
  242.         'import:insurer',
  243.         'insurer:collection:get',
  244.         'insurer:collection:post',
  245.         'insurer:item:get',
  246.         'insurer:item:put',
  247.     ])]
  248.     private $defaultEndTime;
  249.     public function __construct()
  250.     {
  251.         $this->policies = new ArrayCollection();
  252.         $this->demands = new ArrayCollection();
  253.         $this->insureds = new ArrayCollection();
  254.         $this->insuredGlobals = new ArrayCollection();
  255.         $this->users = new ArrayCollection();
  256.         $this->submodalities = new ArrayCollection();
  257.         $this->modalities = new ArrayCollection();
  258.     }
  259.     public function getId(): ?int
  260.     {
  261.         return $this->id;
  262.     }
  263.     public function setName(?string $name): void
  264.     {
  265.         $this->name $name;
  266.     }
  267.     public function getName(): ?string
  268.     {
  269.         return $this->name;
  270.     }
  271.     public function setLegalName(?string $legalName): void
  272.     {
  273.         $this->legalName $legalName;
  274.     }
  275.     public function getLegalName(): ?string
  276.     {
  277.         return $this->legalName;
  278.     }
  279.     public function setTaxID(?string $taxID): void
  280.     {
  281.         $this->taxID $taxID;
  282.     }
  283.     public function getTaxID(): ?string
  284.     {
  285.         return $this->taxID;
  286.     }
  287.     public function setDescription(?string $description): void
  288.     {
  289.         $this->description $description;
  290.     }
  291.     public function getDescription(): ?string
  292.     {
  293.         return $this->description;
  294.     }
  295.     /**
  296.      * @return Collection|PolicyInsurer[]
  297.      */
  298.     public function getPolicies(): Collection
  299.     {
  300.         return $this->policies;
  301.     }
  302.     public function addPolicy(PolicyInsurer $policy): self
  303.     {
  304.         if (!$this->policies->contains($policy)) {
  305.             $this->policies[] = $policy;
  306.             $policy->setInsurer($this);
  307.         }
  308.         return $this;
  309.     }
  310.     public function removePolicy(PolicyInsurer $policy): self
  311.     {
  312.         if ($this->policies->removeElement($policy)) {
  313.             $policy->setInsurer(null);
  314.         }
  315.         return $this;
  316.     }
  317.     /**
  318.      * @return Collection|Demand[]
  319.      */
  320.     public function getDemands(): Collection
  321.     {
  322.         return $this->demands;
  323.     }
  324.     public function addDemand(Demand $demand): self
  325.     {
  326.         if (!$this->demands->contains($demand)) {
  327.             $this->demands[] = $demand;
  328.             $demand->addInsurer($this);
  329.         }
  330.         return $this;
  331.     }
  332.     public function removeDemand(Demand $demand): self
  333.     {
  334.         if ($this->demands->removeElement($demand)) {
  335.             $demand->removeInsurer($this);
  336.         }
  337.         return $this;
  338.     }
  339.     /**
  340.      * @return Collection|InsuredInsurer[]
  341.      */
  342.     public function getInsureds(): Collection
  343.     {
  344.         return $this->insureds;
  345.     }
  346.     public function addInsured(InsuredInsurer $insured): self
  347.     {
  348.         if (!$this->insureds->contains($insured)) {
  349.             $this->insureds[] = $insured;
  350.             $insured->setInsurer($this);
  351.         }
  352.         return $this;
  353.     }
  354.     public function removeInsured(InsuredInsurer $insured): self
  355.     {
  356.         if ($this->insureds->removeElement($insured)) {
  357.             // set the owning side to null (unless already changed)
  358.             if ($insured->getInsurer() === $this) {
  359.                 $insured->setInsurer(null);
  360.             }
  361.         }
  362.         return $this;
  363.     }
  364.     /**
  365.      * @return Collection|InsuredInsurerGlobal[]
  366.      */
  367.     public function getInsuredGlobals(): Collection
  368.     {
  369.         return $this->insuredGlobals;
  370.     }
  371.     public function addInsuredGlobal(InsuredInsurerGlobal $insuredGlobal): self
  372.     {
  373.         if (!$this->insuredGlobals->contains($insuredGlobal)) {
  374.             $this->insuredGlobals[] = $insuredGlobal;
  375.             $insuredGlobal->setInsurer($this);
  376.         }
  377.         return $this;
  378.     }
  379.     public function removeInsuredGlobal(InsuredInsurerGlobal $insuredGlobal): self
  380.     {
  381.         if ($this->insuredGlobals->removeElement($insuredGlobal)) {
  382.             // set the owning side to null (unless already changed)
  383.             if ($insuredGlobal->getInsurer() === $this) {
  384.                 $insuredGlobal->setInsurer(null);
  385.             }
  386.         }
  387.         return $this;
  388.     }
  389.     /**
  390.      * @return Collection|InsurerUser[]
  391.      */
  392.     public function getUsers(): Collection
  393.     {
  394.         return $this->users;
  395.     }
  396.     public function addUser(InsurerUser $user): self
  397.     {
  398.         if (!$this->users->contains($user)) {
  399.             $this->users[] = $user;
  400.             $user->setInsurer($this);
  401.         }
  402.         return $this;
  403.     }
  404.     public function removeUser(InsurerUser $user): self
  405.     {
  406.         if ($this->users->removeElement($user)) {
  407.             // set the owning side to null (unless already changed)
  408.             if ($user->getInsurer() === $this) {
  409.                 $user->setInsurer(null);
  410.             }
  411.         }
  412.         return $this;
  413.     }
  414.     /**
  415.      * @return Collection|InsurerSubmodality[]
  416.      */
  417.     public function getSubmodalities(): Collection
  418.     {
  419.         return $this->submodalities;
  420.     }
  421.     public function addSubmodality(InsurerSubmodality $submodality): self
  422.     {
  423.         if (!$this->submodalities->contains($submodality)) {
  424.             $this->submodalities[] = $submodality;
  425.             $submodality->setInsurer($this);
  426.         }
  427.         return $this;
  428.     }
  429.     public function removeSubmodality(InsurerSubmodality $submodality): self
  430.     {
  431.         if ($this->submodalities->removeElement($submodality)) {
  432.             // set the owning side to null (unless already changed)
  433.             if ($submodality->getInsurer() === $this) {
  434.                 $submodality->setInsurer(null);
  435.             }
  436.         }
  437.         return $this;
  438.     }
  439.     /**
  440.      * @return Collection|InsurerModality[]
  441.      */
  442.     public function getModalities(): Collection
  443.     {
  444.         return $this->modalities;
  445.     }
  446.     public function addModality(InsurerModality $modality): self
  447.     {
  448.         if (!$this->modalities->contains($modality)) {
  449.             $this->modalities[] = $modality;
  450.             $modality->setInsurer($this);
  451.         }
  452.         return $this;
  453.     }
  454.     public function removeModality(InsurerModality $modality): self
  455.     {
  456.         if ($this->modalities->removeElement($modality)) {
  457.             // set the owning side to null (unless already changed)
  458.             if ($modality->getInsurer() === $this) {
  459.                 $modality->setInsurer(null);
  460.             }
  461.         }
  462.         return $this;
  463.     }
  464.     public function getInsurerTaxID(): ?string
  465.     {
  466.         return $this->getTaxID();
  467.     }
  468.     public function getDefaultLimitValue(): ?float
  469.     {
  470.         return $this->defaultLimitValue;
  471.     }
  472.     public function setDefaultLimitValue(?float $defaultLimitValue): self
  473.     {
  474.         $this->defaultLimitValue $defaultLimitValue;
  475.         return $this;
  476.     }
  477.     public function getDefaultComissionRate(): ?float
  478.     {
  479.         return $this->defaultComissionRate;
  480.     }
  481.     public function setDefaultComissionRate(?float $defaultComissionRate): self
  482.     {
  483.         $this->defaultComissionRate $defaultComissionRate;
  484.         return $this;
  485.     }
  486.     public function getDefaultApprovedValue(): ?float
  487.     {
  488.         return $this->defaultApprovedValue;
  489.     }
  490.     public function setDefaultApprovedValue(?float $defaultApprovedValue): self
  491.     {
  492.         $this->defaultApprovedValue $defaultApprovedValue;
  493.         return $this;
  494.     }
  495.     public function getDefaultEndTime(): ?\DateTimeInterface
  496.     {
  497.         return $this->defaultEndTime;
  498.     }
  499.     public function setDefaultEndTime(?\DateTimeInterface $defaultEndTime): self
  500.     {
  501.         $this->defaultEndTime $defaultEndTime;
  502.         return $this;
  503.     }
  504. }