src/Entity/City.php line 11

  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\CityRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. #[ORM\Entity(repositoryClassCityRepository::class)]
  8. class City
  9. {
  10.     #[ORM\Id]
  11.     #[ORM\GeneratedValue]
  12.     #[ORM\Column]
  13.     private ?int $id null;
  14.     #[ORM\Column(length255nullabletrue)]
  15.     private ?string $country null;
  16.     #[ORM\Column(length255nullabletrue)]
  17.     private ?string $city null;
  18.     #[ORM\Column(length255nullabletrue)]
  19.     private ?string $postalCode null;
  20.     #[ORM\Column(length255nullabletrue)]
  21.     private ?string $district null;
  22.     #[ORM\Column(nullabletrue)]
  23.     private ?int $alertCount 20;
  24.     #[ORM\OneToMany(mappedBy'cityEntity'targetEntityBuilding::class)]
  25.     private Collection $buildings;
  26.     #[ORM\OneToMany(mappedBy'city'targetEntityBuildingReportingHistory::class)]
  27.     private Collection $buildingReportingHistories;
  28.     #[ORM\OneToMany(mappedBy'cityEntity'targetEntityResidence::class)]
  29.     private Collection $residences;
  30.     #[ORM\Column(nullabletrue)]
  31.     private ?bool $isInsideHomepage false;
  32.     public function __construct()
  33.     {
  34.         $this->buildings = new ArrayCollection();
  35.         $this->buildingReportingHistories = new ArrayCollection();
  36.         $this->residences = new ArrayCollection();
  37.     }
  38.     public function __toString(): string
  39.     {
  40.         return $this->city ' ' $this->postalCode ' ' $this->country ' ' $this->district;
  41.     }
  42.     public function getCityName(): string
  43.     {
  44.         return $this->city ' ' $this->postalCode ' ' $this->country ' ' $this->district;
  45.     }
  46.     public function getTotalBuildings(): int
  47.     {
  48.         return array_reduce($this->buildings->toArray(), function ($total$building) {
  49.             if($building->getStatus() == "Disponible"){
  50.                 return $total 1;
  51.             }
  52.         }, 0);
  53.     }
  54.     public function getMaxBuildingRent(): int
  55.     {
  56.         return array_reduce($this->buildings->toArray(), function ($max$building) {
  57.             if($building->getStatus() == "Disponible"){
  58.                 return $building->getRent() > $max $building->getRent() : $max;
  59.             }
  60.         }, 0);
  61.     }
  62.     public function getTheMinBuildingRent(): int
  63.     {
  64.         $min PHP_INT_MAX;
  65.         foreach ($this->buildings as $building) {
  66.             if ($building->getStatus() == "Disponible") {
  67.                 $min min($min$building->getRent());
  68.             }
  69.         }
  70.         return $min;
  71.     }
  72.     public function getId(): ?int
  73.     {
  74.         return $this->id;
  75.     }
  76.     public function getCountry(): ?string
  77.     {
  78.         return $this->country;
  79.     }
  80.     public function setCountry(?string $country): self
  81.     {
  82.         $this->country $country;
  83.         return $this;
  84.     }
  85.     public function getCity(): ?string
  86.     {
  87.         return $this->city;
  88.     }
  89.     public function setCity(?string $city): self
  90.     {
  91.         $this->city $city;
  92.         return $this;
  93.     }
  94.     public function getPostalCode(): ?string
  95.     {
  96.         return $this->postalCode;
  97.     }
  98.     public function setPostalCode(?string $postalCode): self
  99.     {
  100.         $this->postalCode $postalCode;
  101.         return $this;
  102.     }
  103.     public function getDistrict(): ?string
  104.     {
  105.         return $this->district;
  106.     }
  107.     public function setDistrict(?string $district): self
  108.     {
  109.         $this->district $district;
  110.         return $this;
  111.     }
  112.     public function getAlertCount(): ?int
  113.     {
  114.         return $this->alertCount;
  115.     }
  116.     public function setAlertCount(?int $alertCount): self
  117.     {
  118.         $this->alertCount $alertCount;
  119.         return $this;
  120.     }
  121.     /**
  122.      * @return Collection<int, Building>
  123.      */
  124.     public function getBuildings(): Collection
  125.     {
  126.         return $this->buildings;
  127.     }
  128.     public function addBuilding(Building $building): self
  129.     {
  130.         if (!$this->buildings->contains($building)) {
  131.             $this->buildings->add($building);
  132.             $building->setCityEntity($this);
  133.         }
  134.         return $this;
  135.     }
  136.     public function removeBuilding(Building $building): self
  137.     {
  138.         if ($this->buildings->removeElement($building)) {
  139.             // set the owning side to null (unless already changed)
  140.             if ($building->getCityEntity() === $this) {
  141.                 $building->setCityEntity(null);
  142.             }
  143.         }
  144.         return $this;
  145.     }
  146.     /**
  147.      * @return Collection<int, BuildingReportingHistory>
  148.      */
  149.     public function getBuildingReportingHistories(): Collection
  150.     {
  151.         return $this->buildingReportingHistories;
  152.     }
  153.     public function addBuildingReportingHistory(BuildingReportingHistory $buildingReportingHistory): self
  154.     {
  155.         if (!$this->buildingReportingHistories->contains($buildingReportingHistory)) {
  156.             $this->buildingReportingHistories->add($buildingReportingHistory);
  157.             $buildingReportingHistory->setCity($this);
  158.         }
  159.         return $this;
  160.     }
  161.     public function removeBuildingReportingHistory(BuildingReportingHistory $buildingReportingHistory): self
  162.     {
  163.         if ($this->buildingReportingHistories->removeElement($buildingReportingHistory)) {
  164.             // set the owning side to null (unless already changed)
  165.             if ($buildingReportingHistory->getCity() === $this) {
  166.                 $buildingReportingHistory->setCity(null);
  167.             }
  168.         }
  169.         return $this;
  170.     }
  171.     /**
  172.      * @return Collection<int, Residence>
  173.      */
  174.     public function getResidences(): Collection
  175.     {
  176.         return $this->residences;
  177.     }
  178.     public function addResidence(Residence $residence): self
  179.     {
  180.         if (!$this->residences->contains($residence)) {
  181.             $this->residences->add($residence);
  182.             $residence->setCityEntity($this);
  183.         }
  184.         return $this;
  185.     }
  186.     public function removeResidence(Residence $residence): self
  187.     {
  188.         if ($this->residences->removeElement($residence)) {
  189.             // set the owning side to null (unless already changed)
  190.             if ($residence->getCityEntity() === $this) {
  191.                 $residence->setCityEntity(null);
  192.             }
  193.         }
  194.         return $this;
  195.     }
  196.     public function isIsInsideHomepage(): ?bool
  197.     {
  198.         return $this->isInsideHomepage;
  199.     }
  200.     public function setIsInsideHomepage(?bool $isInsideHomepage): self
  201.     {
  202.         $this->isInsideHomepage $isInsideHomepage;
  203.         return $this;
  204.     }
  205. }