src/Entity/Province.php line 13

  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\ProvinceRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. #[ORM\Entity(repositoryClass: ProvinceRepository::class)]
  8. class Province
  9. {
  10. #[ORM\Id]
  11. #[ORM\GeneratedValue]
  12. #[ORM\Column]
  13. private ?int $id = null;
  14. #[ORM\Column(length: 255)]
  15. private ?string $nom = null;
  16. #[ORM\Column(length: 255, nullable: true)]
  17. private ?string $president = null;
  18. #[ORM\OneToOne(cascade: ['persist', 'remove'])]
  19. private ?User $user = null;
  20. /**
  21. * @var Collection<int, Federation>
  22. */
  23. #[ORM\OneToMany(targetEntity: Federation::class, mappedBy: 'province')]
  24. private Collection $federations;
  25. /**
  26. * @var Collection<int, Commune>
  27. */
  28. #[ORM\OneToMany(targetEntity: Commune::class, mappedBy: 'province')]
  29. private Collection $communes;
  30. /**
  31. * @var Collection<int, Communique>
  32. */
  33. #[ORM\OneToMany(targetEntity: Communique::class, mappedBy: 'province')]
  34. private Collection $communiques;
  35. public function __construct()
  36. {
  37. $this->federations = new ArrayCollection();
  38. $this->communes = new ArrayCollection();
  39. $this->communiques = new ArrayCollection();
  40. }
  41. public function getId(): ?int
  42. {
  43. return $this->id;
  44. }
  45. public function getNom(): ?string
  46. {
  47. return $this->nom;
  48. }
  49. public function setNom(string $nom): static
  50. {
  51. $this->nom = $nom;
  52. return $this;
  53. }
  54. public function getPresident(): ?string
  55. {
  56. return $this->president;
  57. }
  58. public function setPresident(?string $president): static
  59. {
  60. $this->president = $president;
  61. return $this;
  62. }
  63. public function getUser(): ?User
  64. {
  65. return $this->user;
  66. }
  67. public function setUser(?User $user): static
  68. {
  69. $this->user = $user;
  70. return $this;
  71. }
  72. /**
  73. * @return Collection<int, Federation>
  74. */
  75. public function getFederations(): Collection
  76. {
  77. return $this->federations;
  78. }
  79. public function addFederation(Federation $federation): static
  80. {
  81. if (!$this->federations->contains($federation)) {
  82. $this->federations->add($federation);
  83. $federation->setProvince($this);
  84. }
  85. return $this;
  86. }
  87. public function removeFederation(Federation $federation): static
  88. {
  89. if ($this->federations->removeElement($federation)) {
  90. // set the owning side to null (unless already changed)
  91. if ($federation->getProvince() === $this) {
  92. $federation->setProvince(null);
  93. }
  94. }
  95. return $this;
  96. }
  97. /**
  98. * @return Collection<int, Commune>
  99. */
  100. public function getCommunes(): Collection
  101. {
  102. return $this->communes;
  103. }
  104. public function addCommune(Commune $commune): static
  105. {
  106. if (!$this->communes->contains($commune)) {
  107. $this->communes->add($commune);
  108. $commune->setProvince($this);
  109. }
  110. return $this;
  111. }
  112. public function removeCommune(Commune $commune): static
  113. {
  114. if ($this->communes->removeElement($commune)) {
  115. // set the owning side to null (unless already changed)
  116. if ($commune->getProvince() === $this) {
  117. $commune->setProvince(null);
  118. }
  119. }
  120. return $this;
  121. }
  122. public function getNombreMembres(): int{
  123. $totalMembres = 0;
  124. foreach ($this->federations as $federation) {
  125. $totalMembres += $federation->getMembres()->count();
  126. }
  127. return $totalMembres;
  128. }
  129. /**
  130. * @return Collection<int, Communique>
  131. */
  132. public function getCommuniques(): Collection
  133. {
  134. return $this->communiques;
  135. }
  136. public function addCommunique(Communique $communique): static
  137. {
  138. if (!$this->communiques->contains($communique)) {
  139. $this->communiques->add($communique);
  140. $communique->setProvince($this);
  141. }
  142. return $this;
  143. }
  144. public function removeCommunique(Communique $communique): static
  145. {
  146. if ($this->communiques->removeElement($communique)) {
  147. // set the owning side to null (unless already changed)
  148. if ($communique->getProvince() === $this) {
  149. $communique->setProvince(null);
  150. }
  151. }
  152. return $this;
  153. }
  154. }