<?php
namespace App\Entity;
use App\Repository\EmailingClientCampaignRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: EmailingClientCampaignRepository::class)]
class EmailingClientCampaign
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private $id;
#[ORM\Column(type: 'string', length: 255)]
private $name;
#[ORM\ManyToMany(targetEntity: EmailingClientList::class, inversedBy: 'campaigns')]
private $diffusionLists;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $object;
#[ORM\Column(type: 'json', nullable: true)]
private $mjmlStructure = [];
#[ORM\Column(type: 'datetime', nullable: true)]
private $sendDate;
#[ORM\Column(type: 'string', length: 255)]
private $status;
#[ORM\ManyToOne(targetEntity: AccountingFirm::class, inversedBy: 'emailingClientCampaigns')]
private $accountingFirm;
#[ORM\OneToMany(mappedBy: 'emailingClientCampaign', targetEntity: MailingTask::class)]
private $mailingTask;
#[ORM\Column(type: 'integer', nullable: true)]
private $tokenUsed;
#[ORM\ManyToOne(targetEntity: SatisfactionClientSurvey::class, inversedBy: 'surveys')]
private $satisfactionClientSurvey;
#[ORM\ManyToOne(targetEntity: Survey::class, inversedBy: 'surveys')]
private $survey;
#[ORM\Column(type: 'json', nullable: true)]
private ?array $collaboratorsData = null;
#[ORM\Column(type: 'float', nullable: true)]
private $openRate;
#[ORM\Column(type: 'float', nullable: true)]
private $clickRate;
#[ORM\Column(type: 'float', nullable: true)]
private $unsubscribeRate;
#[ORM\Column(type: 'float', nullable: true)]
private $bounceRate;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $mailjetId;
#[ORM\Column(type: 'integer', nullable: true)]
private $deliveredCount;
#[ORM\Column(type: 'datetime_immutable', nullable: true)]
private ?\DateTimeImmutable $statsUpdatedAt = null;
#[ORM\Column(type: 'json', nullable: true)]
private $selectedCategories = [];
#[ORM\Column(type: 'json', nullable: true)]
private $selectedTags = [];
#[ORM\Column(type: 'json', nullable: true)]
private $widget = [];
public function __construct()
{
$this->mailingTask = new ArrayCollection();
$this->diffusionLists = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getCollaboratorsData(): ?array
{
return $this->collaboratorsData;
}
public function setCollaboratorsData(?array $collaboratorsData): self
{
$this->collaboratorsData = $collaboratorsData;
return $this;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
/**
* @return Collection<int, EmailingClientList>
*/
public function getDiffusionLists(): Collection
{
return $this->diffusionLists;
}
public function addDiffusionList(EmailingClientList $diffusionList): self
{
if (!$this->diffusionLists->contains($diffusionList)) {
$this->diffusionLists[] = $diffusionList;
}
return $this;
}
public function removeDiffusionList(EmailingClientList $diffusionList): self
{
$this->diffusionLists->removeElement($diffusionList);
return $this;
}
public function clearDiffusionLists(): self
{
$this->diffusionLists->clear();
return $this;
}
public function getObject(): ?string
{
return $this->object;
}
public function setObject(?string $object): self
{
$this->object = $object;
return $this;
}
public function getMjmlStructure(): ?array
{
return $this->mjmlStructure;
}
public function setMjmlStructure(?array $mjmlStructure): self
{
$this->mjmlStructure = $mjmlStructure;
return $this;
}
public function getSendDate(): ?\DateTime
{
return $this->sendDate;
}
public function setSendDate(?\DateTime $sendDate): self
{
$this->sendDate = $sendDate;
return $this;
}
public function getStatus(): ?string
{
return $this->status;
}
public function setStatus(string $status): self
{
$this->status = $status;
return $this;
}
public function getAccountingFirm(): ?AccountingFirm
{
return $this->accountingFirm;
}
public function setAccountingFirm(?AccountingFirm $accountingFirm): self
{
$this->accountingFirm = $accountingFirm;
return $this;
}
/**
* @return Collection<int, MailingTask>
*/
public function getMailingTask(): Collection
{
return $this->mailingTask;
}
public function addMailingTask(MailingTask $mailingTask): self
{
if (!$this->mailingTask->contains($mailingTask)) {
$this->mailingTask[] = $mailingTask;
$mailingTask->setEmailingClientCampaign($this);
}
return $this;
}
public function removeMailingTask(MailingTask $mailingTask): self
{
if ($this->mailingTask->removeElement($mailingTask)) {
// set the owning side to null (unless already changed)
if ($mailingTask->getEmailingClientCampaign() === $this) {
$mailingTask->setEmailingClientCampaign(null);
}
}
return $this;
}
public function getTokenUsed(): ?int
{
return $this->tokenUsed;
}
public function setTokenUsed(?int $tokenUsed): self
{
$this->tokenUsed = $tokenUsed;
return $this;
}
public function getSurvey(): ?Survey
{
return $this->survey;
}
public function setSurvey(?Survey $survey): self
{
$this->survey = $survey;
return $this;
}
public function getSatisfactionClientSurvey(): ?SatisfactionClientSurvey
{
return $this->satisfactionClientSurvey;
}
public function setSatisfactionClientSurvey(SatisfactionClientSurvey $satisfactionClientSurvey): self
{
$this->satisfactionClientSurvey = $satisfactionClientSurvey;
return $this;
}
public function getOpenRate(): ?float
{
return $this->openRate;
}
public function setOpenRate(?float $openRate): self
{
$this->openRate = $openRate;
return $this;
}
public function getClickRate(): ?float
{
return $this->clickRate;
}
public function setClickRate(?float $clickRate): self
{
$this->clickRate = $clickRate;
return $this;
}
public function getUnsubscribeRate(): ?float
{
return $this->unsubscribeRate;
}
public function setUnsubscribeRate(?float $unsubscribeRate): self
{
$this->unsubscribeRate = $unsubscribeRate;
return $this;
}
public function getBounceRate(): ?float
{
return $this->bounceRate;
}
public function setBounceRate(?float $bounceRate): self
{
$this->bounceRate = $bounceRate;
return $this;
}
public function getMailjetId(): ?string
{
return $this->mailjetId;
}
public function setMailjetId(?string $mailjetId): self
{
$this->mailjetId = $mailjetId;
return $this;
}
public function getDeliveredCount(): ?int
{
return $this->deliveredCount;
}
public function setDeliveredCount(?int $deliveredCount): self
{
$this->deliveredCount = $deliveredCount;
return $this;
}
public function getStatsUpdatedAt(): ?\DateTimeImmutable
{
return $this->statsUpdatedAt;
}
public function setStatsUpdatedAt(?\DateTimeImmutable $statsUpdatedAt): self
{
$this->statsUpdatedAt = $statsUpdatedAt;
return $this;
}
public function getSelectedCategories(): ?array
{
return $this->selectedCategories;
}
public function setSelectedCategories(ArrayCollection|array $selectedCategories): self
{
if ($selectedCategories instanceof Collection) {
$this->selectedCategories = $selectedCategories->map(fn($cat) => $cat->getId())->toArray();
} elseif (is_array($selectedCategories)) {
$this->selectedCategories = $selectedCategories;
} else {
$this->selectedCategories = [];
}
return $this;
}
public function getSelectedTags(): ?array
{
return $this->selectedTags;
}
public function setSelectedTags(ArrayCollection|array $selectedTags): self
{
if ($selectedTags instanceof Collection) {
$this->selectedTags = $selectedTags->map(fn($tag) => $tag->getId())->toArray();
} elseif (is_array($selectedTags)) {
$this->selectedTags = $selectedTags;
} else {
$this->selectedTags = [];
}
return $this;
}
public function getWidget(): ?array
{
return $this->widget;
}
public function setWidget(?array $widget): self
{
$this->widget = $widget;
return $this;
}
public function hasWidget(): bool
{
return $this->widget !== null && !empty($this->widget);
}
public function getWidgetType(): ?string
{
return $this->widget['type'] ?? null;
}
public function getWidgetId(): ?int
{
return $this->widget['id'] ?? null;
}
public function setWidgetData(string $type, int $id): self
{
$this->widget = [
'type' => $type,
'id' => $id
];
return $this;
}
}