mirror of
https://gitlab.aliens-lyon.fr/encartes/backend.git
synced 2026-03-17 22:51:04 +01:00
Ajout des relations OtM et MtM
This commit is contained in:
parent
87c1d313fb
commit
3e9cae5270
@ -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<int, Floor>
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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<int, Corridor>
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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<int, self>
|
||||
*/
|
||||
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<int, self>
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user