src/Entity/Address.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\AddressRepository;
  4. use DateTime;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\DBAL\Types\Types;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Symfony\Component\HttpFoundation\File\File;
  9. use Symfony\Component\HttpFoundation\File\UploadedFile;
  10. use Symfony\Component\Validator\Constraints as Assert;
  11. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  12. #[ORM\Entity(repositoryClassAddressRepository::class)]
  13. #[ORM\Table(name'address')]
  14. /**
  15.  * @Vich\Uploadable
  16.  */
  17. class Address implements UserObjectInterface
  18. {
  19.     #[ORM\Id]
  20.     #[ORM\GeneratedValue]
  21.     #[ORM\Column(typeTypes::INTEGER)]
  22.     private ?int $id null;
  23.     #[ORM\Column(typeTypes::DATETIME_MUTABLE)]
  24.     private DateTime $createdAt;
  25.     #[ORM\Column(typeTypes::STRINGlength255nullabletrue)]
  26.     private ?string $locationMore null;
  27.     #[ORM\Column(typeTypes::STRINGlength255nullabletrue)]
  28.     private ?string $tgiBp null;
  29.     #[ORM\Column(typeTypes::STRINGlength255nullabletrue)]
  30.     private ?string $tgiPostalCode;
  31.     #[ORM\Column(typeTypes::STRINGlength255nullabletrue)]
  32.     private ?string $tgiCommune;
  33.     #[ORM\Column(typeTypes::STRINGlength255nullabletrue)]
  34.     private ?string $tgiName null;
  35.     #[ORM\Column(typeTypes::STRINGlength255nullabletrue)]
  36.     private ?string $tgiAdresses;
  37.     #[ORM\Column(typeTypes::BOOLEAN)]
  38.     private bool $isDeleted false;
  39.     #[ORM\Column(typeTypes::STRINGlength255nullabletrue)]
  40.     private ?string $gmapsAddress;
  41.     #[ORM\Column(typeTypes::STRINGlength255nullabletrue)]
  42.     private ?string $city null;
  43.     #[ORM\Column(typeTypes::STRINGlength255nullabletrue)]
  44.     private ?string $zipCode null;
  45.     #[ORM\Column(typeTypes::STRINGlength255nullabletrue)]
  46.     private ?string $streetNumber null;
  47.     #[ORM\Column(typeTypes::STRINGlength255nullabletrue)]
  48.     private ?string $roadType null;
  49.     #[ORM\Column(typeTypes::STRINGlength255nullabletrue)]
  50.     private ?string $roadName null;
  51.     #[Assert\NotBlank(message'Ce champ est obligatoire')]
  52.     #[ORM\Column(typeTypes::STRINGlength255nullabletrue)]
  53.     private ?string $houseType null;
  54.     #[ORM\Column(typeTypes::STRINGlength255nullabletrue)]
  55.     private ?string $placeName null;
  56.     #[ORM\Column(typeTypes::STRINGlength255nullabletrue)]
  57.     private ?string $roomNumber;
  58.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  59.     private ?DateTime $arrivalDate null;
  60.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  61.     private $departureDate null;
  62.     #[Assert\Choice(callback'getTypes'multiplefalse)]
  63.     #[ORM\Column(typeTypes::STRINGlength255nullabletrue)]
  64.     private ?string $type null;
  65.     #[Assert\Choice(callback'getResidentTypes'multiplefalse)]
  66.     #[ORM\Column(typeTypes::STRINGlength255nullabletrue)]
  67.     private ?string $residentType;
  68.     #[ORM\Column(typeTypes::STRINGlength255nullabletrue)]
  69.     private ?string $addressFileName null;
  70.     #[ORM\Column(typeTypes::INTEGERnullabletrue)]
  71.     private ?int $addressFileSize null;
  72.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  73.     private DateTime|null $addressFileUpdatedAt null;
  74.     #[ORM\ManyToOne(targetEntityUser::class, fetch'EXTRA_LAZY'inversedBy'addressUser')]
  75.     private ?User $user null;
  76.     /**
  77.      * @var Collection<Insurance>
  78.      */
  79.     #[Assert\Valid]
  80.     #[ORM\OneToMany(mappedBy'addressInsurance'targetEntityInsurance::class)]
  81.     private Collection $insurance;
  82.     /**
  83.      * @var Collection<Video>
  84.      */
  85.     #[ORM\OneToMany(mappedBy'address'targetEntityVideo::class)]
  86.     private Collection $videos;
  87.     /**
  88.      * @var Collection<DisasterDeclaration>
  89.      */
  90.     #[ORM\OneToMany(mappedBy'address'targetEntityDisasterDeclaration::class)]
  91.     private Collection $disasterDeclarations;
  92.     /**
  93.      * NOTE: This is not a mapped field of entity metadata, just a simple property.
  94.      * @Vich\UploadableField(mapping="insurance", fileNameProperty="addressFileName", size="addressFileSize")
  95.      */
  96.     private ?File $addressFile null;
  97.     public function __construct()
  98.     {
  99.         $this->createdAt = new DateTime();
  100.     }
  101.     public function __toString()
  102.     {
  103.         return strval($this->id);
  104.     }
  105.     public function getId(): ?int
  106.     {
  107.         return $this->id;
  108.     }
  109.     public function setCreatedAt(DateTime $createdAt): static
  110.     {
  111.         $this->createdAt $createdAt;
  112.         return $this;
  113.     }
  114.     public function getCreatedAt(): DateTime
  115.     {
  116.         return $this->createdAt;
  117.     }
  118.     public function setLocationMore(?string $locationMore null): static
  119.     {
  120.         $this->locationMore $locationMore;
  121.         return $this;
  122.     }
  123.     public function getLocationMore(): ?string
  124.     {
  125.         return $this->locationMore;
  126.     }
  127.     public function setTgiBp(?string $tgiBp null): static
  128.     {
  129.         $this->tgiBp $tgiBp;
  130.         return $this;
  131.     }
  132.     public function getTgiBp(): ?string
  133.     {
  134.         return $this->tgiBp;
  135.     }
  136.     public function setTgiPostalCode(?String $tgiPostalCode null): static
  137.     {
  138.         $this->tgiPostalCode $tgiPostalCode;
  139.         return $this;
  140.     }
  141.     public function getTgiPostalCode(): ?string
  142.     {
  143.         return $this->tgiPostalCode;
  144.     }
  145.     public function setTgiCommune(?string $tgiCommune null): static
  146.     {
  147.         $this->tgiCommune $tgiCommune;
  148.         return $this;
  149.     }
  150.     public function getTgiCommune(): ?string
  151.     {
  152.         return $this->tgiCommune;
  153.     }
  154.     public function setTgiName(?string $tgiName null): static
  155.     {
  156.         $this->tgiName $tgiName;
  157.         return $this;
  158.     }
  159.     public function getTgiName(): ?string
  160.     {
  161.         return $this->tgiName;
  162.     }
  163.     public function setTgiAdresses(?string $tgiAdresses null): static
  164.     {
  165.         $this->tgiAdresses $tgiAdresses;
  166.         return $this;
  167.     }
  168.     public function getTgiAdresses(): ?string
  169.     {
  170.         return $this->tgiAdresses;
  171.     }
  172.     public function setIsDeleted(bool $isDeleted): static
  173.     {
  174.         $this->isDeleted $isDeleted;
  175.         return $this;
  176.     }
  177.     public function getIsDeleted(): bool
  178.     {
  179.         return $this->isDeleted;
  180.     }
  181.     public function setGmapsAddress(?string $gmapsAddress null): static
  182.     {
  183.         $this->gmapsAddress $gmapsAddress;
  184.         return $this;
  185.     }
  186.     public function getGmapsAddress(): ?string
  187.     {
  188.         return $this->gmapsAddress;
  189.     }
  190.     public function setCity(?string $city null): static
  191.     {
  192.         $this->city $city;
  193.         return $this;
  194.     }
  195.     public function getCity(): ?string
  196.     {
  197.         return $this->city;
  198.     }
  199.     public function setZipCode(?string $zipCode null): static
  200.     {
  201.         $this->zipCode $zipCode;
  202.         return $this;
  203.     }
  204.     public function getZipCode(): ?string
  205.     {
  206.         return $this->zipCode;
  207.     }
  208.     public function setStreetNumber(?string $streetNumber null): static
  209.     {
  210.         $this->streetNumber $streetNumber;
  211.         return $this;
  212.     }
  213.     public function getStreetNumber(): ?string
  214.     {
  215.         return $this->streetNumber;
  216.     }
  217.     public function setRoadType(?string $roadType null): static
  218.     {
  219.         $this->roadType $roadType;
  220.         return $this;
  221.     }
  222.     public function getRoadType(): ?string
  223.     {
  224.         return $this->roadType;
  225.     }
  226.     public function setRoadName(?string $roadName null): static
  227.     {
  228.         $this->roadName $roadName;
  229.         return $this;
  230.     }
  231.     public function getRoadName(): ?string
  232.     {
  233.         return $this->roadName;
  234.     }
  235.     public function setHouseType(?string $houseType null): static
  236.     {
  237.         $this->houseType $houseType;
  238.         return $this;
  239.     }
  240.     public function getHouseType(): ?string
  241.     {
  242.         return $this->houseType;
  243.     }
  244.     public function setType(?string $type null): static
  245.     {
  246.         $this->type $type;
  247.         return $this;
  248.     }
  249.     public function getType(): ?string
  250.     {
  251.         return $this->type;
  252.     }
  253.     public function setResidentType(?string $residentType null): string
  254.     {
  255.         $this->residentType $residentType;
  256.         return $this;
  257.     }
  258.     public function getResidentType(): ?string
  259.     {
  260.         return $this->residentType;
  261.     }
  262.     public function setAddressFileName(?string $addressFileName): static
  263.     {
  264.         $this->addressFileName $addressFileName;
  265.         return $this;
  266.     }
  267.     public function getAddressFileName(): ?string
  268.     {
  269.         return $this->addressFileName;
  270.     }
  271.     public function setAddressFileSize(?int $addressFileSize): static
  272.     {
  273.         $this->addressFileSize $addressFileSize;
  274.         return $this;
  275.     }
  276.     public function getAddressFileSize(): ?int
  277.     {
  278.         return $this->addressFileSize;
  279.     }
  280.     public function setAddressFileUpdatedAt(DateTime|null $addressFileUpdatedAt): static
  281.     {
  282.         $this->addressFileUpdatedAt $addressFileUpdatedAt;
  283.         return $this;
  284.     }
  285.     public function getAddressFileUpdatedAt(): ?DateTime
  286.     {
  287.         return $this->addressFileUpdatedAt;
  288.     }
  289.     public function setUser(?User $user null): static
  290.     {
  291.         $this->user $user;
  292.         return $this;
  293.     }
  294.     public function getUser(): ?User
  295.     {
  296.         return $this->user;
  297.     }
  298.     public function addInsurance(Insurance $insurance): static
  299.     {
  300.         $this->insurance[] = $insurance;
  301.         return $this;
  302.     }
  303.     public function removeInsurance(Insurance $insurance): bool
  304.     {
  305.         return $this->insurance->removeElement($insurance);
  306.     }
  307.     /**
  308.      * @return Collection<Insurance>
  309.      */
  310.     public function getInsurance(): Collection
  311.     {
  312.         return $this->insurance;
  313.     }
  314.     public function addVideo(Video $video): static
  315.     {
  316.         $this->videos[] = $video;
  317.         return $this;
  318.     }
  319.     public function removeVideo(Video $video): bool
  320.     {
  321.         return $this->videos->removeElement($video);
  322.     }
  323.     /**
  324.      * @return Collection<Video>
  325.      */
  326.     public function getVideos(): Collection
  327.     {
  328.         return $this->videos;
  329.     }
  330.     public function addDisasterDeclaration(DisasterDeclaration $disasterDeclaration): static
  331.     {
  332.         $this->disasterDeclarations[] = $disasterDeclaration;
  333.         return $this;
  334.     }
  335.     public function removeDisasterDeclaration(DisasterDeclaration $disasterDeclaration): bool
  336.     {
  337.         return $this->disasterDeclarations->removeElement($disasterDeclaration);
  338.     }
  339.     /**
  340.      * @return Collection<DisasterDeclaration>
  341.      */
  342.     public function getDisasterDeclarations(): Collection
  343.     {
  344.         return $this->disasterDeclarations;
  345.     }
  346.     /**
  347.      * If manually uploading a file (i.e. not using Symfony Form) ensure an instance
  348.      * of 'UploadedFile' is injected into this setter to trigger the  update. If this
  349.      * bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
  350.      * must be able to accept an instance of 'File' as the bundle will inject one here
  351.      * during Doctrine hydration.
  352.      */
  353.     public function setAddressFile(File|UploadedFile $image null): static
  354.     {
  355.         $this->addressFile $image;
  356.         if (null !== $image) {
  357.             // It is required that at least one field changes if you are using doctrine
  358.             // otherwise the event listeners won't be called and the file is lost
  359.             $this->addressFileUpdatedAt = new DateTime();
  360.         }
  361.         return $this;
  362.     }
  363.     public function getAddressFile(): ?File
  364.     {
  365.         return $this->addressFile;
  366.     }
  367.     public function getHouseTypes(): array
  368.     {
  369.         $arr = [
  370.             "Appartement",
  371.             "Maison",
  372.             "Chalet",
  373.             "Ferme",
  374.             "Mobile home",
  375.             "Caravane",
  376.             "Loft",
  377.             "Villa",
  378.         ];
  379.         return array_combine($arr$arr);
  380.     }
  381.     public function getOtherPlaceTypes(): array
  382.     {
  383.         $arr = [
  384.             "Atelier",
  385.             "Box",
  386.             "Cabanon",
  387.             "Dépendance",
  388.             "Entrepôt de stockage",
  389.             "Garage",
  390.             "Grange",
  391.             "Hangar",
  392.             "Remise",
  393.             "Appartement à usage locatif",
  394.             "Maison à usage locatif",
  395.             "Immeuble à usage locatif",
  396.         ];
  397.         if($this->houseType && !in_array($this->houseType$arr)) {
  398.             $arr[] = $this->houseType;
  399.         }
  400.         return array_combine($arr$arr);
  401.     }
  402.     public function getVacancyPlaceTypes()
  403.     {
  404.         $arr = [
  405.             "Appartement",
  406.             "Maison",
  407.             "Villa",
  408.             "Chalet",
  409.             "Bungalow",
  410.             "Mobile home",
  411.             "Cabanon",
  412.         ];
  413.         return array_combine($arr$arr);
  414.     }
  415.     public static function getTypes(bool $isMain falsebool $hasMain falsebool $isEdit false): array
  416.     {
  417.         if ($hasMain) {
  418.             return [
  419.                 "Domicile secondaire" => "second",
  420.                 "Autre local" => "other",
  421.             ];
  422.         }
  423.         if ($isMain) {
  424.             return [
  425.                 "Domicile principal" => "main",
  426.             ];
  427.         }
  428.         if ($isEdit) {
  429.             return [
  430.                 "Domicile principal" => "main",
  431.                 "Domicile secondaire" => "second",
  432.                 "Autre local" => "other",
  433.             ];
  434.         }
  435.         return [
  436.             "Domicile principal" => "main",
  437.             "hôtel" => "hotel",
  438.             "Domicile secondaire" => "second",
  439.             "Lieu de résidence" => "vacancy",
  440.             "Autre local" => "other",
  441.         ];
  442.     }
  443.     public static function getResidentTypes(): array
  444.     {
  445.         return [
  446.             'Propriétaire' => 'owner',
  447.             'Locataire' => 'tenant',
  448.             'Occupant à titre gratuit' => 'freeOccupant',
  449.             'Propriétaire non occupant' => 'nonOccupantOwner',
  450.         ];
  451.     }
  452.     public function getResidentTypeLabel(): string
  453.     {
  454.         $arr = [
  455.             "owner" => "Propriétaire",
  456.             "tenant" => "Locataire",
  457.             "freeOccupant" => "Occupant à titre gratuit",
  458.             "nonOccupantOwner" => "Propriétaire non occupant",
  459.         ];
  460.         return $arr[$this->residentType] ?? '';
  461.     }
  462.     public function getPlaceName(): ?string
  463.     {
  464.         return $this->placeName;
  465.     }
  466.     public function setPlaceName(?string $placeName): self
  467.     {
  468.         $this->placeName $placeName;
  469.         return $this;
  470.     }
  471.     public function getRoomNumber(): ?string
  472.     {
  473.         return $this->roomNumber;
  474.     }
  475.     public function setRoomNumber(?string $roomNumber): self
  476.     {
  477.         $this->roomNumber $roomNumber;
  478.         return $this;
  479.     }
  480.     public function getArrivalDate(): ?\DateTimeInterface
  481.     {
  482.         return $this->arrivalDate;
  483.     }
  484.     public function setArrivalDate(?\DateTimeInterface $arrivalDate): self
  485.     {
  486.         $this->arrivalDate $arrivalDate;
  487.         return $this;
  488.     }
  489.     public function getDepartureDate(): ?\DateTimeInterface
  490.     {
  491.         return $this->departureDate;
  492.     }
  493.     public function setDepartureDate(?\DateTimeInterface $departureDate): self
  494.     {
  495.         $this->departureDate $departureDate;
  496.         return $this;
  497.     }
  498.     public function getActiveInsurance(): ?Insurance
  499.     {
  500.         $insurance $this->insurance->filter(fn(Insurance $insurance) => !$insurance->getIsDeleted())->first();
  501.         return !$insurance null $insurance;
  502.     }
  503.     public function hasActiveInsurance(): bool
  504.     {
  505.         return $this->getActiveInsurance() !== null;
  506.     }
  507.     public function inTypes(): bool
  508.     {
  509.         return in_array($this->type$this->getTypes());
  510.     }
  511.     public function getCountry(): string
  512.     {
  513.         $parts explode(','$this->gmapsAddress);
  514.         return $parts[count($parts) - 1];
  515.     }
  516.     public function getResidentTypeKey(): int
  517.     {
  518.         $types $this->getResidentTypes();
  519.         $k 0;
  520.         foreach ($types as $type) {
  521.             if ($type === $this->residentType)
  522.                 return $k;
  523.             $k++;
  524.         }
  525.         return -1;
  526.     }
  527.     public function getFullAddress(): string
  528.     {
  529.         $road implode(' 'array_filter([
  530.             $this->streetNumber,
  531.             $this->roadName,
  532.         ]));
  533.         $city implode(' 'array_filter([
  534.             $this->zipCode,
  535.             $this->city,
  536.         ]));
  537.         return implode(', 'array_filter([
  538.             $road,
  539.             $city,
  540.             $this->getCountry(),
  541.         ]));
  542.     }
  543. }