src/Entity/Residence.php line 12
<?phpnamespace App\Entity;use App\Repository\ResidenceRepository;use Doctrine\Common\Collections\ArrayCollection;use Doctrine\Common\Collections\Collection;use Doctrine\DBAL\Types\Types;use Doctrine\ORM\Mapping as ORM;#[ORM\Entity(repositoryClass: ResidenceRepository::class)]class Residence{#[ORM\Id]#[ORM\GeneratedValue]#[ORM\Column]private ?int $id = null;#[ORM\ManyToOne(inversedBy: 'residences')]private ?City $cityEntity = null;#[ORM\Column(length: 255)]private ?string $postalCode = null;#[ORM\Column(length: 255, nullable: true)]private ?string $borough = null;#[ORM\Column(length: 255, nullable: true)]private ?string $street = null;#[ORM\Column(length: 255, nullable: true)]private ?string $streetNumber = null;#[ORM\Column(length: 255, nullable: true)]private ?string $country = null;#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]private ?\DateTimeInterface $createdAt = null;#[ORM\ManyToOne(inversedBy: 'residences')]private ?User $administrator = null;#[ORM\Column(length: 255, nullable: true)]private ?string $status = null;#[ORM\Column(length: 255, nullable: true)]private ?string $type = null;#[ORM\Column(length: 255, nullable: true)]private ?string $rentType = null;#[ORM\Column(length: 255, nullable: true)]private ?string $format = null;#[ORM\Column(length: 255, nullable: true)]private ?string $houseRules = null;#[ORM\Column(length: 255, nullable: true)]private ?string $contactName = null;#[ORM\Column(length: 255, nullable: true)]private ?string $mailContact = null;#[ORM\Column(length: 255, nullable: true)]private ?string $phoneContact = null;#[ORM\Column(nullable: true)]private ?int $securityDeposit = null;#[ORM\Column(nullable: true)]private ?int $expenses = null;#[ORM\Column(type: Types::TEXT, nullable: true)]private ?string $expensesDescription = null;#[ORM\Column(nullable: true)]private ?bool $isAidEligible = null;#[ORM\Column(type: Types::TEXT, nullable: true)]private ?string $description = null;#[ORM\OneToMany(mappedBy: 'residence', targetEntity: BuildingEquipment::class, cascade: ['persist', 'remove'])]private Collection $residenceEquipment;#[ORM\OneToMany(mappedBy: 'residence', targetEntity: BuildingDocument::class, cascade: ['persist', 'remove'])]private Collection $buildingDocuments;#[ORM\OneToMany(mappedBy: 'residence', targetEntity: Building::class, cascade: ['persist', 'remove'])]private Collection $buildings;#[ORM\OneToMany(mappedBy: 'residence', targetEntity: BuildingFolder::class)]private Collection $buildingFolders;#[ORM\Column(nullable: true)]private ?bool $isActive = true;#[ORM\Column(nullable: true)]private ?bool $isBlockPossible = false;#[ORM\Column(nullable: true)]private ?string $numberId = null;#[ORM\OneToMany(mappedBy: 'residence', targetEntity: Promotion::class, cascade: ['persist', 'remove'])]private Collection $promotions;#[ORM\ManyToMany(targetEntity: HousingCertificate::class, mappedBy: 'residence')]private Collection $housingCertificates;#[ORM\Column(length: 255, nullable: true)]private ?string $name = null;#[ORM\Column(length: 255, nullable: true)]private ?string $residenceName = null;#[ORM\ManyToOne]private ?City $filteredCity = null;#[ORM\Column(nullable: true)]private ?bool $isAuthorizeAtestation = null;#[ORM\Column]private ?int $rent = null;public function __construct(){$this->residenceEquipment = new ArrayCollection();$this->buildingDocuments = new ArrayCollection();$this->buildings = new ArrayCollection();$this->buildingFolders = new ArrayCollection();$this->createdAt = new \DateTime();$this->promotions = new ArrayCollection();$this->housingCertificates = new ArrayCollection();}public function __toString(): string{return $this->residenceName ?? "";}public function getTotalBuildings(): int{return array_reduce($this->buildings->toArray(), function ($total, $building) {return $total + 1;}, 0);}public function getTotalBuildingsBlocked(): int{return array_reduce($this->buildings->toArray(), function ($total, $building) {if ($building->isIsBlocked()) {return $total + 1;}}, 0);}public function getId(): ?int{return $this->id;}public function getRent(): ?int{return $this->rent;}public function setRent(int $rent): self{$this->rent = $rent;return $this;}public function getCityEntity(): ?City{return $this->cityEntity;}public function setCityEntity(?City $cityEntity): self{$this->cityEntity = $cityEntity;if ($cityEntity) {// dd($cityEntity);// Extraire le nom de la ville à partir de la chaîne complète (ex: "Lille 59000 France")$cityName = $this->extractCityName($cityEntity->getCity());// Mettre à jour le nom de la ville dans l'entité Building//$this->city = $cityName;}return $this;}private function extractCityName(string $fullCityName): string{// Logique pour extraire le nom de la ville// Par exemple, si la chaîne est de la forme "Ville CodePostal Pays", vous pouvez utiliser la fonction explode() pour séparer les parties et récupérer le premier élément.$parts = explode(' ', $fullCityName);$cityName = $parts[0];return $cityName;}public function getPostalCode(): ?string{return $this->postalCode;}public function setPostalCode(string $postalCode): self{$this->postalCode = $postalCode;return $this;}public function getBorough(): ?string{return $this->borough;}public function setBorough(?string $borough): self{$this->borough = $borough;return $this;}public function getStreet(): ?string{return $this->street;}public function setStreet(?string $street): self{$this->street = $street;return $this;}public function getStreetNumber(): ?string{return $this->streetNumber;}public function setStreetNumber(?string $streetNumber): self{$this->streetNumber = $streetNumber;return $this;}public function getCountry(): ?string{return $this->country;}public function setCountry(?string $country): self{$this->country = $country;return $this;}public function getCreatedAt(): ?\DateTimeInterface{return $this->createdAt;}public function setCreatedAt(?\DateTimeInterface $createdAt): self{$this->createdAt = $createdAt;return $this;}public function getAdministrator(): ?User{return $this->administrator;}public function setAdministrator(?User $administrator): self{$this->administrator = $administrator;return $this;}public function getStatus(): ?string{return $this->status;}public function setStatus(?string $status): self{$this->status = $status;return $this;}public function getType(): ?string{return $this->type;}public function setType(?string $type): self{$this->type = $type;return $this;}public function getRentType(): ?string{return $this->rentType;}public function setRentType(?string $rentType): self{$this->rentType = $rentType;return $this;}public function getFormat(): ?string{return $this->format;}public function setFormat(?string $format): self{$this->format = $format;return $this;}public function getHouseRules(): ?string{return $this->houseRules;}public function setHouseRules(?string $houseRules): self{$this->houseRules = $houseRules;return $this;}public function getContactName(): ?string{return $this->contactName;}public function setContactName(?string $contactName): self{$this->contactName = $contactName;return $this;}public function getMailContact(): ?string{return $this->mailContact;}public function setMailContact(?string $mailContact): self{$this->mailContact = $mailContact;return $this;}public function getPhoneContact(): ?string{return $this->phoneContact;}public function setPhoneContact(?string $phoneContact): self{$this->phoneContact = $phoneContact;return $this;}public function getSecurityDeposit(): ?int{return $this->securityDeposit;}public function setSecurityDeposit(?int $securityDeposit): self{$this->securityDeposit = $securityDeposit;return $this;}public function getExpenses(): ?int{return $this->expenses;}public function setExpenses(?int $expenses): self{$this->expenses = $expenses;return $this;}public function getExpensesDescription(): ?string{return $this->expensesDescription;}public function setExpensesDescription(?string $expensesDescription): self{$this->expensesDescription = $expensesDescription;return $this;}public function isIsAidEligible(): ?bool{return $this->isAidEligible;}public function setIsAidEligible(?bool $isAidEligible): self{$this->isAidEligible = $isAidEligible;return $this;}public function getDescription(): ?string{return $this->description;}public function setDescription(?string $description): self{$this->description = $description;return $this;}/*** @return Collection<int, BuildingEquipment>*/public function getResidenceEquipment(): Collection{return $this->residenceEquipment;}public function addResidenceEquipment(BuildingEquipment $residenceEquipment): self{if (!$this->residenceEquipment->contains($residenceEquipment)) {$this->residenceEquipment->add($residenceEquipment);$residenceEquipment->setResidence($this);}return $this;}public function removeResidenceEquipment(BuildingEquipment $residenceEquipment): self{if ($this->residenceEquipment->removeElement($residenceEquipment)) {// set the owning side to null (unless already changed)if ($residenceEquipment->getResidence() === $this) {$residenceEquipment->setResidence(null);}}return $this;}/*** @return Collection<int, BuildingDocument>*/public function getBuildingDocuments(): Collection{return $this->buildingDocuments;}public function addBuildingDocument(BuildingDocument $buildingDocument): self{if (!$this->buildingDocuments->contains($buildingDocument)) {$this->buildingDocuments->add($buildingDocument);$buildingDocument->setResidence($this);}return $this;}public function removeBuildingDocument(BuildingDocument $buildingDocument): self{if ($this->buildingDocuments->removeElement($buildingDocument)) {// set the owning side to null (unless already changed)if ($buildingDocument->getResidence() === $this) {$buildingDocument->setResidence(null);}}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->setResidence($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->getResidence() === $this) {$building->setResidence(null);}}return $this;}/*** @return Collection<int, BuildingFolder>*/public function getBuildingFolders(): Collection{return $this->buildingFolders;}public function addBuildingFolder(BuildingFolder $buildingFolder): self{if (!$this->buildingFolders->contains($buildingFolder)) {$this->buildingFolders->add($buildingFolder);$buildingFolder->setResidence($this);}return $this;}public function removeBuildingFolder(BuildingFolder $buildingFolder): self{if ($this->buildingFolders->removeElement($buildingFolder)) {// set the owning side to null (unless already changed)if ($buildingFolder->getResidence() === $this) {$buildingFolder->setResidence(null);}}return $this;}public function isIsActive(): ?bool{return $this->isActive;}public function setIsActive(?bool $isActive): self{$this->isActive = $isActive;return $this;}public function isIsBlockPossible(): ?bool{return $this->isBlockPossible;}public function setIsBlockPossible(?bool $isBlockPossible): self{$this->isBlockPossible = $isBlockPossible;return $this;}public function getNumberId(): ?string{return $this->numberId;}public function setNumberId(?string $numberId): self{$this->numberId = $numberId;return $this;}/*** @return Collection<int, Promotion>*/public function getPromotions(): Collection{return $this->promotions;}public function addPromotion(Promotion $promotion): self{if (!$this->promotions->contains($promotion)) {$this->promotions->add($promotion);$promotion->setResidence($this);}return $this;}public function removePromotion(Promotion $promotion): self{if ($this->promotions->removeElement($promotion)) {// set the owning side to null (unless already changed)if ($promotion->getResidence() === $this) {$promotion->setResidence(null);}}return $this;}/*** @return Collection<int, HousingCertificate>*/public function getHousingCertificates(): Collection{return $this->housingCertificates;}public function addHousingCertificate(HousingCertificate $housingCertificate): self{if (!$this->housingCertificates->contains($housingCertificate)) {$this->housingCertificates->add($housingCertificate);$housingCertificate->addResidence($this);}return $this;}public function removeHousingCertificate(HousingCertificate $housingCertificate): self{if ($this->housingCertificates->removeElement($housingCertificate)) {$housingCertificate->removeResidence($this);}return $this;}public function getName(): ?string{return $this->name;}public function setName(?string $name): self{$this->name = $name;return $this;}public function getResidenceName(): ?string{return $this->residenceName;}public function setResidenceName(?string $residenceName): self{$this->residenceName = $residenceName;return $this;}public function getFilteredCity(): ?City{return $this->filteredCity;}public function setFilteredCity(?City $filteredCity): self{$this->filteredCity = $filteredCity;return $this;}public function isAuthorizeAtestation(): ?bool{return $this->isAuthorizeAtestation;}public function setIsAuthorizeAtestation(?bool $authorizeAtestation): self{$this->isAuthorizeAtestation =$authorizeAtestation;return $this;}}