<?php
namespace App\Entity;
use App\Repository\ProvinceRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=ProvinceRepository::class)
*/
class Province
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=75, nullable=true)
*/
private $nom;
/**
* @ORM\OneToMany(targetEntity=Federation::class, mappedBy="province")
*/
private $federations;
/**
* @ORM\Column(type="string", length=155, nullable=true)
*/
private $president;
/**
* @ORM\OneToOne(targetEntity=User::class, cascade={"persist", "remove"})
*/
private $user;
/**
* @ORM\OneToMany(targetEntity=Ville::class, mappedBy="province", orphanRemoval=true)
*/
private $villes;
/**
* @ORM\OneToMany(targetEntity=ForumSujet::class, mappedBy="province")
*/
private $forumSujets;
/**
* @ORM\OneToMany(targetEntity=Communique::class, mappedBy="province")
*/
private $communiques;
private $membresNombre;
private $membresQuota;
private $couleur;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $map;
public function __construct()
{
$this->federations = new ArrayCollection();
$this->villes = new ArrayCollection();
$this->forumSujets = new ArrayCollection();
$this->communiques = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getNom(): ?string
{
return $this->nom;
}
public function setNom(?string $nom): self
{
$this->nom = $nom;
return $this;
}
/**
* @return Collection<int, Federation>
*/
public function getFederations(): Collection
{
return $this->federations;
}
public function addFederation(Federation $federation): self
{
if (!$this->federations->contains($federation)) {
$this->federations[] = $federation;
$federation->setProvince($this);
}
return $this;
}
public function removeFederation(Federation $federation): self
{
if ($this->federations->removeElement($federation)) {
// set the owning side to null (unless already changed)
if ($federation->getProvince() === $this) {
$federation->setProvince(null);
}
}
return $this;
}
public function getPresident(): ?string
{
return $this->president;
}
public function setPresident(?string $president): self
{
$this->president = $president;
return $this;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
/**
* @return Collection<int, Ville>
*/
public function getVilles(): Collection
{
return $this->villes;
}
public function addVille(Ville $ville): self
{
if (!$this->villes->contains($ville)) {
$this->villes[] = $ville;
$ville->setProvince($this);
}
return $this;
}
public function removeVille(Ville $ville): self
{
if ($this->villes->removeElement($ville)) {
// set the owning side to null (unless already changed)
if ($ville->getProvince() === $this) {
$ville->setProvince(null);
}
}
return $this;
}
/**
* @return Collection<int, ForumSujet>
*/
public function getForumSujets(): Collection
{
return $this->forumSujets;
}
public function addForumSujet(ForumSujet $forumSujet): self
{
if (!$this->forumSujets->contains($forumSujet)) {
$this->forumSujets[] = $forumSujet;
$forumSujet->setProvince($this);
}
return $this;
}
public function removeForumSujet(ForumSujet $forumSujet): self
{
if ($this->forumSujets->removeElement($forumSujet)) {
// set the owning side to null (unless already changed)
if ($forumSujet->getProvince() === $this) {
$forumSujet->setProvince(null);
}
}
return $this;
}
/**
* @return Collection<int, Communique>
*/
public function getCommuniques(): Collection
{
return $this->communiques;
}
public function addCommunique(Communique $communique): self
{
if (!$this->communiques->contains($communique)) {
$this->communiques[] = $communique;
$communique->setProvince($this);
}
return $this;
}
public function removeCommunique(Communique $communique): self
{
if ($this->communiques->removeElement($communique)) {
// set the owning side to null (unless already changed)
if ($communique->getProvince() === $this) {
$communique->setProvince(null);
}
}
return $this;
}
public function getMembresNombre(){
$this->setMembresNombre();
return $this->membresNombre;
}
public function getMembresQuota(){
$this->setMembresQuota();
return $this->membresQuota;
}
public function getCouleur(){
$choix = 0;
$choix = rand(1, 3);
return $choix;
}
public function setMembresNombre(){
$totalMembres = 0;
foreach($this->federations as $federation){
$totalMembres += sizeof($federation->getMembres());
}
$this->membresNombre = $totalMembres;
}
public function setMembresQuota(){
$membres = 93;
$totalMembres = 0;
$etat = 0;
foreach($this->federations as $federation){
$totalMembres += sizeof($federation->getMembres());
}
$moyenne = $membres / 26;
$this->membresQuota = $moyenne;
}
public function getMap(): ?string
{
return $this->map;
}
public function setMap(?string $map): self
{
$this->map = $map;
return $this;
}
}