src/Entity/Residence.php line 12

  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\ResidenceRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\DBAL\Types\Types;
  7. use Doctrine\ORM\Mapping as ORM;
  8. #[ORM\Entity(repositoryClassResidenceRepository::class)]
  9. class Residence
  10. {
  11.     #[ORM\Id]
  12.     #[ORM\GeneratedValue]
  13.     #[ORM\Column]
  14.     private ?int $id null;
  15.     #[ORM\ManyToOne(inversedBy'residences')]
  16.     private ?City $cityEntity null;
  17.     #[ORM\Column(length255)]
  18.     private ?string $postalCode null;
  19.     #[ORM\Column(length255nullabletrue)]
  20.     private ?string $borough null;
  21.     #[ORM\Column(length255nullabletrue)]
  22.     private ?string $street null;
  23.     #[ORM\Column(length255nullabletrue)]
  24.     private ?string $streetNumber null;
  25.     #[ORM\Column(length255nullabletrue)]
  26.     private ?string $country null;
  27.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  28.     private ?\DateTimeInterface $createdAt null;
  29.     #[ORM\ManyToOne(inversedBy'residences')]
  30.     private ?User $administrator null;
  31.     #[ORM\Column(length255nullabletrue)]
  32.     private ?string $status null;
  33.     #[ORM\Column(length255nullabletrue)]
  34.     private ?string $type null;
  35.     #[ORM\Column(length255nullabletrue)]
  36.     private ?string $rentType null;
  37.     #[ORM\Column(length255nullabletrue)]
  38.     private ?string $format null;
  39.     #[ORM\Column(length255nullabletrue)]
  40.     private ?string $houseRules null;
  41.     #[ORM\Column(length255nullabletrue)]
  42.     private ?string $contactName null;
  43.     #[ORM\Column(length255nullabletrue)]
  44.     private ?string $mailContact null;
  45.     #[ORM\Column(length255nullabletrue)]
  46.     private ?string $phoneContact null;
  47.     #[ORM\Column(nullabletrue)]
  48.     private ?int $securityDeposit null;
  49.     #[ORM\Column(nullabletrue)]
  50.     private ?int $expenses null;
  51.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  52.     private ?string $expensesDescription null;
  53.     #[ORM\Column(nullabletrue)]
  54.     private ?bool $isAidEligible null;
  55.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  56.     private ?string $description null;
  57.     #[ORM\OneToMany(mappedBy'residence'targetEntityBuildingEquipment::class, cascade: ['persist''remove'])]
  58.     private Collection $residenceEquipment;
  59.     #[ORM\OneToMany(mappedBy'residence'targetEntityBuildingDocument::class, cascade: ['persist''remove'])]
  60.     private Collection $buildingDocuments;
  61.     #[ORM\OneToMany(mappedBy'residence'targetEntityBuilding::class, cascade: ['persist''remove'])]
  62.     private Collection $buildings;
  63.     #[ORM\OneToMany(mappedBy'residence'targetEntityBuildingFolder::class)]
  64.     private Collection $buildingFolders;
  65.     #[ORM\Column(nullabletrue)]
  66.     private ?bool $isActive false;
  67.     #[ORM\Column(nullabletrue)]
  68.     private ?bool $isBlockPossible false;
  69.     #[ORM\Column(nullabletrue)]
  70.     private ?string $numberId null;
  71.     #[ORM\OneToMany(mappedBy'residence'targetEntityPromotion::class, cascade: ['persist''remove'])]
  72.     private Collection $promotions;
  73.     #[ORM\ManyToMany(targetEntityHousingCertificate::class, mappedBy'residence')]
  74.     private Collection $housingCertificates;
  75.     #[ORM\Column(length255nullabletrue)]
  76.     private ?string $name null;
  77.     #[ORM\Column(length255nullabletrue)]
  78.     private ?string $residenceName null;
  79.     #[ORM\ManyToOne]
  80.     private ?City $filteredCity null;
  81.     #[ORM\Column(nullabletrue)]
  82.     private ?bool $isAuthorizeAtestation null;
  83.     #[ORM\Column]
  84.     private ?int $rent null;
  85.     public function __construct()
  86.     {
  87.         $this->residenceEquipment = new ArrayCollection();
  88.         $this->buildingDocuments = new ArrayCollection();
  89.         $this->buildings = new ArrayCollection();
  90.         $this->buildingFolders = new ArrayCollection();
  91.         $this->createdAt = new \DateTime();
  92.         $this->promotions = new ArrayCollection();
  93.         $this->housingCertificates = new ArrayCollection();
  94.     }
  95.     public function __toString(): string
  96.     {
  97.         return $this->residenceName ?? "";
  98.     }
  99.     public function getTotalBuildings(): int
  100.     {
  101.         return array_reduce($this->buildings->toArray(), function ($total$building) {
  102.             return $total 1;
  103.         }, 0);
  104.     }
  105.     public function getTotalBuildingsBlocked(): int
  106.     {
  107.         return array_reduce($this->buildings->toArray(), function ($total$building) {
  108.             if ($building->isIsBlocked()) {
  109.                 return $total 1;
  110.             }
  111.         }, 0);
  112.     }
  113.     public function getId(): ?int
  114.     {
  115.         return $this->id;
  116.     }
  117.     public function getRent(): ?int
  118.     {
  119.         return $this->rent;
  120.     }
  121.     public function setRent(int $rent): self
  122.     {
  123.         $this->rent $rent;
  124.         return $this;
  125.     }
  126.     
  127.     
  128.     public function getCityEntity(): ?City
  129.     {
  130.         return $this->cityEntity;
  131.     }
  132.     public function setCityEntity(?City $cityEntity): self
  133.     {
  134.         $this->cityEntity $cityEntity;
  135.     
  136.         if ($cityEntity) {
  137.            // dd($cityEntity);
  138.             // Extraire le nom de la ville Ã  partir de la chaîne complète (ex: "Lille 59000 France")
  139.             $cityName $this->extractCityName($cityEntity->getCity());
  140.     
  141.             // Mettre Ã  jour le nom de la ville dans l'entité Building
  142.             //$this->city = $cityName;
  143.         }
  144.     
  145.         return $this;
  146.     }
  147.     
  148.     private function extractCityName(string $fullCityName): string
  149.     {
  150.         // Logique pour extraire le nom de la ville
  151.         // 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.
  152.         $parts explode(' '$fullCityName);
  153.         $cityName $parts[0];
  154.     
  155.         return $cityName;
  156.     }
  157.     public function getPostalCode(): ?string
  158.     {
  159.         return $this->postalCode;
  160.     }
  161.     public function setPostalCode(string $postalCode): self
  162.     {
  163.         $this->postalCode $postalCode;
  164.         return $this;
  165.     }
  166.     public function getBorough(): ?string
  167.     {
  168.         return $this->borough;
  169.     }
  170.     public function setBorough(?string $borough): self
  171.     {
  172.         $this->borough $borough;
  173.         return $this;
  174.     }
  175.     public function getStreet(): ?string
  176.     {
  177.         return $this->street;
  178.     }
  179.     public function setStreet(?string $street): self
  180.     {
  181.         $this->street $street;
  182.         return $this;
  183.     }
  184.     public function getStreetNumber(): ?string
  185.     {
  186.         return $this->streetNumber;
  187.     }
  188.     public function setStreetNumber(?string $streetNumber): self
  189.     {
  190.         $this->streetNumber $streetNumber;
  191.         return $this;
  192.     }
  193.     public function getCountry(): ?string
  194.     {
  195.         return $this->country;
  196.     }
  197.     public function setCountry(?string $country): self
  198.     {
  199.         $this->country $country;
  200.         return $this;
  201.     }
  202.     public function getCreatedAt(): ?\DateTimeInterface
  203.     {
  204.         return $this->createdAt;
  205.     }
  206.     public function setCreatedAt(?\DateTimeInterface $createdAt): self
  207.     {
  208.         $this->createdAt $createdAt;
  209.         return $this;
  210.     }
  211.     public function getAdministrator(): ?User
  212.     {
  213.         return $this->administrator;
  214.     }
  215.     public function setAdministrator(?User $administrator): self
  216.     {
  217.         $this->administrator $administrator;
  218.         return $this;
  219.     }
  220.     public function getStatus(): ?string
  221.     {
  222.         return $this->status;
  223.     }
  224.     public function setStatus(?string $status): self
  225.     {
  226.         $this->status $status;
  227.         return $this;
  228.     }
  229.     public function getType(): ?string
  230.     {
  231.         return $this->type;
  232.     }
  233.     public function setType(?string $type): self
  234.     {
  235.         $this->type $type;
  236.         return $this;
  237.     }
  238.     public function getRentType(): ?string
  239.     {
  240.         return $this->rentType;
  241.     }
  242.     public function setRentType(?string $rentType): self
  243.     {
  244.         $this->rentType $rentType;
  245.         return $this;
  246.     }
  247.     public function getFormat(): ?string
  248.     {
  249.         return $this->format;
  250.     }
  251.     public function setFormat(?string $format): self
  252.     {
  253.         $this->format $format;
  254.         return $this;
  255.     }
  256.     public function getHouseRules(): ?string
  257.     {
  258.         return $this->houseRules;
  259.     }
  260.     public function setHouseRules(?string $houseRules): self
  261.     {
  262.         $this->houseRules $houseRules;
  263.         return $this;
  264.     }
  265.     public function getContactName(): ?string
  266.     {
  267.         return $this->contactName;
  268.     }
  269.     public function setContactName(?string $contactName): self
  270.     {
  271.         $this->contactName $contactName;
  272.         return $this;
  273.     }
  274.     public function getMailContact(): ?string
  275.     {
  276.         return $this->mailContact;
  277.     }
  278.     public function setMailContact(?string $mailContact): self
  279.     {
  280.         $this->mailContact $mailContact;
  281.         return $this;
  282.     }
  283.     public function getPhoneContact(): ?string
  284.     {
  285.         return $this->phoneContact;
  286.     }
  287.     public function setPhoneContact(?string $phoneContact): self
  288.     {
  289.         $this->phoneContact $phoneContact;
  290.         return $this;
  291.     }
  292.     public function getSecurityDeposit(): ?int
  293.     {
  294.         return $this->securityDeposit;
  295.     }
  296.     public function setSecurityDeposit(?int $securityDeposit): self
  297.     {
  298.         $this->securityDeposit $securityDeposit;
  299.         return $this;
  300.     }
  301.     public function getExpenses(): ?int
  302.     {
  303.         return $this->expenses;
  304.     }
  305.     public function setExpenses(?int $expenses): self
  306.     {
  307.         $this->expenses $expenses;
  308.         return $this;
  309.     }
  310.     public function getExpensesDescription(): ?string
  311.     {
  312.         return $this->expensesDescription;
  313.     }
  314.     public function setExpensesDescription(?string $expensesDescription): self
  315.     {
  316.         $this->expensesDescription $expensesDescription;
  317.         return $this;
  318.     }
  319.     public function isIsAidEligible(): ?bool
  320.     {
  321.         return $this->isAidEligible;
  322.     }
  323.     public function setIsAidEligible(?bool $isAidEligible): self
  324.     {
  325.         $this->isAidEligible $isAidEligible;
  326.         return $this;
  327.     }
  328.     public function getDescription(): ?string
  329.     {
  330.         return $this->description;
  331.     }
  332.     public function setDescription(?string $description): self
  333.     {
  334.         $this->description $description;
  335.         return $this;
  336.     }
  337.     /**
  338.      * @return Collection<int, BuildingEquipment>
  339.      */
  340.     public function getResidenceEquipment(): Collection
  341.     {
  342.         return $this->residenceEquipment;
  343.     }
  344.     public function addResidenceEquipment(BuildingEquipment $residenceEquipment): self
  345.     {
  346.         if (!$this->residenceEquipment->contains($residenceEquipment)) {
  347.             $this->residenceEquipment->add($residenceEquipment);
  348.             $residenceEquipment->setResidence($this);
  349.         }
  350.         return $this;
  351.     }
  352.     public function removeResidenceEquipment(BuildingEquipment $residenceEquipment): self
  353.     {
  354.         if ($this->residenceEquipment->removeElement($residenceEquipment)) {
  355.             // set the owning side to null (unless already changed)
  356.             if ($residenceEquipment->getResidence() === $this) {
  357.                 $residenceEquipment->setResidence(null);
  358.             }
  359.         }
  360.         return $this;
  361.     }
  362.     /**
  363.      * @return Collection<int, BuildingDocument>
  364.      */
  365.     public function getBuildingDocuments(): Collection
  366.     {
  367.         return $this->buildingDocuments;
  368.     }
  369.     public function addBuildingDocument(BuildingDocument $buildingDocument): self
  370.     {
  371.         if (!$this->buildingDocuments->contains($buildingDocument)) {
  372.             $this->buildingDocuments->add($buildingDocument);
  373.             $buildingDocument->setResidence($this);
  374.         }
  375.         return $this;
  376.     }
  377.     public function removeBuildingDocument(BuildingDocument $buildingDocument): self
  378.     {
  379.         if ($this->buildingDocuments->removeElement($buildingDocument)) {
  380.             // set the owning side to null (unless already changed)
  381.             if ($buildingDocument->getResidence() === $this) {
  382.                 $buildingDocument->setResidence(null);
  383.             }
  384.         }
  385.         return $this;
  386.     }
  387.     /**
  388.      * @return Collection<int, Building>
  389.      */
  390.     public function getBuildings(): Collection
  391.     {
  392.         return $this->buildings;
  393.     }
  394.     public function addBuilding(Building $building): self
  395.     {
  396.         if (!$this->buildings->contains($building)) {
  397.             $this->buildings->add($building);
  398.             $building->setResidence($this);
  399.         }
  400.         return $this;
  401.     }
  402.     public function removeBuilding(Building $building): self
  403.     {
  404.         if ($this->buildings->removeElement($building)) {
  405.             // set the owning side to null (unless already changed)
  406.             if ($building->getResidence() === $this) {
  407.                 $building->setResidence(null);
  408.             }
  409.         }
  410.         return $this;
  411.     }
  412.     /**
  413.      * @return Collection<int, BuildingFolder>
  414.      */
  415.     public function getBuildingFolders(): Collection
  416.     {
  417.         return $this->buildingFolders;
  418.     }
  419.     public function addBuildingFolder(BuildingFolder $buildingFolder): self
  420.     {
  421.         if (!$this->buildingFolders->contains($buildingFolder)) {
  422.             $this->buildingFolders->add($buildingFolder);
  423.             $buildingFolder->setResidence($this);
  424.         }
  425.         return $this;
  426.     }
  427.     public function removeBuildingFolder(BuildingFolder $buildingFolder): self
  428.     {
  429.         if ($this->buildingFolders->removeElement($buildingFolder)) {
  430.             // set the owning side to null (unless already changed)
  431.             if ($buildingFolder->getResidence() === $this) {
  432.                 $buildingFolder->setResidence(null);
  433.             }
  434.         }
  435.         return $this;
  436.     }
  437.     public function isIsActive(): ?bool
  438.     {
  439.         return $this->isActive;
  440.     }
  441.     public function setIsActive(?bool $isActive): self
  442.     {
  443.         $this->isActive $isActive;
  444.         return $this;
  445.     }
  446.     public function isIsBlockPossible(): ?bool
  447.     {
  448.         return $this->isBlockPossible;
  449.     }
  450.     public function setIsBlockPossible(?bool $isBlockPossible): self
  451.     {
  452.         $this->isBlockPossible $isBlockPossible;
  453.         return $this;
  454.     }
  455.     public function getNumberId(): ?string
  456.     {
  457.         return $this->numberId;
  458.     }
  459.     public function setNumberId(?string $numberId): self
  460.     {
  461.         $this->numberId $numberId;
  462.         return $this;
  463.     }
  464.     /**
  465.      * @return Collection<int, Promotion>
  466.      */
  467.     public function getPromotions(): Collection
  468.     {
  469.         return $this->promotions;
  470.     }
  471.     public function addPromotion(Promotion $promotion): self
  472.     {
  473.         if (!$this->promotions->contains($promotion)) {
  474.             $this->promotions->add($promotion);
  475.             $promotion->setResidence($this);
  476.         }
  477.         return $this;
  478.     }
  479.     public function removePromotion(Promotion $promotion): self
  480.     {
  481.         if ($this->promotions->removeElement($promotion)) {
  482.             // set the owning side to null (unless already changed)
  483.             if ($promotion->getResidence() === $this) {
  484.                 $promotion->setResidence(null);
  485.             }
  486.         }
  487.         return $this;
  488.     }
  489.     /**
  490.      * @return Collection<int, HousingCertificate>
  491.      */
  492.     public function getHousingCertificates(): Collection
  493.     {
  494.         return $this->housingCertificates;
  495.     }
  496.     public function addHousingCertificate(HousingCertificate $housingCertificate): self
  497.     {
  498.         if (!$this->housingCertificates->contains($housingCertificate)) {
  499.             $this->housingCertificates->add($housingCertificate);
  500.             $housingCertificate->addResidence($this);
  501.         }
  502.         return $this;
  503.     }
  504.     public function removeHousingCertificate(HousingCertificate $housingCertificate): self
  505.     {
  506.         if ($this->housingCertificates->removeElement($housingCertificate)) {
  507.             $housingCertificate->removeResidence($this);
  508.         }
  509.         return $this;
  510.     }
  511.     public function getName(): ?string
  512.     {
  513.         return $this->name;
  514.     }
  515.     public function setName(?string $name): self
  516.     {
  517.         $this->name $name;
  518.         return $this;
  519.     }
  520.     public function getResidenceName(): ?string
  521.     {
  522.         return $this->residenceName;
  523.     }
  524.     public function setResidenceName(?string $residenceName): self
  525.     {
  526.         $this->residenceName $residenceName;
  527.         return $this;
  528.     }
  529.     public function getFilteredCity(): ?City
  530.     {
  531.         return $this->filteredCity;
  532.     }
  533.     public function setFilteredCity(?City $filteredCity): self
  534.     {
  535.         $this->filteredCity $filteredCity;
  536.         return $this;
  537.     }
  538.     public function isAuthorizeAtestation(): ?bool{
  539.         return $this->isAuthorizeAtestation;
  540.     }
  541.     public function setIsAuthorizeAtestation(?bool $authorizeAtestation): self{
  542.         $this->isAuthorizeAtestation =$authorizeAtestation;
  543.         return $this;
  544.     }
  545. }