387 lines
11 KiB
PHP

<?php
namespace App\Entity;
use App\Repository\PlaceRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
enum PlaceType: string {
case Room = 'R';
case Corridor = 'C';
case Stairs = 'S';
case Lift = 'L';
case Toilets = 'T';
}
#[ORM\Entity(repositoryClass: PlaceRepository::class)]
class Place
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: "integer")]
private $id;
#[ORM\Column(type: "string", enumType: PlaceType::class)]
private $type;
#[ORM\OneToMany(targetEntity: PlaceName::class, mappedBy: "place")]
private $names;
#[ORM\OneToMany(targetEntity: RoomUserName::class, mappedBy: "place")]
private $users;
#[ORM\ManyToMany(targetEntity: Floor::class, inversedBy: "places")]
private $floors;
#[ORM\ManyToMany(targetEntity: Place::class, inversedBy: "connectedPlaces")]
private $connectedPlaces;
#[ORM\OneToMany(targetEntity: ThreeDObjectFile::class, mappedBy: "place")]
private $ComplexRepresentation;
#[ORM\OneToMany(targetEntity: Polyhedron::class, mappedBy: "place")]
private $PolyhedronRepresentation;
#[ORM\OneToMany(targetEntity: Cylinder::class, mappedBy: "place")]
private $CylinderRepresentation;
#[ORM\OneToMany(targetEntity: PolySurface::class, mappedBy: "place")]
private $PolySurfaceRepresentation;
#[ORM\OneToMany(targetEntity: Edition::class, mappedBy: "editedPlace")]
private $editions;
public function __construct()
{
$this->connectedPlaces = new ArrayCollection();
$this->names = new ArrayCollection();
$this->users = new ArrayCollection();
$this->floors = new ArrayCollection();
$this->ComplexRepresentation = new ArrayCollection();
$this->PolyhedronRepresentation = new ArrayCollection();
$this->CylinderRepresentation = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getType(): ?PlaceType
{
return $this->type;
}
public function setType(PlaceType $type): bool
{
$this->type = $type;
return true;
}
/**
* @return Collection<int, self>
*/
public function getNames(): Collection //of PlaceName
{
return $this->names;
}
public function getJoinedNames(): array //of sting
{
$names = array();
foreach ($this->names as $plName) {
$names[] = $plName->getName();
}
return $names;
}
public function addName(PlaceName $name): self
{
if (!$this->names->contains($name)) {
$this->names[] = $name;
}
return $this;
}
public function removeName(PlaceName $name): self
{
$this->names->removeElement($name);
return $this;
}
/**
* @return Collection<int, self>
*/
public function getEditions(): Collection
{ return $this->editions;
}
public function addEdition(Edition $edition): self
{ if (!$this->editions->contains($edition)) {
$this->editions[] = $edition;
}
return $this;
}
public function removeEdition(Edition $edition): self
{ $this->editions->removeElement($edition);
return $this;
}
/**
* @return Collection<int, self>
*/
public function getRoomUsers(): Collection
{
return $this->users;
}
public function getJoinedRoomUsersNames(): array
{
$names = new ArrayCollection();
foreach ($this->users as $roomUserName) {
$names[] = $roomUserName->getUserName();
}
return $names->toArray();
}
public function addRoomUser(RoomUserName $user): self
{
if (!$this->users->contains($user)) {
$this->users[] = $user;
}
return $this;
}
public function removeRoomUser(RoomUserName $user): self
{
$this->users->removeElement($user);
return $this;
}
/**
* @return Collection<int, ThreeDObjectFile>
*/
public function getFloors(): Collection
{
return $this->floors;
}
public function getFloorsId(): array
{
$response = array();
foreach ($this->floors as $f) {
$response[] = $f->getId();
}
return $response;
}
public function getFloorsNameAndId(): array
{
$response = array();
foreach ($this->floors as $f) {
$response[] = array('id' => $f->getId(), 'name' => $f->getName());
}
return $response;
}
public function addFloor(Floor $floor): self
{
if (!$this->floors->contains($floor)) {
$this->floors[] = $floor;
}
return $this;
}
public function removeFloor(Floor $floor): self
{
$this->floors->removeElement($floor);
return $this;
}
/**
* @return Collection<int, self>
*/
public function getConnectedPlaces(): Collection
{
return $this->connectedPlaces;
}
public function addConnection(self $connection): self
{
$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 removeConnection(self $connection): self
{
$this->removeConnectedPlace($connection);
$connection->removeConnectedPlace($this);
return $this;
}
private function removeConnectedPlace(Place $place_to_deconnect): self
{
$this->connectedPlaces->removeElement($place_to_deconnect);
return $this;
}
/**
* @return Collection<int, ThreeDObjectFile>
*/
public function getComplexRepresentation(): Collection
{
return $this->ComplexRepresentation;
}
public function addComplexRepresentation(ThreeDObjectFile $complexRepresentation): self
{
if (!$this->ComplexRepresentation->contains($complexRepresentation)) {
$this->ComplexRepresentation[] = $complexRepresentation;
$complexRepresentation->setRoom($this);
}
return $this;
}
public function removeComplexRepresentation(ThreeDObjectFile $complexRepresentation): self
{
if ($this->ComplexRepresentation->removeElement($complexRepresentation)) {
// set the owning side to null (unless already changed)
if ($complexRepresentation->getRoom() === $this) {
$complexRepresentation->setRoom(null);
}
}
return $this;
}
/**
* @return Collection<int, Polyhedron>
*/
public function getPolyhedronRepresentation(): Collection
{
return $this->PolyhedronRepresentation;
}
public function addPolyhedronRepresentation(Polyhedron $polyhedronRepresentation): self
{
if (!$this->PolyhedronRepresentation->contains($polyhedronRepresentation)) {
$this->PolyhedronRepresentation[] = $polyhedronRepresentation;
$polyhedronRepresentation->setRoom($this);
}
return $this;
}
public function removePolyhedronRepresentation(Polyhedron $polyhedronRepresentation): self
{
if ($this->PolyhedronRepresentation->removeElement($polyhedronRepresentation)) {
// set the owning side to null (unless already changed)
if ($polyhedronRepresentation->getRoom() === $this) {
$polyhedronRepresentation->setRoom(null);
}
}
return $this;
}
/**
* @return Collection<int, Cylinder>
*/
public function getCylinderRepresentation(): Collection
{
return $this->CylinderRepresentation;
}
public function addCylinderRepresentation(Cylinder $cylinderRepresentation): self
{
if (!$this->CylinderRepresentation->contains($cylinderRepresentation)) {
$this->CylinderRepresentation[] = $cylinderRepresentation;
$cylinderRepresentation->setPlace($this);
}
return $this;
}
public function removeCylinderRepresentation(Cylinder $cylinderRepresentation): self
{
if ($this->CylinderRepresentation->removeElement($cylinderRepresentation)) {
// set the owning side to null (unless already changed)
if ($cylinderRepresentation->getPlace() === $this) {
$cylinderRepresentation->setPlace(null);
}
}
return $this;
}
/**
* @return Collection<int, PolySurface>
*/
public function getPolySurfaceRepresentation(): Collection
{
return $this->PolySurfaceRepresentation;
}
public function addPolySurfaceRepresentation(PolySurface $polySurfaceRepresentation): self
{
if (!$this->PolySurfaceRepresentation->contains($polySurfaceRepresentation)) {
$this->PolySurfaceRepresentation[] = $polySurfaceRepresentation;
$polySurfaceRepresentation->setPlace($this);
}
return $this;
}
public function removePolySurfaceRepresentation(PolySurface $polySurfaceRepresentation): self
{
if ($this->PolySurfaceRepresentation->removeElement($polySurfaceRepresentation)) {
// set the owning side to null (unless already changed)
if ($polySurfaceRepresentation->getPlace() === $this) {
$polySurfaceRepresentation->setPlace(null);
}
}
return $this;
}
public function getTwoDRepresentation(string $representation, int $alt) : array
{
if ($representation=='Cylinder') {
$rep = $this->getCylinderRepresentation()[0]; //ARBITRARY
if ($rep != null){
$repPoints = $rep->getCylinderbase()->getPolygonpoint(); //Points in repository format
$Points = new ArrayCollection();
foreach ($repPoints as $p) {
$xy=array('x'=>$p->getX(), 'y'=>$p->getY());
if (!$Points->contains($xy)){
$Points[] = $xy;
}
}
return $Points->toArray();
}
}
elseif ($representation=='PolySurface') {
$rep = $this->getPolySurfaceRepresentation()[0]; //ARBITRARY
if ($rep != null){
$repPoints = $rep->getPolysurfaceComponent()->getPolygonpoint(); //Points in repository format
$Points = new ArrayCollection();
foreach ($repPoints as $p) {
$xy=array('x'=>$p->getX(), 'y'=>$p->getY());
if (!$Points->contains($xy)){
$Points[] = $xy;
}
}
return $Points;
}
}
else {
return null;
}
}
}