Encartes-backend/src/Entity/Building.php
2023-02-14 01:46:32 +01:00

80 lines
1.6 KiB
PHP

<?php
namespace App\Entity;
use App\Repository\BuildingRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: BuildingRepository::class)]
class Building
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: "integer")]
private $id;
#[ORM\Column(type: "string")]
private $name;
#[ORM\ManyToOne(targetEntity: Site::class, inversedBy: "buildings")]
#[ORM\JoinColumn(nullable: false)]
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;
}
public function getSite(): ?Site
{
return $this->site;
}
public function setSite(?Site $site): self
{
$this->site = $site;
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;
}
}