ContactPoint.php 7.7 KB

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