ResidenceArea.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Entity\Billing;
  4. use ApiPlatform\Metadata\ApiResource;
  5. use ApiPlatform\Metadata\Delete;
  6. use ApiPlatform\Metadata\Get;
  7. use ApiPlatform\Metadata\GetCollection;
  8. use ApiPlatform\Metadata\Post;
  9. use ApiPlatform\Metadata\Put;
  10. use App\Attribute\BillingSettingDefaultValue;
  11. use App\Entity\Product\IntangibleDiscountDetail;
  12. use App\Repository\Billing\ResidenceAreaRepository;
  13. use DH\Auditor\Provider\Doctrine\Auditing\Annotation\Auditable;
  14. use Doctrine\Common\Collections\ArrayCollection;
  15. use Doctrine\Common\Collections\Collection;
  16. use Doctrine\ORM\Mapping as ORM;
  17. /**
  18. * Zone de résidence d'un Access, telle que définie par l'Organization.
  19. *
  20. * Security :
  21. *
  22. * @see \App\Doctrine\Billing\CurrentResidenceAreaExtension
  23. */
  24. #[ApiResource(
  25. operations: [
  26. new Get(
  27. security: 'is_granted(\'ROLE_ORGANIZATION_VIEW\') and object.getBillingSetting().getOrganization().getId() == user.getOrganization().getId()'
  28. ),
  29. new Put(
  30. security: 'is_granted(\'ROLE_ORGANIZATION\') and object.getBillingSetting().getOrganization().getId() == user.getOrganization().getId()'
  31. ),
  32. new Delete(
  33. security: 'is_granted(\'ROLE_ORGANIZATION\') and object.getBillingSetting().getOrganization().getId() == user.getOrganization().getId()'
  34. ),
  35. new GetCollection(
  36. security: 'is_granted(\'ROLE_ORGANIZATION\')'
  37. ),
  38. new Post(
  39. security: 'is_granted(\'ROLE_ORGANIZATION\')'
  40. ),
  41. ]
  42. )]
  43. #[Auditable]
  44. #[BillingSettingDefaultValue(fieldName: 'billingSetting')]
  45. #[ORM\Entity(repositoryClass: ResidenceAreaRepository::class)]
  46. class ResidenceArea
  47. {
  48. #[ORM\Id]
  49. #[ORM\Column]
  50. #[ORM\GeneratedValue]
  51. private ?int $id = null;
  52. #[ORM\ManyToOne(targetEntity: BillingSetting::class, inversedBy: 'residenceAreas')]
  53. #[ORM\JoinColumn(nullable: false)]
  54. private BillingSetting $billingSetting;
  55. /** @var Collection<int, AccessBilling> */
  56. #[ORM\OneToMany(targetEntity: AccessBilling::class, mappedBy: 'residenceArea')]
  57. private Collection $accessBilling;
  58. /** @var Collection<int, IntangibleDiscountDetail> */
  59. #[ORM\OneToMany(targetEntity: IntangibleDiscountDetail::class, mappedBy: 'residenceArea')]
  60. private Collection $intangibleDiscountDetails;
  61. #[ORM\Column(length: 255)]
  62. private string $label;
  63. public function __construct()
  64. {
  65. $this->accessBilling = new ArrayCollection();
  66. $this->intangibleDiscountDetails = new ArrayCollection();
  67. }
  68. public function getId(): ?int
  69. {
  70. return $this->id;
  71. }
  72. public function getLabel(): string
  73. {
  74. return $this->label;
  75. }
  76. public function setLabel(string $label): self
  77. {
  78. $this->label = $label;
  79. return $this;
  80. }
  81. public function getBillingSetting(): ?BillingSetting
  82. {
  83. return $this->billingSetting;
  84. }
  85. public function setBillingSetting(?BillingSetting $billingSetting): self
  86. {
  87. $this->billingSetting = $billingSetting;
  88. return $this;
  89. }
  90. /**
  91. * @return Collection<int, AccessBilling>
  92. */
  93. public function getAccessBilling(): Collection
  94. {
  95. return $this->accessBilling;
  96. }
  97. public function addAccessBilling(AccessBilling $accessBilling): self
  98. {
  99. if (!$this->accessBilling->contains($accessBilling)) {
  100. $this->accessBilling[] = $accessBilling;
  101. $accessBilling->setResidenceArea($this);
  102. }
  103. return $this;
  104. }
  105. public function removeAccessBilling(AccessBilling $accessBilling): self
  106. {
  107. if ($this->accessBilling->removeElement($accessBilling)) {
  108. // set the owning side to null (unless already changed)
  109. if ($accessBilling->getResidenceArea() === $this) {
  110. $accessBilling->setResidenceArea(null);
  111. }
  112. }
  113. return $this;
  114. }
  115. /**
  116. * @return Collection<int, IntangibleDiscountDetail>
  117. */
  118. public function getIntangibleDiscountDetails(): Collection
  119. {
  120. return $this->intangibleDiscountDetails;
  121. }
  122. public function addIntangibleDiscountDetail(IntangibleDiscountDetail $intangibleDiscountDetail): self
  123. {
  124. if (!$this->intangibleDiscountDetails->contains($intangibleDiscountDetail)) {
  125. $this->intangibleDiscountDetails[] = $intangibleDiscountDetail;
  126. $intangibleDiscountDetail->setResidenceArea($this);
  127. }
  128. return $this;
  129. }
  130. public function removeIntangibleDiscountDetail(IntangibleDiscountDetail $intangibleDiscountDetail): self
  131. {
  132. if ($this->intangibleDiscountDetails->removeElement($intangibleDiscountDetail)) {
  133. // set the owning side to null (unless already changed)
  134. if ($intangibleDiscountDetail->getResidenceArea() === $this) {
  135. $intangibleDiscountDetail->setResidenceArea(null);
  136. }
  137. }
  138. return $this;
  139. }
  140. }