<?php
namespace App\Entity;
use App\Repository\ContactListRepository;
use App\Traits\DateTrait;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation as Serializer;
use JMS\Serializer\Annotation\Expose;
use JMS\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity(repositoryClass=ContactListRepository::class)(repositoryClass=ContactListRepository::class)
*
* @Serializer\ExclusionPolicy("ALL")
*/
class ContactList
{
use DateTrait;
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*
* @Expose
* @Groups({"contactList"})
*/
private ?int $id = NULL;
/**
* @ORM\Column(type="string", length=255)
* @Assert\NotBlank(message="Le nom de la liste de contacts est obligatoire")
*
* @Expose
* @Groups({"contactList"})
*/
private ?string $label = NULL;
/**
* @ORM\ManyToMany(targetEntity=User::class, inversedBy="contactLists", cascade={"persist"})
*/
private Collection $users;
/**
* @ORM\OneToMany(targetEntity=Newsletter::class, mappedBy="contactList")
*/
private Collection $newsletters;
/**
* @ORM\OneToMany(targetEntity=PushWebCampaign::class, mappedBy="contactList")
*/
private Collection $pushWebCampaigns;
/**
* @ORM\OneToMany(targetEntity=SmsSpotHitCampaign::class, mappedBy="contactList")
*/
private Collection $smsSpotHitCampaigns;
public function __construct()
{
$this->users = new ArrayCollection();
$this->newsletters = new ArrayCollection();
$this->pushWebCampaigns = new ArrayCollection();
$this->smsSpotHitCampaigns = new ArrayCollection();
}
public function __toString(): string
{
return $this->label ?? "";
}
/*
* ============================================================================================
* =============================== FONCTIONS CUSTOM ===========================================
* ============================================================================================
*/
public function countNewsletterisProcessingOrProgrammed(): int
{
$i = 0;
foreach ( $this->getNewsletters() as $newsletter ) {
if ( $newsletter instanceof Newsletter && in_array( $newsletter->getStatus(), [
Newsletter::STATUS_PROCESSING,
Newsletter::STATUS_PROGRAMMED,
] ) ) {
$i++;
}
}
return $i;
}
/*
* ============================================================================================
* ============================== FIN FONCTIONS CUSTOM ========================================
* ============================================================================================
*/
/**
* @return Collection|Newsletter[]
*/
public function getNewsletters(): Collection
{
return $this->newsletters;
}
public function getId(): ?int
{
return $this->id;
}
public function getLabel(): ?string
{
return $this->label;
}
public function setLabel( string $label ): self
{
$this->label = $label;
return $this;
}
/**
* @return Collection|User[]
*/
public function getUsers(): Collection
{
return $this->users;
}
public function addUser( User $user ): self
{
if ( !$this->users->contains( $user ) ) {
$this->users[] = $user;
}
return $this;
}
public function removeUser( User $user ): self
{
$this->users->removeElement( $user );
return $this;
}
public function addNewsletter( Newsletter $newsletter ): self
{
if ( !$this->newsletters->contains( $newsletter ) ) {
$this->newsletters[] = $newsletter;
$newsletter->setContactList( $this );
}
return $this;
}
public function removeNewsletter( Newsletter $newsletter ): self
{
if ( $this->newsletters->removeElement( $newsletter ) ) {
// set the owning side to null (unless already changed)
if ( $newsletter->getContactList() === $this ) {
$newsletter->setContactList( NULL );
}
}
return $this;
}
/**
* @return Collection<int, PushWebCampaign>
*/
public function getPushWebCampaigns(): Collection
{
return $this->pushWebCampaigns;
}
public function addPushWebCampaign(PushWebCampaign $pushWebCampaign): self
{
if (!$this->pushWebCampaigns->contains($pushWebCampaign)) {
$this->pushWebCampaigns[] = $pushWebCampaign;
$pushWebCampaign->setContactList($this);
}
return $this;
}
public function removePushWebCampaign(PushWebCampaign $pushWebCampaign): self
{
if ($this->pushWebCampaigns->removeElement($pushWebCampaign)) {
// set the owning side to null (unless already changed)
if ($pushWebCampaign->getContactList() === $this) {
$pushWebCampaign->setContactList(null);
}
}
return $this;
}
/**
* @return Collection<int, SmsSpotHitCampaign>
*/
public function getSmsSpotHitCampaigns(): Collection
{
return $this->smsSpotHitCampaigns;
}
public function addSmsSpotHitCampaign(SmsSpotHitCampaign $smsSpotHitCampaign): self
{
if (!$this->smsSpotHitCampaigns->contains($smsSpotHitCampaign)) {
$this->smsSpotHitCampaigns[] = $smsSpotHitCampaign;
$smsSpotHitCampaign->setContactList($this);
}
return $this;
}
public function removeSmsSpotHitCampaign(SmsSpotHitCampaign $smsSpotHitCampaign): self
{
if ($this->pushWebCampaigns->removeElement($smsSpotHitCampaign)) {
// set the owning side to null (unless already changed)
if ($smsSpotHitCampaign->getContactList() === $this) {
$smsSpotHitCampaign->setContactList(NULL);
}
}
return $this;
}
}