src/Entity/ContactList.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\ContactListRepository;
  4. use App\Traits\DateTrait;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use JMS\Serializer\Annotation as Serializer;
  9. use JMS\Serializer\Annotation\Expose;
  10. use JMS\Serializer\Annotation\Groups;
  11. use Symfony\Component\Validator\Constraints as Assert;
  12. /**
  13. * @ORM\Entity(repositoryClass=ContactListRepository::class)(repositoryClass=ContactListRepository::class)
  14. *
  15. * @Serializer\ExclusionPolicy("ALL")
  16. */
  17. class ContactList
  18. {
  19. use DateTrait;
  20. /**
  21. * @ORM\Id
  22. * @ORM\GeneratedValue
  23. * @ORM\Column(type="integer")
  24. *
  25. * @Expose
  26. * @Groups({"contactList"})
  27. */
  28. private ?int $id = NULL;
  29. /**
  30. * @ORM\Column(type="string", length=255)
  31. * @Assert\NotBlank(message="Le nom de la liste de contacts est obligatoire")
  32. *
  33. * @Expose
  34. * @Groups({"contactList"})
  35. */
  36. private ?string $label = NULL;
  37. /**
  38. * @ORM\ManyToMany(targetEntity=User::class, inversedBy="contactLists", cascade={"persist"})
  39. */
  40. private Collection $users;
  41. /**
  42. * @ORM\OneToMany(targetEntity=Newsletter::class, mappedBy="contactList")
  43. */
  44. private Collection $newsletters;
  45. /**
  46. * @ORM\OneToMany(targetEntity=PushWebCampaign::class, mappedBy="contactList")
  47. */
  48. private Collection $pushWebCampaigns;
  49. /**
  50. * @ORM\OneToMany(targetEntity=SmsSpotHitCampaign::class, mappedBy="contactList")
  51. */
  52. private Collection $smsSpotHitCampaigns;
  53. public function __construct()
  54. {
  55. $this->users = new ArrayCollection();
  56. $this->newsletters = new ArrayCollection();
  57. $this->pushWebCampaigns = new ArrayCollection();
  58. $this->smsSpotHitCampaigns = new ArrayCollection();
  59. }
  60. public function __toString(): string
  61. {
  62. return $this->label ?? "";
  63. }
  64. /*
  65. * ============================================================================================
  66. * =============================== FONCTIONS CUSTOM ===========================================
  67. * ============================================================================================
  68. */
  69. public function countNewsletterisProcessingOrProgrammed(): int
  70. {
  71. $i = 0;
  72. foreach($this->getNewsletters() as $newsletter)
  73. {
  74. if($newsletter instanceof Newsletter && in_array($newsletter->getStatus(), [
  75. Newsletter::STATUS_PROCESSING,
  76. Newsletter::STATUS_PROGRAMMED,
  77. ]))
  78. {
  79. $i++;
  80. }
  81. }
  82. return $i;
  83. }
  84. /*
  85. * ============================================================================================
  86. * ============================== FIN FONCTIONS CUSTOM ========================================
  87. * ============================================================================================
  88. */
  89. /**
  90. * @return Collection|Newsletter[]
  91. */
  92. public function getNewsletters(): Collection
  93. {
  94. return $this->newsletters;
  95. }
  96. public function getId(): ?int
  97. {
  98. return $this->id;
  99. }
  100. public function getLabel(): ?string
  101. {
  102. return $this->label;
  103. }
  104. public function setLabel(string $label): self
  105. {
  106. $this->label = $label;
  107. return $this;
  108. }
  109. /**
  110. * @return Collection|User[]
  111. */
  112. public function getUsers(): Collection
  113. {
  114. return $this->users;
  115. }
  116. public function addUser(User $user): self
  117. {
  118. if(!$this->users->contains($user))
  119. {
  120. $this->users[] = $user;
  121. }
  122. return $this;
  123. }
  124. public function removeUser(User $user): self
  125. {
  126. $this->users->removeElement($user);
  127. return $this;
  128. }
  129. public function addNewsletter(Newsletter $newsletter): self
  130. {
  131. if(!$this->newsletters->contains($newsletter))
  132. {
  133. $this->newsletters[] = $newsletter;
  134. $newsletter->setContactList($this);
  135. }
  136. return $this;
  137. }
  138. public function removeNewsletter(Newsletter $newsletter): self
  139. {
  140. if($this->newsletters->removeElement($newsletter))
  141. {
  142. // set the owning side to null (unless already changed)
  143. if($newsletter->getContactList() === $this)
  144. {
  145. $newsletter->setContactList(NULL);
  146. }
  147. }
  148. return $this;
  149. }
  150. /**
  151. * @return Collection<int, PushWebCampaign>
  152. */
  153. public function getPushWebCampaigns(): Collection
  154. {
  155. return $this->pushWebCampaigns;
  156. }
  157. public function addPushWebCampaign(PushWebCampaign $pushWebCampaign): self
  158. {
  159. if(!$this->pushWebCampaigns->contains($pushWebCampaign))
  160. {
  161. $this->pushWebCampaigns[] = $pushWebCampaign;
  162. $pushWebCampaign->setContactList($this);
  163. }
  164. return $this;
  165. }
  166. public function removePushWebCampaign(PushWebCampaign $pushWebCampaign): self
  167. {
  168. if($this->pushWebCampaigns->removeElement($pushWebCampaign))
  169. {
  170. // set the owning side to null (unless already changed)
  171. if($pushWebCampaign->getContactList() === $this)
  172. {
  173. $pushWebCampaign->setContactList(null);
  174. }
  175. }
  176. return $this;
  177. }
  178. /**
  179. * @return Collection<int, SmsSpotHitCampaign>
  180. */
  181. public function getSmsSpotHitCampaigns(): Collection
  182. {
  183. return $this->smsSpotHitCampaigns;
  184. }
  185. public function addSmsSpotHitCampaign(SmsSpotHitCampaign $smsSpotHitCampaign): self
  186. {
  187. if(!$this->smsSpotHitCampaigns->contains($smsSpotHitCampaign))
  188. {
  189. $this->smsSpotHitCampaigns[] = $smsSpotHitCampaign;
  190. $smsSpotHitCampaign->setContactList($this);
  191. }
  192. return $this;
  193. }
  194. public function removeSmsSpotHitCampaign(SmsSpotHitCampaign $smsSpotHitCampaign): self
  195. {
  196. if($this->smsSpotHitCampaigns->removeElement($smsSpotHitCampaign))
  197. {
  198. // set the owning side to null (unless already changed)
  199. if($smsSpotHitCampaign->getContactList() === $this)
  200. {
  201. $smsSpotHitCampaign->setContactList(NULL);
  202. }
  203. }
  204. return $this;
  205. }
  206. }