ContactPoint.php 7.6 KB

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