src/Entity/Ville.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\VilleRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. /**
  8. * @ORM\Entity(repositoryClass=VilleRepository::class)
  9. */
  10. class Ville
  11. {
  12. /**
  13. * @ORM\Id
  14. * @ORM\GeneratedValue
  15. * @ORM\Column(type="integer")
  16. */
  17. private $id;
  18. /**
  19. * @ORM\Column(type="string", length=255)
  20. */
  21. private $nom;
  22. /**
  23. * @ORM\ManyToOne(targetEntity=Province::class, inversedBy="villes")
  24. * @ORM\JoinColumn(nullable=false)
  25. */
  26. private $province;
  27. /**
  28. * @ORM\OneToMany(targetEntity=Commune::class, mappedBy="ville", orphanRemoval=true)
  29. */
  30. private $communes;
  31. /**
  32. * @ORM\OneToOne(targetEntity=Federation::class, mappedBy="ville", cascade={"persist", "remove"})
  33. */
  34. private $federation;
  35. public function __construct()
  36. {
  37. $this->communes = new ArrayCollection();
  38. }
  39. public function getId(): ?int
  40. {
  41. return $this->id;
  42. }
  43. public function getNom(): ?string
  44. {
  45. return $this->nom;
  46. }
  47. public function setNom(string $nom): self
  48. {
  49. $this->nom = $nom;
  50. return $this;
  51. }
  52. public function getProvince(): ?Province
  53. {
  54. return $this->province;
  55. }
  56. public function setProvince(?Province $province): self
  57. {
  58. $this->province = $province;
  59. return $this;
  60. }
  61. /**
  62. * @return Collection<int, Commune>
  63. */
  64. public function getCommunes(): Collection
  65. {
  66. return $this->communes;
  67. }
  68. public function addCommune(Commune $commune): self
  69. {
  70. if (!$this->communes->contains($commune)) {
  71. $this->communes[] = $commune;
  72. $commune->setVille($this);
  73. }
  74. return $this;
  75. }
  76. public function removeCommune(Commune $commune): self
  77. {
  78. if ($this->communes->removeElement($commune)) {
  79. // set the owning side to null (unless already changed)
  80. if ($commune->getVille() === $this) {
  81. $commune->setVille(null);
  82. }
  83. }
  84. return $this;
  85. }
  86. public function getFederation(): ?Federation
  87. {
  88. return $this->federation;
  89. }
  90. public function setFederation(?Federation $federation): self
  91. {
  92. // unset the owning side of the relation if necessary
  93. if ($federation === null && $this->federation !== null) {
  94. $this->federation->setVille(null);
  95. }
  96. // set the owning side of the relation if necessary
  97. if ($federation !== null && $federation->getVille() !== $this) {
  98. $federation->setVille($this);
  99. }
  100. $this->federation = $federation;
  101. return $this;
  102. }
  103. }