ContactPoint.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Entity\Core;
  4. use ApiPlatform\Metadata\ApiResource;
  5. use App\Entity\Billing\ResidenceArea;
  6. use App\Entity\Organization\Organization;
  7. use App\Entity\Person\Person;
  8. use App\Entity\Place\AbstractPlace;
  9. // use DH\Auditor\Provider\Doctrine\Auditing\Annotation\Auditable;
  10. use App\Entity\Place\Place;
  11. use App\Entity\Traits\CreatedOnAndByTrait;
  12. use App\Enum\Core\ContactPointTypeEnum;
  13. use App\Repository\Core\ContactPointRepository;
  14. use App\Validator\Core as OpentalentAssert;
  15. use Doctrine\Common\Collections\ArrayCollection;
  16. use Doctrine\Common\Collections\Collection;
  17. use Doctrine\ORM\Mapping as ORM;
  18. use JetBrains\PhpStorm\Pure;
  19. use libphonenumber\PhoneNumber;
  20. use Symfony\Component\Validator\Constraints as Assert;
  21. /**
  22. * Données de contact d'une Person ou d'une Organization ou d'un lieu.
  23. *
  24. * Security :
  25. *
  26. * * @see App\Security\Voter\ContactPointVoter
  27. */
  28. #[ApiResource(operations: [])]
  29. // #[Auditable]
  30. #[ORM\Entity(repositoryClass: ContactPointRepository::class)]
  31. #[OpentalentAssert\ContactPoint]
  32. class ContactPoint
  33. {
  34. use CreatedOnAndByTrait;
  35. #[ORM\Id]
  36. #[ORM\Column]
  37. #[ORM\GeneratedValue]
  38. private ?int $id = null;
  39. #[ORM\Column(length: 50, enumType: ContactPointTypeEnum::class)]
  40. private ContactPointTypeEnum $contactType;
  41. #[ORM\Column(length: 255, nullable: true)]
  42. #[Assert\Email(message: 'invalid-email-format', mode: 'strict')]
  43. private ?string $email = null;
  44. #[ORM\Column(length: 255, nullable: true)]
  45. private ?string $emailInvalid = null;
  46. #[ORM\Column(type: 'phone_number', nullable: true)]
  47. private ?PhoneNumber $faxNumber = null;
  48. #[ORM\Column(length: 255, nullable: true)]
  49. private ?string $faxNumberInvalid = null;
  50. #[ORM\Column(type: 'phone_number', nullable: true)]
  51. private ?PhoneNumber $telphone = null;
  52. #[ORM\Column(length: 255, nullable: true)]
  53. private ?string $telphoneInvalid = null;
  54. #[ORM\Column(type: 'phone_number', nullable: true)]
  55. private ?PhoneNumber $mobilPhone = null;
  56. #[ORM\Column(length: 255, nullable: true)]
  57. private ?string $mobilPhoneInvalid = null;
  58. /** @var Collection<int, Organization> */
  59. #[ORM\ManyToMany(targetEntity: Organization::class, inversedBy: 'contactPoints')]
  60. #[ORM\JoinTable(name: 'organization_contactpoint')]
  61. #[ORM\JoinColumn(name: 'contactPoint_id', referencedColumnName: 'id', unique: true)]
  62. #[ORM\InverseJoinColumn(name: 'organization_id', referencedColumnName: 'id')]
  63. private Collection $organization;
  64. /** @var Collection<int, Person> */
  65. #[ORM\ManyToMany(targetEntity: Person::class, inversedBy: 'contactPoints')]
  66. #[ORM\JoinTable(name: 'person_contactpoint')]
  67. #[ORM\JoinColumn(name: 'contactPoint_id', referencedColumnName: 'id', unique: true)]
  68. #[ORM\InverseJoinColumn(name: 'person_id', referencedColumnName: 'id')]
  69. private Collection $person;
  70. /** @var Collection<int, Place> */
  71. #[ORM\ManyToMany(targetEntity: Place::class, mappedBy: 'contactpoint')]
  72. private Collection $place;
  73. #[Pure]
  74. public function __construct()
  75. {
  76. $this->organization = new ArrayCollection();
  77. $this->person = new ArrayCollection();
  78. $this->place = new ArrayCollection();
  79. }
  80. public function getId(): ?int
  81. {
  82. return $this->id;
  83. }
  84. public function getContactType(): ContactPointTypeEnum
  85. {
  86. return $this->contactType;
  87. }
  88. public function setContactType(ContactPointTypeEnum $contactType): self
  89. {
  90. $this->contactType = $contactType;
  91. return $this;
  92. }
  93. public function getEmail(): ?string
  94. {
  95. return $this->email;
  96. }
  97. public function setEmail(?string $email): self
  98. {
  99. $this->email = $email;
  100. if (!is_null($this->email && !is_null($this->getEmailInvalid()))) {
  101. $this->setEmailInvalid(null);
  102. }
  103. return $this;
  104. }
  105. public function getEmailInvalid(): ?string
  106. {
  107. return $this->emailInvalid;
  108. }
  109. public function setEmailInvalid(?string $emailInvalid): self
  110. {
  111. $this->emailInvalid = $emailInvalid;
  112. return $this;
  113. }
  114. public function getFaxNumber(): ?PhoneNumber
  115. {
  116. return $this->faxNumber;
  117. }
  118. public function setFaxNumber(?PhoneNumber $faxNumber): self
  119. {
  120. $this->faxNumber = $faxNumber;
  121. if (!is_null($this->faxNumber) && !is_null($this->getFaxNumberInvalid())) {
  122. $this->setFaxNumberInvalid(null);
  123. }
  124. return $this;
  125. }
  126. public function getFaxNumberInvalid(): ?string
  127. {
  128. return $this->faxNumberInvalid;
  129. }
  130. public function setFaxNumberInvalid(?string $faxNumberInvalid): self
  131. {
  132. $this->faxNumberInvalid = $faxNumberInvalid;
  133. return $this;
  134. }
  135. public function getTelphone(): ?PhoneNumber
  136. {
  137. return $this->telphone;
  138. }
  139. public function setTelphone(?PhoneNumber $telphone): self
  140. {
  141. $this->telphone = $telphone;
  142. if (!is_null($this->telphone && !is_null($this->getTelphoneInvalid()))) {
  143. $this->setTelphoneInvalid(null);
  144. }
  145. return $this;
  146. }
  147. public function getTelphoneInvalid(): ?string
  148. {
  149. return $this->telphoneInvalid;
  150. }
  151. public function setTelphoneInvalid(?string $telphoneInvalid): self
  152. {
  153. $this->telphoneInvalid = $telphoneInvalid;
  154. return $this;
  155. }
  156. public function getMobilPhone(): ?PhoneNumber
  157. {
  158. return $this->mobilPhone;
  159. }
  160. public function setMobilPhone(?PhoneNumber $mobilPhone): self
  161. {
  162. $this->mobilPhone = $mobilPhone;
  163. if (!is_null($this->mobilPhone && !is_null($this->getMobilPhoneInvalid()))) {
  164. $this->setMobilPhoneInvalid(null);
  165. }
  166. return $this;
  167. }
  168. public function getMobilPhoneInvalid(): ?string
  169. {
  170. return $this->mobilPhoneInvalid;
  171. }
  172. public function setMobilPhoneInvalid(?string $mobilPhoneInvalid): self
  173. {
  174. $this->mobilPhoneInvalid = $mobilPhoneInvalid;
  175. return $this;
  176. }
  177. public function getOrganization(): Collection
  178. {
  179. return $this->organization;
  180. }
  181. public function addOrganization(Organization $organization): self
  182. {
  183. if (!$this->organization->contains($organization)) {
  184. $this->organization[] = $organization;
  185. $organization->addContactPoint($this);
  186. }
  187. return $this;
  188. }
  189. public function removeOrganization(Organization $organization): self
  190. {
  191. if ($this->organization->removeElement($organization)) {
  192. $organization->removeContactPoint($this);
  193. }
  194. return $this;
  195. }
  196. public function getPerson(): Collection
  197. {
  198. return $this->person;
  199. }
  200. public function addPerson(Person $person): self
  201. {
  202. if (!$this->person->contains($person)) {
  203. $this->person[] = $person;
  204. $person->addContactPoint($this);
  205. }
  206. return $this;
  207. }
  208. public function removePerson(Person $person): self
  209. {
  210. if ($this->person->removeElement($person)) {
  211. $person->removeContactPoint($this);
  212. }
  213. return $this;
  214. }
  215. /**
  216. * @return Collection<int, Place>
  217. */
  218. public function getPlace(): Collection
  219. {
  220. return $this->place;
  221. }
  222. public function addPlace(Place $place): self
  223. {
  224. if (!$this->place->contains($place)) {
  225. $this->place[] = $place;
  226. $place->addContactpoint($this);
  227. }
  228. return $this;
  229. }
  230. public function removePlace(Place $place): self
  231. {
  232. if ($this->place->removeElement($place)) {
  233. $place->removeContactpoint($this);
  234. }
  235. return $this;
  236. }
  237. }