src/Entity/Contact.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\ContactRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\DBAL\Types\Types;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Symfony\Component\Validator\Constraints as Assert;
  9. use App\Enum\ContactStatus;
  10. use App\Enum\Product;
  11. #[ORM\Entity(repositoryClass: ContactRepository::class)]
  12. class Contact
  13. {
  14. private const RGX_NAME = '/^[a-zA-ZÀ-ÖØ-öø-ÿ \'-]+$/u';
  15. #[ORM\Id]
  16. #[ORM\GeneratedValue]
  17. #[ORM\Column(name:"i_id", type: Types::INTEGER, nullable:false, options:["unsigned" => true])]
  18. private ?int $iId = null;
  19. #[ORM\Column(length: 50)]
  20. private Product $eProduct;
  21. #[ORM\Column(length: 30)]
  22. private ContactStatus $eStatus;
  23. #[ORM\Column(length: 255)]
  24. #[Assert\NotBlank]
  25. #[Assert\Email]
  26. private ?string $sEmail = null;
  27. #[ORM\Column(length: 70, nullable: true)]
  28. #[Assert\NotBlank]
  29. #[Assert\Regex(self::RGX_NAME)]
  30. private ?string $sName1 = null;
  31. #[ORM\Column(length: 70)]
  32. #[Assert\NotBlank]
  33. #[Assert\Regex(self::RGX_NAME)]
  34. private ?string $sName2 = null;
  35. #[ORM\Column(length: 20)]
  36. #[Assert\NotBlank]
  37. private ?string $sPhone = null;
  38. #[ORM\Column(type: Types::DATETIME_IMMUTABLE, nullable: true)]
  39. #[Assert\Type(\DateTimeImmutable::class)]
  40. private \DateTimeImmutable $dtCreation;
  41. #[ORM\Column(length: 20)]
  42. private string $sToken;
  43. #[ORM\Column(length: 255, nullable: true)]
  44. private ?string $sObs = null;
  45. #[ORM\OneToMany(mappedBy: 'contact', targetEntity: Seed::class, cascade: ["persist"])]
  46. private Collection $seeds;
  47. /**
  48. * @var Collection<int, Contact2emails>
  49. */
  50. #[ORM\OneToMany(mappedBy: 'contact', targetEntity: Contact2emails::class)]
  51. private Collection $contact2emails;
  52. public function __construct(ContactStatus $eStatus, Product $eProduct = null)
  53. {
  54. $this->eStatus = $eStatus;
  55. $this->eProduct = $eProduct ?? Product::none;
  56. $this->sToken = uniqid() . rand(100, 999);
  57. $this->dtCreation = new \DateTimeImmutable();
  58. $this->seeds = new ArrayCollection();
  59. $this->contact2emails = new ArrayCollection();
  60. }
  61. public function getIId(): ?int
  62. {
  63. return $this->iId;
  64. }
  65. public function getEProduct(): Product
  66. {
  67. return $this->eProduct;
  68. }
  69. public function setEProduct(Product $eProduct): static
  70. {
  71. $this->eProduct = $eProduct;
  72. return $this;
  73. }
  74. public function getSStatus(): string
  75. {
  76. return $this->eStatus->value;
  77. }
  78. public function setEStatus(ContactStatus $eStatus): static
  79. {
  80. $this->eStatus = $eStatus;
  81. return $this;
  82. }
  83. public function getSEmail(): ?string
  84. {
  85. return $this->sEmail;
  86. }
  87. public function setSEmail(string $sEmail): static
  88. {
  89. $this->sEmail = strtolower($sEmail);
  90. return $this;
  91. }
  92. public function getSName1(): ?string
  93. {
  94. return $this->sName1;
  95. }
  96. public function setSName1(string $sName1): static
  97. {
  98. $this->sName1 = mb_convert_case(\trim($sName1), MB_CASE_TITLE, 'UTF-8');
  99. return $this;
  100. }
  101. public function getSName2(): ?string
  102. {
  103. return $this->sName2;
  104. }
  105. public function setSName2(string $sName2): static
  106. {
  107. $this->sName2 = mb_convert_case(\trim($sName2), MB_CASE_UPPER_SIMPLE, 'UTF-8');
  108. return $this;
  109. }
  110. public function getSPhone(): ?string
  111. {
  112. return $this->sPhone;
  113. }
  114. public function setSPhone(string $sPhone): static
  115. {
  116. $this->sPhone = $sPhone;
  117. return $this;
  118. }
  119. public function getDtCreation(): \DateTimeImmutable
  120. {
  121. return $this->dtCreation;
  122. }
  123. public function setDtCreation(\DateTimeImmutable $dtCreation): static
  124. {
  125. $this->dtCreation = $dtCreation;
  126. return $this;
  127. }
  128. public function getSToken(): string
  129. {
  130. return $this->sToken;
  131. }
  132. public function setSToken(string $sToken): static
  133. {
  134. $this->sToken = $sToken;
  135. return $this;
  136. }
  137. public function getSObs(): ?string
  138. {
  139. return $this->sObs;
  140. }
  141. public function setSObs(?string $sObs): static
  142. {
  143. $this->sObs = $sObs;
  144. return $this;
  145. }
  146. public function getSeeds(): Collection
  147. {
  148. return $this->seeds;
  149. }
  150. /**
  151. * @return Collection<int, Contact2emails>
  152. */
  153. public function getContact2emails(): Collection
  154. {
  155. return $this->contact2emails;
  156. }
  157. }