src/Entity/Modality.php line 82

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. /**
  17.  * The most generic type of item.
  18.  *
  19.  * @see https://schema.org/Thing
  20.  *
  21.  * @author Jordi Fernandes Alves <jfadev@gmail.com>
  22.  */
  23. #[ORM\Entity]
  24. #[ApiResource(
  25.     iri'Modality',
  26.     itemOperations: [
  27.         'get' => [
  28.             // 'security' => "is_granted('ROLE_USER')",
  29.             'normalization_context' => [
  30.                 'groups' => 'modality:item:get',
  31.                 'enable_max_depth' => true
  32.             ]
  33.         ],
  34.         'put' => [
  35.             // 'security' => "is_granted('ROLE_USER')",
  36.             'normalization_context' => [
  37.                 'groups' => 'modality:item:put',
  38.                 'enable_max_depth' => true
  39.             ],
  40.             'denormalization_context' => [
  41.                 'groups' => 'modality:item:put',
  42.                 'enable_max_depth' => true
  43.             ]
  44.         ],
  45.         'delete' => [
  46.             // 'security' => "is_granted('ROLE_USER')",
  47.         ]
  48.     ],
  49.     collectionOperations: [
  50.         'get' => [
  51.             // 'security' => "is_granted('ROLE_USER')",
  52.             'normalization_context' => [
  53.                 'groups' => ['modality:collection:get''createdAt'],
  54.                 'enable_max_depth' => true
  55.             ]
  56.         ],
  57.         'post' => [
  58.             // 'security' => "is_granted('ROLE_USER')",
  59.             'normalization_context' => [
  60.                 'groups' => 'modality:collection:post',
  61.                 'enable_max_depth' => true
  62.             ],
  63.             'denormalization_context' => [
  64.                 'groups' => 'modality:collection:post',
  65.                 'enable_max_depth' => true
  66.             ]
  67.         ],
  68.     ]
  69. )]
  70. #[ApiFilter(SearchFilter::class, properties: [
  71.     'name' => 'partial',
  72.     'createdAt' => 'start',
  73. ])]
  74. #[ApiFilter(OrderFilter::class, properties: [
  75.     'name',
  76.     'createdAt'
  77. ])]
  78. class Modality
  79. {
  80.     use TimestampableEntity;
  81.     
  82.     #[ORM\Id]
  83.     #[ORM\GeneratedValue(strategy'AUTO')]
  84.     #[ORM\Column(type'integer')]
  85.     #[Groups([
  86.         'import:insurer',
  87.         'modality:collection:get',
  88.         'modality:item:get',
  89.     ])]
  90.     private ?int $id null;
  91.     /**
  92.      * The name of the item.
  93.      *
  94.      * @see https://schema.org/name
  95.      */
  96.     #[ORM\Column(type'string')]
  97.     #[ApiProperty(iri'https://schema.org/name')]
  98.     #[Assert\Type('string')]
  99.     #[Groups([
  100.         'import:insurer',
  101.         'modality:collection:get',
  102.         'modality:collection:post',
  103.         'modality:item:get',
  104.         'modality:item:put',
  105.         'insurer_modality:item:get',
  106.         'demand:item:get',
  107.         'demand:collection:get',
  108.     ])]
  109.     private ?string $name null;
  110.     /**
  111.      * A description of the item.
  112.      *
  113.      * @see https://schema.org/description
  114.      */
  115.     #[ORM\Column(type'text'nullabletrue)]
  116.     #[ApiProperty(iri'https://schema.org/description')]
  117.     #[Assert\Type('string')]
  118.     #[Groups([
  119.         'import:insurer',
  120.         'modality:collection:post',
  121.         'modality:item:get',
  122.         'modality:item:put',
  123.     ])]
  124.     private ?string $description null;
  125.     #[ORM\OneToMany(mappedBy'modality'targetEntitySubmodality::class, cascade: ["persist""remove"], orphanRemovaltrue)]
  126.     #[Groups([
  127.         'modality:item:get',
  128.     ])]
  129.     #[MaxDepth(1)]
  130.     private $submodalities;
  131.     #[ORM\OneToMany(mappedBy'modality'targetEntityInsurerModality::class, cascade: ["remove"], orphanRemovaltrue)]
  132.     private $insurers;
  133.     public function __construct()
  134.     {
  135.         $this->submodalities = new ArrayCollection();
  136.         $this->insurers = new ArrayCollection();
  137.     }
  138.     public function getId(): ?int
  139.     {
  140.         return $this->id;
  141.     }
  142.     public function setName(?string $name): void
  143.     {
  144.         $this->name $name;
  145.     }
  146.     public function getName(): ?string
  147.     {
  148.         return $this->name;
  149.     }
  150.     public function setDescription(?string $description): void
  151.     {
  152.         $this->description $description;
  153.     }
  154.     public function getDescription(): ?string
  155.     {
  156.         return $this->description;
  157.     }
  158.     public function addSubmodality(Submodality $submodality): void
  159.     {
  160.         $this->submodalities[] = $submodality;
  161.     }
  162.     public function removeSubmodality(Submodality $submodality): void
  163.     {
  164.         $this->submodalities->removeElement($submodality);
  165.     }
  166.     public function getSubmodalities(): ?Collection
  167.     {
  168.         return $this->submodalities;
  169.     }
  170.     /**
  171.      * @return Collection|InsurerModality[]
  172.      */
  173.     public function getInsurers(): Collection
  174.     {
  175.         return $this->insurers;
  176.     }
  177.     public function addInsurer(InsurerModality $insurer): self
  178.     {
  179.         if (!$this->insurers->contains($insurer)) {
  180.             $this->insurers[] = $insurer;
  181.             $insurer->setModality($this);
  182.         }
  183.         return $this;
  184.     }
  185.     public function removeInsurer(InsurerModality $insurer): self
  186.     {
  187.         if ($this->insurers->removeElement($insurer)) {
  188.             // set the owning side to null (unless already changed)
  189.             if ($insurer->getModality() === $this) {
  190.                 $insurer->setModality(null);
  191.             }
  192.         }
  193.         return $this;
  194.     }
  195. }