src/Flexy/Apps/NewsletterBundle/Entity/NewsletterCompaignLaunch.php line 14
<?php
namespace App\Flexy\Apps\NewsletterBundle\Entity;
use ApiPlatform\Metadata\ApiResource;
use App\Repository\Flexy\Apps\NewsletterBundle\Entity\NewsletterCompaignLaunchRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: NewsletterCompaignLaunchRepository::class)]
#[ApiResource]
class NewsletterCompaignLaunch
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\ManyToOne(inversedBy: 'newsletterCompaignLaunches',cascade:["persist"])]
#[ORM\JoinColumn(nullable: false)]
private ?NewsletterCompaign $newsletterCompaign = null;
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $createdAt = null;
#[ORM\OneToMany(mappedBy: 'newsletterCompaignLaunch', targetEntity: NewsletterMailLog::class, orphanRemoval: true,cascade:["persist"])]
private Collection $newsletterMailLogs;
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $description = null;
public function __construct()
{
$this->newsletterMailLogs = new ArrayCollection();
$this->createdAt = new \DateTime();
}
public function __toString()
{
$description = $this->description ? "(".$this->description.")" : "";
return $this->newsletterCompaign->getName(). " ".$description;
}
public function getId(): ?int
{
return $this->id;
}
public function getNewsletterCompaign(): ?NewsletterCompaign
{
return $this->newsletterCompaign;
}
public function setNewsletterCompaign(?NewsletterCompaign $newsletterCompaign): static
{
$this->newsletterCompaign = $newsletterCompaign;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
public function setCreatedAt(?\DateTimeInterface $createdAt): static
{
$this->createdAt = $createdAt;
return $this;
}
/**
* @return Collection<int, NewsletterMailLog>
*/
public function getNewsletterMailLogs(): Collection
{
return $this->newsletterMailLogs;
}
public function addNewsletterMailLog(NewsletterMailLog $newsletterMailLog): static
{
if (!$this->newsletterMailLogs->contains($newsletterMailLog)) {
$this->newsletterMailLogs->add($newsletterMailLog);
$newsletterMailLog->setNewsletterCompaignLaunch($this);
}
return $this;
}
public function removeNewsletterMailLog(NewsletterMailLog $newsletterMailLog): static
{
if ($this->newsletterMailLogs->removeElement($newsletterMailLog)) {
// set the owning side to null (unless already changed)
if ($newsletterMailLog->getNewsletterCompaignLaunch() === $this) {
$newsletterMailLog->setNewsletterCompaignLaunch(null);
}
}
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): static
{
$this->description = $description;
return $this;
}
public function getSuccessMails()
{
$result = 0;
foreach ($this->newsletterMailLogs as $mailLog) {
if($mailLog->getStatus() == "success"){
$result++;
}
}
return $result;
}
public function getFailedMails()
{
$result = 0;
foreach ($this->newsletterMailLogs as $mailLog) {
if($mailLog->getStatus() == "failed"){
$result++;
}
}
return $result;
}
public function getOpenedMails()
{
$result = 0;
foreach ($this->newsletterMailLogs as $mailLog) {
if($mailLog->isOpened()){
$result++;
}
}
return $result;
}
}