ContactPoint.php 7.9 KB

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