src/Entity/PolicyInsurer.php line 65

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiProperty;
  4. use ApiPlatform\Core\Annotation\ApiResource;
  5. use ApiPlatform\Core\Annotation\ApiFilter;
  6. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  7. use App\Trait\TimestampableEntity;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Symfony\Component\Serializer\Annotation\Groups;
  10. use Symfony\Component\Serializer\Annotation\MaxDepth;
  11. #[ORM\Entity]
  12. #[ApiResource(
  13.     iri'PolicyInsurer',
  14.     itemOperations: [
  15.         'get' => [
  16.             // 'security' => "is_granted('ROLE_USER')",
  17.             'normalization_context' => [
  18.                 'groups' => 'policy_insurer:item:get',
  19.                 'enable_max_depth' => true
  20.             ]
  21.         ],
  22.         'put' => [
  23.             // 'security' => "is_granted('ROLE_USER')",
  24.             'normalization_context' => [
  25.                 'groups' => 'policy_insurer:item:put',
  26.                 'enable_max_depth' => true
  27.             ],
  28.             'denormalization_context' => [
  29.                 'groups' => 'policy_insurer:item:put',
  30.                 'enable_max_depth' => true
  31.             ]
  32.         ],
  33.         'delete' => [
  34.             // 'security' => "is_granted('ROLE_USER')",
  35.         ]
  36.     ],
  37.     collectionOperations: [
  38.         'get' => [
  39.             // 'security' => "is_granted('ROLE_USER')",
  40.             'normalization_context' => [
  41.                 'groups' => ['policy_insurer:collection:get''createdAt'],
  42.                 'enable_max_depth' => true
  43.             ]
  44.         ],
  45.         'post' => [
  46.             // 'security' => "is_granted('ROLE_USER')",
  47.             'normalization_context' => [
  48.                 'groups' => 'policy_insurer:collection:post',
  49.                 'enable_max_depth' => true
  50.             ],
  51.             'denormalization_context' => [
  52.                 'groups' => 'policy_insurer:collection:post',
  53.                 'enable_max_depth' => true
  54.             ]
  55.         ],
  56.     ]
  57. )]
  58. #[ApiFilter(SearchFilter::class, properties: [
  59.     'policy' => 'exact',
  60.     'insurer' => 'exact'
  61. ])]
  62. class PolicyInsurer
  63. {
  64.     use TimestampableEntity;
  65.     
  66.     #[ORM\Id]
  67.     #[ORM\GeneratedValue]
  68.     #[ORM\Column(type'integer')]
  69.     #[Groups([
  70.         'policy_insurer:collection:get',
  71.         'policy_insurer:item:get',
  72.         'policy:item:get',
  73.         'policy:collection:post',
  74.         'policy:item:put',
  75.     ])]
  76.     private $id;
  77.     #[ORM\ManyToOne(targetEntityPolicy::class, inversedBy'insurers')]
  78.     #[ORM\JoinColumn(onDelete"CASCADE")]
  79.     #[Groups([
  80.         'policy_insurer:collection:get',
  81.         'policy_insurer:collection:post',
  82.         'policy_insurer:item:get',
  83.         'policy_insurer:item:put',
  84.         'policy:collection:post',
  85.         'policy:item:put',
  86.     ])]
  87.     #[MaxDepth(1)]
  88.     private $policy;
  89.     #[ORM\ManyToOne(targetEntityInsurer::class, inversedBy'policies')]
  90.     #[Groups([
  91.         'policy_insurer:collection:get',
  92.         'policy_insurer:collection:post',
  93.         'policy_insurer:item:get',
  94.         'policy_insurer:item:put',
  95.         'policy:collection:get',
  96.         'policy:collection:post',
  97.         'policy:item:put',
  98.         'policy:item:get',
  99.         'demand:item:get',
  100.     ])]
  101.     private $insurer;
  102.     #[ORM\Column(type'float'nullabletrue)]
  103.     #[Groups([
  104.         'import:policy',
  105.         'policy_insurer:collection:get',
  106.         'policy_insurer:collection:post',
  107.         'policy_insurer:item:get',
  108.         'policy_insurer:item:put',
  109.         'policy:collection:get',
  110.         'policy:collection:post',
  111.         'policy:item:get',
  112.         'policy:item:put',
  113.         'demand:item:get',
  114.     ])]
  115.     private $participationRate;
  116.     #[ApiProperty()]
  117.     #[Groups([
  118.         'policy:item:get',
  119.         'policy_insurer:collection:get',
  120.     ])]
  121.     private $insurerName;
  122.     #[ApiProperty()]
  123.     #[Groups([
  124.         'import:policy',
  125.         'policy:item:get',
  126.         'policy_insurer:collection:get',
  127.     ])]
  128.     private $insurerTaxID;
  129.     // #[ApiProperty()]
  130.     // #[Groups([
  131.     //     'import:policy',
  132.     // ])]
  133.     // private $policyNumber;
  134.     public function getId(): ?int
  135.     {
  136.         return $this->id;
  137.     }
  138.     public function getPolicy(): ?Policy
  139.     {
  140.         return $this->policy;
  141.     }
  142.     public function setPolicy(?Policy $policy): self
  143.     {
  144.         $this->policy $policy;
  145.         return $this;
  146.     }
  147.     public function getInsurer(): ?Insurer
  148.     {
  149.         return $this->insurer;
  150.     }
  151.     public function setInsurer(?Insurer $insurer): self
  152.     {
  153.         $this->insurer $insurer;
  154.         return $this;
  155.     }
  156.     public function getParticipationRate(): ?float
  157.     {
  158.         return $this->participationRate;
  159.     }
  160.     public function setParticipationRate(?float $participationRate): self
  161.     {
  162.         $this->participationRate $participationRate;
  163.         return $this;
  164.     }
  165.     public function getInsurerName(): ?string
  166.     {
  167.         return $this->getInsurer()->getName();
  168.     }
  169.     public function getInsurerTaxID(): ?string
  170.     {
  171.         return $this->getInsurer()->getTaxID();
  172.     }
  173.     // public function getPolicyNumber(): ?string
  174.     // {
  175.     //     return $this->getPolicy()->getPolicyNumber();
  176.     // }
  177. }