src/Entity/InsurerSubmodality.php line 68

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\Validator\Constraints as Assert;
  10. use Symfony\Component\Serializer\Annotation\Groups;
  11. use Symfony\Component\Serializer\Annotation\MaxDepth;
  12. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  13. #[ORM\Entity]
  14. #[UniqueEntity(fields: ['insurer''submodality'])]
  15. #[ApiResource(
  16.     iri'InsurerSubmodality',
  17.     itemOperations: [
  18.         'get' => [
  19.             // 'security' => "is_granted('ROLE_USER')",
  20.             'normalization_context' => [
  21.                 'groups' => 'insurer_submodality:item:get',
  22.                 'enable_max_depth' => true
  23.             ]
  24.         ],
  25.         'put' => [
  26.             // 'security' => "is_granted('ROLE_USER')",
  27.             'normalization_context' => [
  28.                 'groups' => 'insurer_submodality:item:put',
  29.                 'enable_max_depth' => true
  30.             ],
  31.             'denormalization_context' => [
  32.                 'groups' => 'insurer_submodality:item:put',
  33.                 'enable_max_depth' => true
  34.             ]
  35.         ],
  36.         'delete' => [
  37.             // 'security' => "is_granted('ROLE_USER')",
  38.         ]
  39.     ],
  40.     collectionOperations: [
  41.         'get' => [
  42.             // 'security' => "is_granted('ROLE_USER')",
  43.             'normalization_context' => [
  44.                 'groups' => ['insurer_submodality:collection:get''createdAt'],
  45.                 'enable_max_depth' => true
  46.             ]
  47.         ],
  48.         'post' => [
  49.             // 'security' => "is_granted('ROLE_USER')",
  50.             'normalization_context' => [
  51.                 'groups' => 'insurer_submodality:collection:post',
  52.                 'enable_max_depth' => true
  53.             ],
  54.             'denormalization_context' => [
  55.                 'groups' => 'insurer_submodality:collection:post',
  56.                 'enable_max_depth' => true
  57.             ]
  58.         ],
  59.     ]
  60. )]
  61. #[ApiFilter(SearchFilter::class, properties: [
  62.     'submodality' => 'exact',
  63.     'insurer' => 'exact'
  64. ])]
  65. class InsurerSubmodality
  66. {
  67.     use TimestampableEntity;
  68.     
  69.     #[ORM\Id]
  70.     #[ORM\GeneratedValue]
  71.     #[ORM\Column(type'integer')]
  72.     #[Groups([
  73.         'insurer_submodality:collection:get',
  74.         'insurer_submodality:item:get',
  75.     ])]
  76.     private $id;
  77.     #[ORM\Column(type'string'length255nullabletrue)]
  78.     #[Groups([
  79.         'insurer_submodality:collection:get',
  80.         'insurer_submodality:item:get',
  81.         'insurer:item:get',
  82.     ])]
  83.     private $name;
  84.     #[ORM\ManyToOne(targetEntityInsurer::class, inversedBy'submodalities')]
  85.     #[Groups([
  86.         'insurer_submodality:collection:get',
  87.         'insurer_submodality:collection:post',
  88.         'insurer_submodality:item:get',
  89.         'insurer_submodality:item:put',
  90.     ])]
  91.     #[MaxDepth(1)]
  92.     private $insurer;
  93.     #[ORM\ManyToOne(targetEntitySubmodality::class, inversedBy'insurers')]
  94.     #[Groups([
  95.         'insurer_submodality:collection:get',
  96.         'insurer_submodality:collection:post',
  97.         'insurer_submodality:item:get',
  98.         'insurer_submodality:item:put',
  99.         'insurer:item:get',
  100.     ])]
  101.     #[MaxDepth(1)]
  102.     private $submodality;
  103.     #[ORM\Column(type'boolean')]
  104.     #[Assert\Type('boolean')]
  105.     #[Groups([
  106.         'import:insurer',
  107.         'insurer_submodality:collection:get',
  108.         'insurer_submodality:collection:post',
  109.         'insurer_submodality:item:get',
  110.         'insurer_submodality:item:put',
  111.         'insurer:item:get',
  112.         'insurer:item:put',
  113.     ])]
  114.     private bool $isSelected false;
  115.     #[ApiProperty()]
  116.     #[Groups([
  117.         'insurer_submodality:collection:get',
  118.         'insurer:item:get',
  119.     ])]
  120.     private $modality;
  121.     
  122.     #[ApiProperty()]
  123.     #[Groups([
  124.         'import:insurer',
  125.         'insurer_submodality:collection:get',
  126.         'insurer:item:get',
  127.     ])]
  128.     private $modalityName;
  129.     
  130.     #[ApiProperty()]
  131.     #[Groups([
  132.         'import:insurer',
  133.         'insurer_submodality:collection:get',
  134.         'insurer:item:get',
  135.     ])]
  136.     private $submodalityName;
  137.     public function getId(): ?int
  138.     {
  139.         return $this->id;
  140.     }
  141.     public function setName(): void
  142.     {
  143.         $this->name "{$this->getModalityName()} / {$this->getSubmodalityName()}";
  144.     }
  145.     public function getName(): ?string
  146.     {
  147.         return $this->name;
  148.     }
  149.     public function getInsurer(): ?Insurer
  150.     {
  151.         return $this->insurer;
  152.     }
  153.     public function setInsurer(?Insurer $insurer): self
  154.     {
  155.         $this->insurer $insurer;
  156.         return $this;
  157.     }
  158.     public function getSubmodality(): ?Submodality
  159.     {
  160.         return $this->submodality;
  161.     }
  162.     public function setSubmodality(?Submodality $submodality): self
  163.     {
  164.         $this->submodality $submodality;
  165.         return $this;
  166.     }
  167.     public function setIsSelected($isSelected): self
  168.     {
  169.         $this->isSelected $isSelected;
  170.         return $this;
  171.     }
  172.     public function getIsSelected(): ?bool
  173.     {
  174.         return $this->isSelected;
  175.     }
  176.     public function getModality(): ?Modality
  177.     {
  178.         return $this->getSubmodality()?->getModality();
  179.     }
  180.     public function getModalityName(): ?string
  181.     {
  182.         return $this->getModality()?->getName();
  183.     }
  184.     
  185.     public function getSubmodalityName(): ?string
  186.     {
  187.         return $this->getSubmodality()?->getName();
  188.     }
  189. }