src/Flexy/Apps/NewsletterBundle/Entity/NewsletterCompaignLaunch.php line 14

  1. <?php
  2. namespace App\Flexy\Apps\NewsletterBundle\Entity;
  3. use ApiPlatform\Metadata\ApiResource;
  4. use App\Repository\Flexy\Apps\NewsletterBundle\Entity\NewsletterCompaignLaunchRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\DBAL\Types\Types;
  8. use Doctrine\ORM\Mapping as ORM;
  9. #[ORM\Entity(repositoryClassNewsletterCompaignLaunchRepository::class)]
  10. #[ApiResource]
  11. class NewsletterCompaignLaunch
  12. {
  13.     #[ORM\Id]
  14.     #[ORM\GeneratedValue]
  15.     #[ORM\Column]
  16.     private ?int $id null;
  17.     #[ORM\ManyToOne(inversedBy'newsletterCompaignLaunches',cascade:["persist"])]
  18.     #[ORM\JoinColumn(nullablefalse)]
  19.     private ?NewsletterCompaign $newsletterCompaign null;
  20.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  21.     private ?\DateTimeInterface $createdAt null;
  22.     #[ORM\OneToMany(mappedBy'newsletterCompaignLaunch'targetEntityNewsletterMailLog::class, orphanRemovaltrue,cascade:["persist"])]
  23.     private Collection $newsletterMailLogs;
  24.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  25.     private ?string $description null;
  26.     public function __construct()
  27.     {
  28.         $this->newsletterMailLogs = new ArrayCollection();
  29.         $this->createdAt = new \DateTime();
  30.     }
  31.     public function __toString()
  32.     {
  33.         $description $this->description "(".$this->description.")" "";
  34.         return $this->newsletterCompaign->getName(). " ".$description;
  35.     }
  36.     
  37.     public function getId(): ?int
  38.     {
  39.         return $this->id;
  40.     }
  41.     public function getNewsletterCompaign(): ?NewsletterCompaign
  42.     {
  43.         return $this->newsletterCompaign;
  44.     }
  45.     public function setNewsletterCompaign(?NewsletterCompaign $newsletterCompaign): static
  46.     {
  47.         $this->newsletterCompaign $newsletterCompaign;
  48.         return $this;
  49.     }
  50.     public function getCreatedAt(): ?\DateTimeInterface
  51.     {
  52.         return $this->createdAt;
  53.     }
  54.     public function setCreatedAt(?\DateTimeInterface $createdAt): static
  55.     {
  56.         $this->createdAt $createdAt;
  57.         return $this;
  58.     }
  59.     /**
  60.      * @return Collection<int, NewsletterMailLog>
  61.      */
  62.     public function getNewsletterMailLogs(): Collection
  63.     {
  64.         return $this->newsletterMailLogs;
  65.     }
  66.     public function addNewsletterMailLog(NewsletterMailLog $newsletterMailLog): static
  67.     {
  68.         if (!$this->newsletterMailLogs->contains($newsletterMailLog)) {
  69.             $this->newsletterMailLogs->add($newsletterMailLog);
  70.             $newsletterMailLog->setNewsletterCompaignLaunch($this);
  71.         }
  72.         return $this;
  73.     }
  74.     public function removeNewsletterMailLog(NewsletterMailLog $newsletterMailLog): static
  75.     {
  76.         if ($this->newsletterMailLogs->removeElement($newsletterMailLog)) {
  77.             // set the owning side to null (unless already changed)
  78.             if ($newsletterMailLog->getNewsletterCompaignLaunch() === $this) {
  79.                 $newsletterMailLog->setNewsletterCompaignLaunch(null);
  80.             }
  81.         }
  82.         return $this;
  83.     }
  84.     public function getDescription(): ?string
  85.     {
  86.         return $this->description;
  87.     }
  88.     public function setDescription(?string $description): static
  89.     {
  90.         $this->description $description;
  91.         return $this;
  92.     }
  93.     public function getSuccessMails()
  94.     {
  95.         $result 0;
  96.         foreach ($this->newsletterMailLogs as $mailLog) {
  97.             if($mailLog->getStatus() == "success"){
  98.                 $result++;
  99.             }
  100.         }
  101.         return $result;
  102.     }
  103.     public function getFailedMails()
  104.     {
  105.         $result 0;
  106.         foreach ($this->newsletterMailLogs as $mailLog) {
  107.             if($mailLog->getStatus() == "failed"){
  108.                 $result++;
  109.             }
  110.         }
  111.         return $result;
  112.     }
  113.     public function getOpenedMails()
  114.     {
  115.         $result 0;
  116.         foreach ($this->newsletterMailLogs as $mailLog) {
  117.             if($mailLog->isOpened()){
  118.                 $result++;
  119.             }
  120.         }
  121.         return $result;
  122.     }
  123. }