ResidenceArea.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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: 'object.getBillingSetting().getOrganization().getId() == user.getOrganization().getId()'
  31. ),
  32. new Delete(
  33. security: 'object.getBillingSetting().getOrganization().getId() == user.getOrganization().getId()'
  34. ),
  35. new GetCollection(
  36. security: 'is_granted(\'ROLE_ORGANIZATION_VIEW\')'
  37. ),
  38. new Post(),
  39. ],
  40. security: 'is_granted(\'ROLE_ORGANIZATION\')'
  41. )]
  42. // #[Auditable]
  43. #[BillingSettingDefaultValue(fieldName: 'billingSetting')]
  44. #[ORM\Entity(repositoryClass: ResidenceAreaRepository::class)]
  45. class ResidenceArea
  46. {
  47. #[ORM\Id]
  48. #[ORM\Column]
  49. #[ORM\GeneratedValue]
  50. private ?int $id = null;
  51. #[ORM\ManyToOne(targetEntity: BillingSetting::class, inversedBy: 'residenceAreas')]
  52. #[ORM\JoinColumn(nullable: false)]
  53. private BillingSetting $billingSetting;
  54. #[ORM\OneToMany(mappedBy: 'residenceArea', targetEntity: AccessBilling::class)]
  55. private Collection $accessBilling;
  56. #[ORM\OneToMany(mappedBy: 'residenceArea', targetEntity: IntangibleDiscountDetail::class)]
  57. private Collection $intangibleDiscountDetails;
  58. #[ORM\Column(length: 255)]
  59. private string $label;
  60. public function __construct()
  61. {
  62. $this->accessBilling = new ArrayCollection();
  63. $this->intangibleDiscountDetails = new ArrayCollection();
  64. }
  65. public function getId(): ?int
  66. {
  67. return $this->id;
  68. }
  69. public function getLabel(): string
  70. {
  71. return $this->label;
  72. }
  73. public function setLabel(string $label): self
  74. {
  75. $this->label = $label;
  76. return $this;
  77. }
  78. public function getBillingSetting(): ?BillingSetting
  79. {
  80. return $this->billingSetting;
  81. }
  82. public function setBillingSetting(?BillingSetting $billingSetting): self
  83. {
  84. $this->billingSetting = $billingSetting;
  85. return $this;
  86. }
  87. /**
  88. * @return Collection<int, AccessBilling>
  89. */
  90. public function getAccessBilling(): Collection
  91. {
  92. return $this->accessBilling;
  93. }
  94. public function addAccessBilling(AccessBilling $accessBilling): self
  95. {
  96. if (!$this->accessBilling->contains($accessBilling)) {
  97. $this->accessBilling[] = $accessBilling;
  98. $accessBilling->setResidenceArea($this);
  99. }
  100. return $this;
  101. }
  102. public function removeAccessBilling(AccessBilling $accessBilling): self
  103. {
  104. if ($this->accessBilling->removeElement($accessBilling)) {
  105. // set the owning side to null (unless already changed)
  106. if ($accessBilling->getResidenceArea() === $this) {
  107. $accessBilling->setResidenceArea(null);
  108. }
  109. }
  110. return $this;
  111. }
  112. /**
  113. * @return Collection<int, IntangibleDiscountDetail>
  114. */
  115. public function getIntangibleDiscountDetails(): Collection
  116. {
  117. return $this->intangibleDiscountDetails;
  118. }
  119. public function addIntangibleDiscountDetail(IntangibleDiscountDetail $intangibleDiscountDetail): self
  120. {
  121. if (!$this->intangibleDiscountDetails->contains($intangibleDiscountDetail)) {
  122. $this->intangibleDiscountDetails[] = $intangibleDiscountDetail;
  123. $intangibleDiscountDetail->setResidenceArea($this);
  124. }
  125. return $this;
  126. }
  127. public function removeIntangibleDiscountDetail(IntangibleDiscountDetail $intangibleDiscountDetail): self
  128. {
  129. if ($this->intangibleDiscountDetails->removeElement($intangibleDiscountDetail)) {
  130. // set the owning side to null (unless already changed)
  131. if ($intangibleDiscountDetail->getResidenceArea() === $this) {
  132. $intangibleDiscountDetail->setResidenceArea(null);
  133. }
  134. }
  135. return $this;
  136. }
  137. }