From 3e9cae5270c1f8c520b89421cdddb846c3dadd50 Mon Sep 17 00:00:00 2001 From: Mysaa Date: Wed, 16 Nov 2022 15:24:07 +0100 Subject: [PATCH] Ajout des relations OtM et MtM --- src/Entity/Building.php | 42 +++++++++++++++++++++++++ src/Entity/Corridor.php | 18 +++++++++++ src/Entity/Floor.php | 60 +++++++++++++++++++++++++++++++++++ src/Entity/Place.php | 69 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 189 insertions(+) diff --git a/src/Entity/Building.php b/src/Entity/Building.php index f077ac7..f4f1414 100644 --- a/src/Entity/Building.php +++ b/src/Entity/Building.php @@ -3,6 +3,8 @@ namespace App\Entity; use App\Repository\BuildingRepository; +use Doctrine\Common\Collections\ArrayCollection; +use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; /** @@ -23,6 +25,16 @@ class Building */ private $site; + /** + * @ORM\OneToMany(targetEntity=Floor::class, mappedBy="building") + */ + private $floors; + + public function __construct() + { + $this->floors = new ArrayCollection(); + } + public function getId(): ?int { return $this->id; @@ -39,4 +51,34 @@ class Building return $this; } + + /** + * @return Collection + */ + public function getFloors(): Collection + { + return $this->floors; + } + + public function addFloor(Floor $floor): self + { + if (!$this->floors->contains($floor)) { + $this->floors[] = $floor; + $floor->setBuilding($this); + } + + return $this; + } + + public function removeFloor(Floor $floor): self + { + if ($this->floors->removeElement($floor)) { + // set the owning side to null (unless already changed) + if ($floor->getBuilding() === $this) { + $floor->setBuilding(null); + } + } + + return $this; + } } diff --git a/src/Entity/Corridor.php b/src/Entity/Corridor.php index 55552aa..b3280ee 100644 --- a/src/Entity/Corridor.php +++ b/src/Entity/Corridor.php @@ -17,8 +17,26 @@ class Corridor */ private $id; + /** + * @ORM\ManyToOne(targetEntity=Floor::class, inversedBy="corridors") + * @ORM\JoinColumn(nullable=false) + */ + private $floor; + public function getId(): ?int { return $this->id; } + + public function getFloor(): ?Floor + { + return $this->floor; + } + + public function setFloor(?Floor $floor): self + { + $this->floor = $floor; + + return $this; + } } diff --git a/src/Entity/Floor.php b/src/Entity/Floor.php index 5640667..9c9d646 100644 --- a/src/Entity/Floor.php +++ b/src/Entity/Floor.php @@ -3,6 +3,8 @@ namespace App\Entity; use App\Repository\FloorRepository; +use Doctrine\Common\Collections\ArrayCollection; +use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; /** @@ -17,8 +19,66 @@ class Floor */ private $id; + /** + * @ORM\ManyToOne(targetEntity=Building::class, inversedBy="floors") + * @ORM\JoinColumn(nullable=false) + */ + private $building; + + /** + * @ORM\OneToMany(targetEntity=Corridor::class, mappedBy="floor") + */ + private $corridors; + + public function __construct() + { + $this->corridors = new ArrayCollection(); + } + public function getId(): ?int { return $this->id; } + + public function getBuilding(): ?Building + { + return $this->building; + } + + public function setBuilding(?Building $building): self + { + $this->building = $building; + + return $this; + } + + /** + * @return Collection + */ + public function getCorridors(): Collection + { + return $this->corridors; + } + + public function addCorridor(Corridor $corridor): self + { + if (!$this->corridors->contains($corridor)) { + $this->corridors[] = $corridor; + $corridor->setFloor($this); + } + + return $this; + } + + public function removeCorridor(Corridor $corridor): self + { + if ($this->corridors->removeElement($corridor)) { + // set the owning side to null (unless already changed) + if ($corridor->getFloor() === $this) { + $corridor->setFloor(null); + } + } + + return $this; + } } diff --git a/src/Entity/Place.php b/src/Entity/Place.php index fb2a2df..66e4b1d 100644 --- a/src/Entity/Place.php +++ b/src/Entity/Place.php @@ -3,6 +3,8 @@ namespace App\Entity; use App\Repository\PlaceRepository; +use Doctrine\Common\Collections\ArrayCollection; +use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; /** @@ -17,8 +19,75 @@ class Place */ private $id; + /** + * @ORM\ManyToMany(targetEntity=Place::class, inversedBy="connectedPlaces") + */ + private $connection; + + /** + * @ORM\ManyToMany(targetEntity=Place::class, mappedBy="connection") + */ + private $connectedPlaces; + + public function __construct() + { + $this->connection = new ArrayCollection(); + $this->connectedPlaces = new ArrayCollection(); + } + public function getId(): ?int { return $this->id; } + + /** + * @return Collection + */ + public function getConnection(): Collection + { + return $this->connection; + } + + public function addConnection(self $connection): self + { + if (!$this->connection->contains($connection)) { + $this->connection[] = $connection; + } + + return $this; + } + + public function removeConnection(self $connection): self + { + $this->connection->removeElement($connection); + + return $this; + } + + /** + * @return Collection + */ + public function getConnectedPlaces(): Collection + { + return $this->connectedPlaces; + } + + public function addConnectedPlace(self $connectedPlace): self + { + if (!$this->connectedPlaces->contains($connectedPlace)) { + $this->connectedPlaces[] = $connectedPlace; + $connectedPlace->addConnection($this); + } + + return $this; + } + + public function removeConnectedPlace(self $connectedPlace): self + { + if ($this->connectedPlaces->removeElement($connectedPlace)) { + $connectedPlace->removeConnection($this); + } + + return $this; + } }