src/Entity/City.php line 11
<?php
namespace App\Entity;
use App\Repository\CityRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: CityRepository::class)]
class City
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $country = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $city = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $postalCode = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $district = null;
#[ORM\Column(nullable: true)]
private ?int $alertCount = 20;
#[ORM\OneToMany(mappedBy: 'cityEntity', targetEntity: Building::class)]
private Collection $buildings;
#[ORM\OneToMany(mappedBy: 'city', targetEntity: BuildingReportingHistory::class)]
private Collection $buildingReportingHistories;
#[ORM\OneToMany(mappedBy: 'cityEntity', targetEntity: Residence::class)]
private Collection $residences;
#[ORM\Column(nullable: true)]
private ?bool $isInsideHomepage = false;
public function __construct()
{
$this->buildings = new ArrayCollection();
$this->buildingReportingHistories = new ArrayCollection();
$this->residences = new ArrayCollection();
}
public function __toString(): string
{
return $this->city . ' ' . $this->postalCode . ' ' . $this->country . ' ' . $this->district;
}
public function getCityName(): string
{
return $this->city . ' ' . $this->postalCode . ' ' . $this->country . ' ' . $this->district;
}
public function getTotalBuildings(): int
{
return array_reduce($this->buildings->toArray(), function ($total, $building) {
if($building->getStatus() == "Disponible"){
return $total + 1;
}
}, 0);
}
public function getMaxBuildingRent(): int
{
return array_reduce($this->buildings->toArray(), function ($max, $building) {
if($building->getStatus() == "Disponible"){
return $building->getRent() > $max ? $building->getRent() : $max;
}
}, 0);
}
public function getTheMinBuildingRent(): int
{
$min = PHP_INT_MAX;
foreach ($this->buildings as $building) {
if ($building->getStatus() == "Disponible") {
$min = min($min, $building->getRent());
}
}
return $min;
}
public function getId(): ?int
{
return $this->id;
}
public function getCountry(): ?string
{
return $this->country;
}
public function setCountry(?string $country): self
{
$this->country = $country;
return $this;
}
public function getCity(): ?string
{
return $this->city;
}
public function setCity(?string $city): self
{
$this->city = $city;
return $this;
}
public function getPostalCode(): ?string
{
return $this->postalCode;
}
public function setPostalCode(?string $postalCode): self
{
$this->postalCode = $postalCode;
return $this;
}
public function getDistrict(): ?string
{
return $this->district;
}
public function setDistrict(?string $district): self
{
$this->district = $district;
return $this;
}
public function getAlertCount(): ?int
{
return $this->alertCount;
}
public function setAlertCount(?int $alertCount): self
{
$this->alertCount = $alertCount;
return $this;
}
/**
* @return Collection<int, Building>
*/
public function getBuildings(): Collection
{
return $this->buildings;
}
public function addBuilding(Building $building): self
{
if (!$this->buildings->contains($building)) {
$this->buildings->add($building);
$building->setCityEntity($this);
}
return $this;
}
public function removeBuilding(Building $building): self
{
if ($this->buildings->removeElement($building)) {
// set the owning side to null (unless already changed)
if ($building->getCityEntity() === $this) {
$building->setCityEntity(null);
}
}
return $this;
}
/**
* @return Collection<int, BuildingReportingHistory>
*/
public function getBuildingReportingHistories(): Collection
{
return $this->buildingReportingHistories;
}
public function addBuildingReportingHistory(BuildingReportingHistory $buildingReportingHistory): self
{
if (!$this->buildingReportingHistories->contains($buildingReportingHistory)) {
$this->buildingReportingHistories->add($buildingReportingHistory);
$buildingReportingHistory->setCity($this);
}
return $this;
}
public function removeBuildingReportingHistory(BuildingReportingHistory $buildingReportingHistory): self
{
if ($this->buildingReportingHistories->removeElement($buildingReportingHistory)) {
// set the owning side to null (unless already changed)
if ($buildingReportingHistory->getCity() === $this) {
$buildingReportingHistory->setCity(null);
}
}
return $this;
}
/**
* @return Collection<int, Residence>
*/
public function getResidences(): Collection
{
return $this->residences;
}
public function addResidence(Residence $residence): self
{
if (!$this->residences->contains($residence)) {
$this->residences->add($residence);
$residence->setCityEntity($this);
}
return $this;
}
public function removeResidence(Residence $residence): self
{
if ($this->residences->removeElement($residence)) {
// set the owning side to null (unless already changed)
if ($residence->getCityEntity() === $this) {
$residence->setCityEntity(null);
}
}
return $this;
}
public function isIsInsideHomepage(): ?bool
{
return $this->isInsideHomepage;
}
public function setIsInsideHomepage(?bool $isInsideHomepage): self
{
$this->isInsideHomepage = $isInsideHomepage;
return $this;
}
}