<?php
namespace App\Entity;
use App\Repository\VilleRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=VilleRepository::class)
*/
class Ville
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $nom;
/**
* @ORM\ManyToOne(targetEntity=Province::class, inversedBy="villes")
* @ORM\JoinColumn(nullable=false)
*/
private $province;
/**
* @ORM\OneToMany(targetEntity=Commune::class, mappedBy="ville", orphanRemoval=true)
*/
private $communes;
/**
* @ORM\OneToOne(targetEntity=Federation::class, mappedBy="ville", cascade={"persist", "remove"})
*/
private $federation;
public function __construct()
{
$this->communes = 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;
}
public function getProvince(): ?Province
{
return $this->province;
}
public function setProvince(?Province $province): self
{
$this->province = $province;
return $this;
}
/**
* @return Collection<int, Commune>
*/
public function getCommunes(): Collection
{
return $this->communes;
}
public function addCommune(Commune $commune): self
{
if (!$this->communes->contains($commune)) {
$this->communes[] = $commune;
$commune->setVille($this);
}
return $this;
}
public function removeCommune(Commune $commune): self
{
if ($this->communes->removeElement($commune)) {
// set the owning side to null (unless already changed)
if ($commune->getVille() === $this) {
$commune->setVille(null);
}
}
return $this;
}
public function getFederation(): ?Federation
{
return $this->federation;
}
public function setFederation(?Federation $federation): self
{
// unset the owning side of the relation if necessary
if ($federation === null && $this->federation !== null) {
$this->federation->setVille(null);
}
// set the owning side of the relation if necessary
if ($federation !== null && $federation->getVille() !== $this) {
$federation->setVille($this);
}
$this->federation = $federation;
return $this;
}
}