src/Entity/Submodality.php line 76

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'Submodality',
  19.     itemOperations: [
  20.         'get' => [
  21.             // 'security' => "is_granted('ROLE_USER')",
  22.             'normalization_context' => [
  23.                 'groups' => 'submodality:item:get',
  24.                 'enable_max_depth' => true
  25.             ]
  26.         ],
  27.         'put' => [
  28.             // 'security' => "is_granted('ROLE_USER')",
  29.             'normalization_context' => [
  30.                 'groups' => 'submodality:item:put',
  31.                 'enable_max_depth' => true
  32.             ],
  33.             'denormalization_context' => [
  34.                 'groups' => 'submodality: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' => ['submodality:collection:get''createdAt'],
  47.                 'enable_max_depth' => true
  48.             ]
  49.         ],
  50.         'post' => [
  51.             // 'security' => "is_granted('ROLE_USER')",
  52.             'normalization_context' => [
  53.                 'groups' => 'submodality:collection:post',
  54.                 'enable_max_depth' => true
  55.             ],
  56.             'denormalization_context' => [
  57.                 'groups' => 'submodality:collection:post',
  58.                 'enable_max_depth' => true
  59.             ]
  60.         ],
  61.     ]
  62. )]
  63. #[ApiFilter(SearchFilter::class, properties: [
  64.     'modality' => 'exact',
  65.     'name' => 'partial',
  66.     'createdAt' => 'start',
  67. ])]
  68. #[ApiFilter(OrderFilter::class, properties: [
  69.     'name',
  70.     'createdAt'
  71. ])]
  72. class Submodality
  73. {
  74.     use TimestampableEntity;
  75.     
  76.     #[ORM\Id]
  77.     #[ORM\GeneratedValue(strategy'AUTO')]
  78.     #[ORM\Column(type'integer')]
  79.     #[Groups([
  80.         'submodality:collection:get',
  81.         'submodality:item:get',
  82.         'demand:item:put',
  83.     ])]
  84.     private ?int $id null;
  85.     /**
  86.      * The name of the item.
  87.      *
  88.      * @see https://schema.org/name
  89.      */
  90.     #[ORM\Column(type'string')]
  91.     #[ApiProperty(iri'https://schema.org/name')]
  92.     #[Assert\Type('string')]
  93.     #[Groups([
  94.         'import:insurer',
  95.         'submodality:collection:get',
  96.         'submodality:collection:post',
  97.         'submodality:item:get',
  98.         'submodality:item:put',
  99.         'demand:item:get',
  100.         'modality:item:get',
  101.         'demand:collection:get',
  102.     ])]
  103.     private ?string $name null;
  104.     /**
  105.      * A description of the item.
  106.      *
  107.      * @see https://schema.org/description
  108.      */
  109.     #[ORM\Column(type'text'nullabletrue)]
  110.     #[ApiProperty(iri'https://schema.org/description')]
  111.     #[Assert\Type('string')]
  112.     #[Groups([
  113.         'submodality:collection:post',
  114.         'submodality:item:get',
  115.         'submodality:item:put',
  116.     ])]
  117.     private ?string $description null;
  118.     #[ORM\ManyToOne(inversedBy"submodalities"targetEntityModality::class)]
  119.     #[ORM\JoinColumn(nullablefalse)]
  120.     #[Groups([
  121.         'submodality:collection:post',
  122.         'modality:collection:post'
  123.     ])]
  124.     #[MaxDepth(1)]
  125.     private ?Modality $modality null;
  126.     #[ORM\OneToMany(targetEntityInsurerSubmodality::class, mappedBy'submodality'cascade: ["remove"], orphanRemovaltrue)]
  127.     private $insurers;
  128.     #[ORM\OneToMany(targetEntityInsuredInsurer::class, mappedBy'submodality'cascade: ["remove"], orphanRemovaltrue)]
  129.     private $insureds;
  130.     #[ApiProperty()]
  131.     #[Groups([
  132.         'modality:collection:get',
  133.     ])]
  134.     private $modalityName;
  135.     public function __construct()
  136.     {
  137.         $this->insurers = new ArrayCollection();
  138.         $this->insureds = new ArrayCollection();
  139.     }
  140.     public function getId(): ?int
  141.     {
  142.         return $this->id;
  143.     }
  144.     public function setName(?string $name): void
  145.     {
  146.         $this->name $name;
  147.     }
  148.     public function getName(): ?string
  149.     {
  150.         return $this->name;
  151.     }
  152.     public function setDescription(?string $description): void
  153.     {
  154.         $this->description $description;
  155.     }
  156.     public function getDescription(): ?string
  157.     {
  158.         return $this->description;
  159.     }
  160.     public function setModality(?Modality $modality): void
  161.     {
  162.         $this->modality $modality;
  163.     }
  164.     public function getModality(): ?Modality
  165.     {
  166.         return $this->modality;
  167.     }
  168.     /**
  169.      * @return Collection|Insurer[]
  170.      */
  171.     public function getInsurers(): Collection
  172.     {
  173.         return $this->insurers;
  174.     }
  175.     public function addInsurer(InsurerSubmodality $insurer): self
  176.     {
  177.         if (!$this->insurers->contains($insurer)) {
  178.             $this->insurers[] = $insurer;
  179.             $insurer->setSubmodality($this);
  180.         }
  181.         return $this;
  182.     }
  183.     public function removeInsurer(InsurerSubmodality $insurer): self
  184.     {
  185.         if ($this->insurers->removeElement($insurer)) {
  186.             // set the owning side to null (unless already changed)
  187.             if ($insurer->getSubmodality() === $this) {
  188.                 $insurer->setSubmodality(null);
  189.             }
  190.         }
  191.         return $this;
  192.     }
  193.     /**
  194.      * @return Collection|InsuredInsurer[]
  195.      */
  196.     public function getInsureds(): Collection
  197.     {
  198.         return $this->insureds;
  199.     }
  200.     public function getModalityName(): ?string
  201.     {
  202.         return $this->getModality()->getName();
  203.     }
  204.     public function addInsured(InsuredInsurer $insured): self
  205.     {
  206.         if (!$this->insureds->contains($insured)) {
  207.             $this->insureds[] = $insured;
  208.             $insured->setSubmodality($this);
  209.         }
  210.         return $this;
  211.     }
  212.     public function removeInsured(InsuredInsurer $insured): self
  213.     {
  214.         if ($this->insureds->removeElement($insured)) {
  215.             // set the owning side to null (unless already changed)
  216.             if ($insured->getSubmodality() === $this) {
  217.                 $insured->setSubmodality(null);
  218.             }
  219.         }
  220.         return $this;
  221.     }
  222. }