TypeOfPractice.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Entity\Organization;
  4. use ApiPlatform\Core\Annotation\ApiResource;
  5. use App\Repository\Organization\TypeOfPracticeRepository;
  6. use DH\Auditor\Provider\Doctrine\Auditing\Annotation\Auditable;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Doctrine\Common\Collections\Collection;
  9. use Doctrine\ORM\Mapping as ORM;
  10. use JetBrains\PhpStorm\Pure;
  11. use Symfony\Component\Serializer\Annotation\Groups;
  12. use Symfony\Component\Validator\Constraints as Assert;
  13. /**
  14. * Type des pratique d'une organisation
  15. */
  16. #[Auditable]
  17. #[ApiResource(
  18. collectionOperations: [
  19. 'get' => [
  20. 'normalization_context' => [
  21. 'groups' => ['read']
  22. ]
  23. ]
  24. ],
  25. itemOperations: ['get'],
  26. attributes:[
  27. 'pagination_enabled' => false
  28. ]
  29. )]
  30. #[ORM\Entity(repositoryClass: TypeOfPracticeRepository::class)]
  31. class TypeOfPractice
  32. {
  33. #[ORM\Id]
  34. #[ORM\Column]
  35. #[ORM\GeneratedValue]
  36. #[Groups(["read"])]
  37. private ?int $id = null;
  38. #[ORM\Column(length: 255, nullable: true)]
  39. #[Assert\Choice(callback: ['\App\Enum\Cotisation\TypeOfPracticeEnum', 'toArray'], message: 'invalid-name')]
  40. #[Groups(["read"])]
  41. private ?string $name = null;
  42. #[ORM\Column(length: 255, nullable: true)]
  43. #[Assert\Choice(callback: ['\App\Enum\Cotisation\CategoryTypeOfPracticeEnum', 'toArray'], message: 'invalid-category')]
  44. #[Groups(["read"])]
  45. private ?string $category = null;
  46. #[ORM\ManyToMany(targetEntity: Organization::class, inversedBy: 'typeOfPractices')]
  47. #[ORM\JoinTable(name: 'organization_type_of_practices')]
  48. #[ORM\JoinColumn(name: 'typeofpractice_id', referencedColumnName: 'id')]
  49. #[ORM\InverseJoinColumn(name: 'organization_id', referencedColumnName: 'id')]
  50. private Collection $organizations;
  51. #[Pure] public function __construct()
  52. {
  53. $this->organizations = new ArrayCollection();
  54. }
  55. public function getId(): ?int
  56. {
  57. return $this->id;
  58. }
  59. public function getName(): ?string
  60. {
  61. return $this->name;
  62. }
  63. public function setName(?string $name): self
  64. {
  65. $this->name = $name;
  66. return $this;
  67. }
  68. public function getCategory(): ?string
  69. {
  70. return $this->category;
  71. }
  72. public function setCategory(?string $category): self
  73. {
  74. $this->category = $category;
  75. return $this;
  76. }
  77. public function getOrganizations(): Collection
  78. {
  79. return $this->organizations;
  80. }
  81. public function addOrganization(Organization $organization): self
  82. {
  83. if (!$this->organizations->contains($organization)) {
  84. $this->organizations[] = $organization;
  85. $organization->addTypeOfPractice($this);
  86. }
  87. return $this;
  88. }
  89. public function removeOrganization(Organization $organization): self
  90. {
  91. if ($this->organizations->removeElement($organization)) {
  92. $organization->removeTypeOfPractice($this);
  93. }
  94. return $this;
  95. }
  96. }