src/Entity/Province.php line 13

Open in your IDE?
  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. /**
  8. * @ORM\Entity(repositoryClass=ProvinceRepository::class)
  9. */
  10. class Province
  11. {
  12. /**
  13. * @ORM\Id
  14. * @ORM\GeneratedValue
  15. * @ORM\Column(type="integer")
  16. */
  17. private $id;
  18. /**
  19. * @ORM\Column(type="string", length=75, nullable=true)
  20. */
  21. private $nom;
  22. /**
  23. * @ORM\OneToMany(targetEntity=Federation::class, mappedBy="province")
  24. */
  25. private $federations;
  26. /**
  27. * @ORM\Column(type="string", length=155, nullable=true)
  28. */
  29. private $president;
  30. /**
  31. * @ORM\OneToOne(targetEntity=User::class, cascade={"persist", "remove"})
  32. */
  33. private $user;
  34. /**
  35. * @ORM\OneToMany(targetEntity=Ville::class, mappedBy="province", orphanRemoval=true)
  36. */
  37. private $villes;
  38. /**
  39. * @ORM\OneToMany(targetEntity=ForumSujet::class, mappedBy="province")
  40. */
  41. private $forumSujets;
  42. /**
  43. * @ORM\OneToMany(targetEntity=Communique::class, mappedBy="province")
  44. */
  45. private $communiques;
  46. private $membresNombre;
  47. private $membresQuota;
  48. private $couleur;
  49. /**
  50. * @ORM\Column(type="text", nullable=true)
  51. */
  52. private $map;
  53. public function __construct()
  54. {
  55. $this->federations = new ArrayCollection();
  56. $this->villes = new ArrayCollection();
  57. $this->forumSujets = new ArrayCollection();
  58. $this->communiques = new ArrayCollection();
  59. }
  60. public function getId(): ?int
  61. {
  62. return $this->id;
  63. }
  64. public function getNom(): ?string
  65. {
  66. return $this->nom;
  67. }
  68. public function setNom(?string $nom): self
  69. {
  70. $this->nom = $nom;
  71. return $this;
  72. }
  73. /**
  74. * @return Collection<int, Federation>
  75. */
  76. public function getFederations(): Collection
  77. {
  78. return $this->federations;
  79. }
  80. public function addFederation(Federation $federation): self
  81. {
  82. if (!$this->federations->contains($federation)) {
  83. $this->federations[] = $federation;
  84. $federation->setProvince($this);
  85. }
  86. return $this;
  87. }
  88. public function removeFederation(Federation $federation): self
  89. {
  90. if ($this->federations->removeElement($federation)) {
  91. // set the owning side to null (unless already changed)
  92. if ($federation->getProvince() === $this) {
  93. $federation->setProvince(null);
  94. }
  95. }
  96. return $this;
  97. }
  98. public function getPresident(): ?string
  99. {
  100. return $this->president;
  101. }
  102. public function setPresident(?string $president): self
  103. {
  104. $this->president = $president;
  105. return $this;
  106. }
  107. public function getUser(): ?User
  108. {
  109. return $this->user;
  110. }
  111. public function setUser(?User $user): self
  112. {
  113. $this->user = $user;
  114. return $this;
  115. }
  116. /**
  117. * @return Collection<int, Ville>
  118. */
  119. public function getVilles(): Collection
  120. {
  121. return $this->villes;
  122. }
  123. public function addVille(Ville $ville): self
  124. {
  125. if (!$this->villes->contains($ville)) {
  126. $this->villes[] = $ville;
  127. $ville->setProvince($this);
  128. }
  129. return $this;
  130. }
  131. public function removeVille(Ville $ville): self
  132. {
  133. if ($this->villes->removeElement($ville)) {
  134. // set the owning side to null (unless already changed)
  135. if ($ville->getProvince() === $this) {
  136. $ville->setProvince(null);
  137. }
  138. }
  139. return $this;
  140. }
  141. /**
  142. * @return Collection<int, ForumSujet>
  143. */
  144. public function getForumSujets(): Collection
  145. {
  146. return $this->forumSujets;
  147. }
  148. public function addForumSujet(ForumSujet $forumSujet): self
  149. {
  150. if (!$this->forumSujets->contains($forumSujet)) {
  151. $this->forumSujets[] = $forumSujet;
  152. $forumSujet->setProvince($this);
  153. }
  154. return $this;
  155. }
  156. public function removeForumSujet(ForumSujet $forumSujet): self
  157. {
  158. if ($this->forumSujets->removeElement($forumSujet)) {
  159. // set the owning side to null (unless already changed)
  160. if ($forumSujet->getProvince() === $this) {
  161. $forumSujet->setProvince(null);
  162. }
  163. }
  164. return $this;
  165. }
  166. /**
  167. * @return Collection<int, Communique>
  168. */
  169. public function getCommuniques(): Collection
  170. {
  171. return $this->communiques;
  172. }
  173. public function addCommunique(Communique $communique): self
  174. {
  175. if (!$this->communiques->contains($communique)) {
  176. $this->communiques[] = $communique;
  177. $communique->setProvince($this);
  178. }
  179. return $this;
  180. }
  181. public function removeCommunique(Communique $communique): self
  182. {
  183. if ($this->communiques->removeElement($communique)) {
  184. // set the owning side to null (unless already changed)
  185. if ($communique->getProvince() === $this) {
  186. $communique->setProvince(null);
  187. }
  188. }
  189. return $this;
  190. }
  191. public function getMembresNombre(){
  192. $this->setMembresNombre();
  193. return $this->membresNombre;
  194. }
  195. public function getMembresQuota(){
  196. $this->setMembresQuota();
  197. return $this->membresQuota;
  198. }
  199. public function getCouleur(){
  200. $choix = 0;
  201. $choix = rand(1, 3);
  202. return $choix;
  203. }
  204. public function setMembresNombre(){
  205. $totalMembres = 0;
  206. foreach($this->federations as $federation){
  207. $totalMembres += sizeof($federation->getMembres());
  208. }
  209. $this->membresNombre = $totalMembres;
  210. }
  211. public function setMembresQuota(){
  212. $membres = 93;
  213. $totalMembres = 0;
  214. $etat = 0;
  215. foreach($this->federations as $federation){
  216. $totalMembres += sizeof($federation->getMembres());
  217. }
  218. $moyenne = $membres / 26;
  219. $this->membresQuota = $moyenne;
  220. }
  221. public function getMap(): ?string
  222. {
  223. return $this->map;
  224. }
  225. public function setMap(?string $map): self
  226. {
  227. $this->map = $map;
  228. return $this;
  229. }
  230. }