ResidenceArea.php 5.1 KB

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