Modify Connections to be symetric and to be beautiful + add connectedFloors to get_floor

This commit is contained in:
Kouril42
2023-02-21 20:05:01 +01:00
parent 5cc241bdfa
commit 1e67114d82
6 changed files with 102 additions and 37 deletions
+28 -35
View File
@@ -28,8 +28,6 @@ class Place
private $floors;
#[ORM\ManyToMany(targetEntity: Place::class, inversedBy: "connectedPlaces")]
private $connection;
#[ORM\ManyToMany(targetEntity: Place::class, mappedBy: "connection")]
private $connectedPlaces;
#[ORM\OneToMany(targetEntity: ThreeDObjectFile::class, mappedBy: "place")]
@@ -46,7 +44,6 @@ class Place
public function __construct()
{
$this->connection = new ArrayCollection();
$this->connectedPlaces = new ArrayCollection();
$this->names = new ArrayCollection();
$this->users = new ArrayCollection();
@@ -77,12 +74,12 @@ class Place
/**
* @return Collection<int, self>
*/
public function getNames(): Collection
public function getNames(): Collection //of PlaceName
{
return $this->names;
}
public function getJoinedNames(): array
public function getJoinedNames(): array //of sting
{
$names = array();
foreach ($this->names as $plName) {
@@ -160,6 +157,14 @@ class Place
{
return $this->floors;
}
public function getFloorsId(): array
{
$response = array();
foreach ($this->floors as $f) {
$response[] = $f->getId();
}
return $response;
}
public function addFloor(Floor $floor): self
{
@@ -174,27 +179,6 @@ class Place
$this->floors->removeElement($floor);
return $this;
}
/**
* @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>
@@ -204,20 +188,29 @@ class Place
return $this->connectedPlaces;
}
public function addConnectedPlace(self $connectedPlace): self
public function addConnection(self $connection): self
{
if (!$this->connectedPlaces->contains($connectedPlace)) {
$this->connectedPlaces[] = $connectedPlace;
$connectedPlace->addConnection($this);
$this->addConnectedPlace($connection);
$connection->addConnectedPlace($this);
return $this;
}
private function addConnectedPlace(Place $place_to_connect): self
{
if (!$this->connectedPlaces->contains($place_to_connect)) {
$this->connectedPlaces[] = $place_to_connect;
}
return $this;
}
public function removeConnectedPlace(self $connectedPlace): self
public function removeConnection(self $connection): self
{
if ($this->connectedPlaces->removeElement($connectedPlace)) {
$connectedPlace->removeConnection($this);
}
$this->removeConnectedPlace($connection);
$connection->removeConnectedPlace($this);
return $this;
}
private function removeConnectedPlace(Place $place_to_deconnect): self
{
$this->connectedPlaces->removeElement($place_to_deconnect);
return $this;
}