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. if ( $newsletter instanceof Newsletter && in_array( $newsletter->getStatus(), [
  74. Newsletter::STATUS_PROCESSING,
  75. Newsletter::STATUS_PROGRAMMED,
  76. ] ) ) {
  77. $i++;
  78. }
  79. }
  80. return $i;
  81. }
  82. /*
  83. * ============================================================================================
  84. * ============================== FIN FONCTIONS CUSTOM ========================================
  85. * ============================================================================================
  86. */
  87. /**
  88. * @return Collection|Newsletter[]
  89. */
  90. public function getNewsletters(): Collection
  91. {
  92. return $this->newsletters;
  93. }
  94. public function getId(): ?int
  95. {
  96. return $this->id;
  97. }
  98. public function getLabel(): ?string
  99. {
  100. return $this->label;
  101. }
  102. public function setLabel( string $label ): self
  103. {
  104. $this->label = $label;
  105. return $this;
  106. }
  107. /**
  108. * @return Collection|User[]
  109. */
  110. public function getUsers(): Collection
  111. {
  112. return $this->users;
  113. }
  114. public function addUser( User $user ): self
  115. {
  116. if ( !$this->users->contains( $user ) ) {
  117. $this->users[] = $user;
  118. }
  119. return $this;
  120. }
  121. public function removeUser( User $user ): self
  122. {
  123. $this->users->removeElement( $user );
  124. return $this;
  125. }
  126. public function addNewsletter( Newsletter $newsletter ): self
  127. {
  128. if ( !$this->newsletters->contains( $newsletter ) ) {
  129. $this->newsletters[] = $newsletter;
  130. $newsletter->setContactList( $this );
  131. }
  132. return $this;
  133. }
  134. public function removeNewsletter( Newsletter $newsletter ): self
  135. {
  136. if ( $this->newsletters->removeElement( $newsletter ) ) {
  137. // set the owning side to null (unless already changed)
  138. if ( $newsletter->getContactList() === $this ) {
  139. $newsletter->setContactList( NULL );
  140. }
  141. }
  142. return $this;
  143. }
  144. /**
  145. * @return Collection<int, PushWebCampaign>
  146. */
  147. public function getPushWebCampaigns(): Collection
  148. {
  149. return $this->pushWebCampaigns;
  150. }
  151. public function addPushWebCampaign(PushWebCampaign $pushWebCampaign): self
  152. {
  153. if (!$this->pushWebCampaigns->contains($pushWebCampaign)) {
  154. $this->pushWebCampaigns[] = $pushWebCampaign;
  155. $pushWebCampaign->setContactList($this);
  156. }
  157. return $this;
  158. }
  159. public function removePushWebCampaign(PushWebCampaign $pushWebCampaign): self
  160. {
  161. if ($this->pushWebCampaigns->removeElement($pushWebCampaign)) {
  162. // set the owning side to null (unless already changed)
  163. if ($pushWebCampaign->getContactList() === $this) {
  164. $pushWebCampaign->setContactList(null);
  165. }
  166. }
  167. return $this;
  168. }
  169. /**
  170. * @return Collection<int, SmsSpotHitCampaign>
  171. */
  172. public function getSmsSpotHitCampaigns(): Collection
  173. {
  174. return $this->smsSpotHitCampaigns;
  175. }
  176. public function addSmsSpotHitCampaign(SmsSpotHitCampaign $smsSpotHitCampaign): self
  177. {
  178. if (!$this->smsSpotHitCampaigns->contains($smsSpotHitCampaign)) {
  179. $this->smsSpotHitCampaigns[] = $smsSpotHitCampaign;
  180. $smsSpotHitCampaign->setContactList($this);
  181. }
  182. return $this;
  183. }
  184. public function removeSmsSpotHitCampaign(SmsSpotHitCampaign $smsSpotHitCampaign): self
  185. {
  186. if ($this->pushWebCampaigns->removeElement($smsSpotHitCampaign)) {
  187. // set the owning side to null (unless already changed)
  188. if ($smsSpotHitCampaign->getContactList() === $this) {
  189. $smsSpotHitCampaign->setContactList(NULL);
  190. }
  191. }
  192. return $this;
  193. }
  194. }