src/Entity/Address.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Abstract\Entity;
  4. use App\Repository\AddressRepository;
  5. use Symfony\Component\Validator\Constraints as Assert;
  6. use Doctrine\ORM\Mapping as ORM;
  7. #[ORM\Entity(repositoryClass: AddressRepository::class)]
  8. #[Index(name: "address_zip_city_street_idx", columns: ["zip", "city", "street"])]
  9. class Address extends Entity
  10. {
  11. #[ORM\Id]
  12. #[ORM\GeneratedValue]
  13. #[ORM\Column]
  14. private ?int $id = null;
  15. #[ORM\Column(length: 255, nullable: true)]
  16. #[Assert\NotBlank(groups: ['address'])]
  17. private ?string $street = null;
  18. #[ORM\Column(nullable: true)]
  19. #[Assert\NotBlank(groups: ['address'])]
  20. #[Assert\Positive]
  21. #[Assert\Length(min:'4',max:'5')]
  22. private ?int $zip = null;
  23. #[ORM\Column(length: 255, nullable: true)]
  24. #[Assert\NotBlank(groups: ['address'])]
  25. private ?string $city = null;
  26. #[ORM\Column(length: 255, nullable: true)]
  27. private ?string $zipFeatureId = null;
  28. #[ORM\Column(length: 255, nullable: true)]
  29. private ?string $addressFeatureId = null;
  30. #[ORM\Column(length: 30, nullable: true)]
  31. private ?string $country = null;
  32. public function getId(): ?int
  33. {
  34. return $this->id;
  35. }
  36. public function getStreet(): ?string
  37. {
  38. return $this->street;
  39. }
  40. public function setStreet(?string $street): self
  41. {
  42. $this->street = $street;
  43. return $this;
  44. }
  45. public function getZip(): ?int
  46. {
  47. return $this->zip;
  48. }
  49. public function setZip(?int $zip): self
  50. {
  51. $this->zip = $zip;
  52. return $this;
  53. }
  54. public function getCity(): ?string
  55. {
  56. return $this->city;
  57. }
  58. public function setCity(?string $city): self
  59. {
  60. $this->city = $city;
  61. return $this;
  62. }
  63. public function getZipFeatureId(): ?string
  64. {
  65. return $this->zipFeatureId;
  66. }
  67. public function setZipFeatureId(?string $zipFeatureId): self
  68. {
  69. $this->zipFeatureId = $zipFeatureId;
  70. return $this;
  71. }
  72. public function getAddressFeatureId(): ?string
  73. {
  74. return $this->addressFeatureId;
  75. }
  76. public function setAddressFeatureId(?string $addressFeatureId): self
  77. {
  78. $this->addressFeatureId = $addressFeatureId;
  79. return $this;
  80. }
  81. /**
  82. * @return string
  83. */
  84. public function getAddressString(): string
  85. {
  86. if(!empty($this->street) && !empty($this->zip) && !empty($this->city)){
  87. return sprintf("%s %s %s", $this->street, $this->zip, $this->city);
  88. }
  89. return '';
  90. }
  91. public function clearCityIfZipMissing(): void
  92. {
  93. if(empty($this->zip)){
  94. $this->city = '';
  95. }
  96. }
  97. public function getCountry(): ?string
  98. {
  99. return $this->country;
  100. }
  101. public function setCountry(?string $country): static
  102. {
  103. $this->country = $country;
  104. return $this;
  105. }
  106. }