src/Entity/Tu.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Abstract\Entity;
  4. use App\Repository\TuRepository;
  5. use App\Validator\InputValidator;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Symfony\Component\Mime\Address as EmailAddress;
  10. use Symfony\Component\Uid\Uuid;
  11. use Symfony\Component\Validator\Constraints as Assert;
  12. #[ORM\Entity(repositoryClass: TuRepository::class)]
  13. #[Index(name: "tu_configName_idx", columns: ["configName"])]
  14. class Tu extends Entity
  15. {
  16. #[ORM\Id]
  17. #[ORM\Column(type: 'uuid', unique: true)]
  18. #[ORM\GeneratedValue(strategy: 'CUSTOM')]
  19. #[ORM\CustomIdGenerator(class: 'doctrine.uuid_generator')]
  20. private ?Uuid $id = null;
  21. #[ORM\Column(length: 100)]
  22. #[Assert\NotBlank(message: 'tu.error.name')]
  23. private ?string $name = null;
  24. #[ORM\OneToMany(mappedBy: 'tU', targetEntity: PricingModel::class, cascade: ['persist', 'remove'])]
  25. #[ORM\OrderBy(['employeeDiscount' => 'ASC'])]
  26. #[Assert\Valid]
  27. private Collection $pricingModels;
  28. #[ORM\Column(length: 30)]
  29. #[Assert\NotBlank(message: 'tu.error.configName')]
  30. private ?string $configName = null;
  31. #[ORM\OneToMany(mappedBy: 'tu', targetEntity: Enterprise::class)]
  32. private Collection $enterprises;
  33. #[ORM\OneToMany(mappedBy: 'tu', targetEntity: User::class)]
  34. private Collection $users;
  35. #[ORM\Column(length: 80, nullable: true)]
  36. private ?string $senderEmail = null;
  37. #[ORM\Column(length: 80, nullable: true)]
  38. private ?string $senderName = null;
  39. public function __construct()
  40. {
  41. $this->pricingModels = new ArrayCollection();
  42. $this->enterprises = new ArrayCollection();
  43. $this->users = new ArrayCollection();
  44. }
  45. public function getId(): ?Uuid
  46. {
  47. return $this->id;
  48. }
  49. public function getName(): ?string
  50. {
  51. return $this->name;
  52. }
  53. public function setName(string $name): static
  54. {
  55. $this->name = $name;
  56. return $this;
  57. }
  58. /**
  59. * @return Collection<int, PricingModel>
  60. */
  61. public function getPricingModels(): Collection
  62. {
  63. return $this->pricingModels;
  64. }
  65. public function addPricingModel(PricingModel $pricingModel): static
  66. {
  67. if (!$this->pricingModels->contains($pricingModel)) {
  68. $this->pricingModels->add($pricingModel);
  69. $pricingModel->setTU($this);
  70. }
  71. return $this;
  72. }
  73. public function removePricingModel(PricingModel $pricingModel): static
  74. {
  75. if ($this->pricingModels->removeElement($pricingModel)) {
  76. // set the owning side to null (unless already changed)
  77. if ($pricingModel->getTU() === $this) {
  78. $pricingModel->setTU(null);
  79. }
  80. }
  81. return $this;
  82. }
  83. public function getConfigName(): ?string
  84. {
  85. return $this->configName;
  86. }
  87. public function setConfigName(string $configName): static
  88. {
  89. $this->configName = $configName;
  90. return $this;
  91. }
  92. /**
  93. * @return Collection<int, Enterprise>
  94. */
  95. public function getEnterprises(): Collection
  96. {
  97. return $this->enterprises;
  98. }
  99. public function addEnterprise(Enterprise $enterprise): static
  100. {
  101. if (!$this->enterprises->contains($enterprise)) {
  102. $this->enterprises->add($enterprise);
  103. $enterprise->setTu($this);
  104. }
  105. return $this;
  106. }
  107. public function removeEnterprise(Enterprise $enterprise): static
  108. {
  109. if ($this->enterprises->removeElement($enterprise)) {
  110. // set the owning side to null (unless already changed)
  111. if ($enterprise->getTu() === $this) {
  112. $enterprise->setTu(null);
  113. }
  114. }
  115. return $this;
  116. }
  117. /**
  118. * @return Collection<int, User>
  119. */
  120. public function getUsers(): Collection
  121. {
  122. return $this->users;
  123. }
  124. public function addUser(User $user): static
  125. {
  126. if (!$this->users->contains($user)) {
  127. $this->users->add($user);
  128. $user->setTu($this);
  129. }
  130. return $this;
  131. }
  132. public function removeUser(User $user): static
  133. {
  134. if ($this->users->removeElement($user)) {
  135. // set the owning side to null (unless already changed)
  136. if ($user->getTu() === $this) {
  137. $user->setTu(null);
  138. }
  139. }
  140. return $this;
  141. }
  142. public function getSenderEmail(): ?string
  143. {
  144. return $this->senderEmail;
  145. }
  146. public function setSenderEmail(?string $senderEmail): static
  147. {
  148. $this->senderEmail = $senderEmail;
  149. return $this;
  150. }
  151. public function getSenderName(): ?string
  152. {
  153. return $this->senderName;
  154. }
  155. public function setSenderName(?string $senderName): static
  156. {
  157. $this->senderName = $senderName;
  158. return $this;
  159. }
  160. public function getSenderEmailAddress(): ?EmailAddress
  161. {
  162. $senderEmail = null;
  163. if(!empty($this->senderEmail) && InputValidator::emailAddressValidation($this->senderEmail)){
  164. if(!empty($this->senderName)){
  165. $senderEmail = new EmailAddress($this->senderEmail, $this->senderName);
  166. } else {
  167. $senderEmail = new EmailAddress($this->senderEmail);
  168. }
  169. }
  170. return $senderEmail;
  171. }
  172. }