AddressPostal.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Entity\Core;
  4. use ApiPlatform\Metadata\ApiResource;
  5. use App\Entity\Organization\OrganizationAddressPostal;
  6. use App\Entity\Person\PersonAddressPostal;
  7. use App\Entity\Place\AbstractPlace;
  8. // use DH\Auditor\Provider\Doctrine\Auditing\Annotation\Auditable;
  9. use App\Repository\Core\AddressPostalRepository;
  10. use Doctrine\Common\Collections\ArrayCollection;
  11. use Doctrine\Common\Collections\Collection;
  12. use Doctrine\ORM\Mapping as ORM;
  13. use Symfony\Component\Serializer\Annotation\Groups;
  14. /**
  15. * Adresse postale d'une organisation ou d'une personne.
  16. *
  17. * Security :
  18. *
  19. * * @see App\Doctrine\Core\AllowedAddressPostalExtension
  20. */
  21. #[ApiResource(operations: [])]
  22. // #[Auditable]
  23. #[ORM\Entity(repositoryClass: AddressPostalRepository::class)]
  24. class AddressPostal
  25. {
  26. #[ORM\Id]
  27. #[ORM\Column]
  28. #[ORM\GeneratedValue]
  29. #[Groups(['address', 'access_address'])]
  30. private ?int $id = null;
  31. #[ORM\ManyToOne]
  32. #[Groups('address')]
  33. private ?Country $addressCountry = null;
  34. #[ORM\Column(length: 100, nullable: true)]
  35. #[Groups('address')]
  36. private ?string $addressCity = null;
  37. #[ORM\Column(length: 100, nullable: true)]
  38. #[Groups('address')]
  39. private ?string $addressOwner = null;
  40. #[ORM\Column(length: 20, nullable: true)]
  41. #[Groups('address')]
  42. private ?string $postalCode = null;
  43. #[ORM\Column(length: 255, nullable: true)]
  44. #[Groups('address')]
  45. private ?string $streetAddress = null;
  46. #[ORM\Column(length: 255, nullable: true)]
  47. #[Groups('address')]
  48. private ?string $streetAddressSecond = null;
  49. #[ORM\Column(length: 255, nullable: true)]
  50. #[Groups('address')]
  51. private ?string $streetAddressThird = null;
  52. #[ORM\Column(nullable: true)]
  53. #[Groups('address')]
  54. private ?float $latitude = null;
  55. #[ORM\Column(nullable: true)]
  56. #[Groups('address')]
  57. private ?float $longitude = null;
  58. #[ORM\OneToOne(mappedBy: 'addressPostal')]
  59. private OrganizationAddressPostal $organizationAddressPostal;
  60. #[ORM\OneToOne(mappedBy: 'addressPostal')]
  61. private PersonAddressPostal $personAddressPostal;
  62. #[ORM\OneToMany(mappedBy: 'addressPostal', targetEntity: AbstractPlace::class)]
  63. private Collection $places;
  64. #[ORM\OneToMany(mappedBy: 'addressPostal', targetEntity: OrganizationAddressPostal::class, cascade: [], orphanRemoval: false)]
  65. protected Collection $organizationAddressPostals;
  66. public function __construct()
  67. {
  68. $this->places = new ArrayCollection();
  69. $this->organizationAddressPostals = new ArrayCollection();
  70. }
  71. public function getId(): ?int
  72. {
  73. return $this->id;
  74. }
  75. public function getAddressCountry(): ?Country
  76. {
  77. return $this->addressCountry;
  78. }
  79. public function setAddressCountry(?Country $addressCountry): self
  80. {
  81. $this->addressCountry = $addressCountry;
  82. return $this;
  83. }
  84. public function getAddressCity(): ?string
  85. {
  86. return $this->addressCity;
  87. }
  88. public function setAddressCity(?string $addressCity): self
  89. {
  90. $this->addressCity = $addressCity;
  91. return $this;
  92. }
  93. public function getAddressOwner(): ?string
  94. {
  95. return $this->addressOwner;
  96. }
  97. public function setAddressOwner(?string $addressOwner): self
  98. {
  99. $this->addressOwner = $addressOwner;
  100. return $this;
  101. }
  102. public function getPostalCode(): ?string
  103. {
  104. return $this->postalCode;
  105. }
  106. public function setPostalCode(?string $postalCode): self
  107. {
  108. $this->postalCode = $postalCode;
  109. return $this;
  110. }
  111. public function getStreetAddress(): ?string
  112. {
  113. return $this->streetAddress;
  114. }
  115. public function setStreetAddress(?string $streetAddress): self
  116. {
  117. $this->streetAddress = $streetAddress;
  118. return $this;
  119. }
  120. public function getStreetAddressSecond(): ?string
  121. {
  122. return $this->streetAddressSecond;
  123. }
  124. public function setStreetAddressSecond(?string $streetAddressSecond): self
  125. {
  126. $this->streetAddressSecond = $streetAddressSecond;
  127. return $this;
  128. }
  129. public function getStreetAddressThird(): ?string
  130. {
  131. return $this->streetAddressThird;
  132. }
  133. public function setStreetAddressThird(?string $streetAddressThird): self
  134. {
  135. $this->streetAddressThird = $streetAddressThird;
  136. return $this;
  137. }
  138. public function getLatitude(): ?float
  139. {
  140. return $this->latitude;
  141. }
  142. public function setLatitude(?float $latitude): self
  143. {
  144. $this->latitude = $latitude;
  145. return $this;
  146. }
  147. public function getLongitude(): ?float
  148. {
  149. return $this->longitude;
  150. }
  151. public function setLongitude(?float $longitude): self
  152. {
  153. $this->longitude = $longitude;
  154. return $this;
  155. }
  156. public function getOrganizationAddressPostal(): ?OrganizationAddressPostal
  157. {
  158. return $this->organizationAddressPostal;
  159. }
  160. public function setOrganizationAddressPostal(OrganizationAddressPostal $organizationAddressPostal): self
  161. {
  162. $this->organizationAddressPostal = $organizationAddressPostal;
  163. return $this;
  164. }
  165. public function getPersonAddressPostal(): ?PersonAddressPostal
  166. {
  167. return $this->personAddressPostal;
  168. }
  169. public function setPersonAddressPostal(PersonAddressPostal $personAddressPostal): self
  170. {
  171. $this->personAddressPostal = $personAddressPostal;
  172. return $this;
  173. }
  174. /**
  175. * @return Collection<int, AbstractPlace>
  176. */
  177. public function getPlaces(): Collection
  178. {
  179. return $this->places;
  180. }
  181. public function addPlace(AbstractPlace $place): self
  182. {
  183. if (!$this->places->contains($place)) {
  184. $this->places[] = $place;
  185. $place->setAddressPostal($this);
  186. }
  187. return $this;
  188. }
  189. public function removePlace(AbstractPlace $place): self
  190. {
  191. if ($this->places->removeElement($place)) {
  192. // set the owning side to null (unless already changed)
  193. if ($place->getAddressPostal() === $this) {
  194. $place->setAddressPostal(null);
  195. }
  196. }
  197. return $this;
  198. }
  199. function getOrganizationAddressPostals(): Collection
  200. {
  201. return $this->organizationAddressPostals;
  202. }
  203. function addOrganizationAddressPostal(OrganizationAddressPostal $organizationAddressPostal): self
  204. {
  205. if (!$this->organizationAddressPostals->contains($organizationAddressPostal)) {
  206. $this->organizationAddressPostals[] = $organizationAddressPostal;
  207. $organizationAddressPostal->setAddressPostal($this);
  208. }
  209. return $this;
  210. }
  211. function removeOrganizationAddressPostal(OrganizationAddressPostal $organizationAddressPostal): self
  212. {
  213. if ($this->organizationAddressPostals->removeElement($organizationAddressPostal)) {
  214. // $organizationAddressPostal->setAddressPostal(null); // TODO: actuellement, pas nullable: conserver?
  215. }
  216. return $this;
  217. }
  218. }