<?php
namespace App\Entity;
use App\Repository\EmailRecipientRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: EmailRecipientRepository::class)]
#[ORM\Table(name: 'email_message_recipients')]
class EmailRecipient extends BaseEntity
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private ?int $id = null;
#[ORM\ManyToOne(targetEntity: EmailMessage::class, inversedBy: 'recipients')]
#[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
private ?EmailMessage $emailMessage = null;
#[ORM\Column(length: 255)]
private string $recipientEmail;
#[ORM\Column(length: 64, unique: true)]
private string $openToken;
#[ORM\Column(type: 'boolean')]
private bool $opened = false;
#[ORM\Column(type: 'datetime_immutable', nullable: true)]
private ?\DateTimeImmutable $firstOpenedAt = null;
#[ORM\Column(type: 'datetime_immutable', nullable: true)]
private ?\DateTimeImmutable $lastOpenedAt = null;
#[ORM\Column(type: 'integer')]
private int $openCount = 0;
#[ORM\Column(length: 255, nullable: true)]
private ?string $lastOpenedIpHash = null;
#[ORM\Column(length: 512, nullable: true)]
private ?string $lastOpenedUserAgent = null;
/**
* @var Collection<int, EmailOpenEvent>
*/
#[ORM\OneToMany(mappedBy: 'recipient', targetEntity: EmailOpenEvent::class, cascade: ['persist'], orphanRemoval: true)]
private Collection $openEvents;
public function __construct()
{
$this->openEvents = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getEmailMessage(): ?EmailMessage
{
return $this->emailMessage;
}
public function setEmailMessage(?EmailMessage $emailMessage): self
{
$this->emailMessage = $emailMessage;
return $this;
}
public function getRecipientEmail(): string
{
return $this->recipientEmail;
}
public function setRecipientEmail(string $recipientEmail): self
{
$this->recipientEmail = $recipientEmail;
return $this;
}
public function getOpenToken(): string
{
return $this->openToken;
}
public function setOpenToken(string $openToken): self
{
$this->openToken = $openToken;
return $this;
}
public function isOpened(): bool
{
return $this->opened;
}
public function setOpened(bool $opened): self
{
$this->opened = $opened;
return $this;
}
public function getFirstOpenedAt(): ?\DateTimeImmutable
{
return $this->firstOpenedAt;
}
public function setFirstOpenedAt(?\DateTimeImmutable $firstOpenedAt): self
{
$this->firstOpenedAt = $firstOpenedAt;
return $this;
}
public function getLastOpenedAt(): ?\DateTimeImmutable
{
return $this->lastOpenedAt;
}
public function setLastOpenedAt(?\DateTimeImmutable $lastOpenedAt): self
{
$this->lastOpenedAt = $lastOpenedAt;
return $this;
}
public function getOpenCount(): int
{
return $this->openCount;
}
public function setOpenCount(int $openCount): self
{
$this->openCount = $openCount;
return $this;
}
public function incrementOpenCount(): self
{
$this->openCount++;
return $this;
}
public function getLastOpenedIpHash(): ?string
{
return $this->lastOpenedIpHash;
}
public function setLastOpenedIpHash(?string $lastOpenedIpHash): self
{
$this->lastOpenedIpHash = $lastOpenedIpHash;
return $this;
}
public function getLastOpenedUserAgent(): ?string
{
return $this->lastOpenedUserAgent;
}
public function setLastOpenedUserAgent(?string $lastOpenedUserAgent): self
{
$this->lastOpenedUserAgent = $lastOpenedUserAgent;
return $this;
}
/**
* @return Collection<int, EmailOpenEvent>
*/
public function getOpenEvents(): Collection
{
return $this->openEvents;
}
public function addOpenEvent(EmailOpenEvent $openEvent): self
{
if (!$this->openEvents->contains($openEvent)) {
$this->openEvents->add($openEvent);
$openEvent->setRecipient($this);
}
return $this;
}
public function removeOpenEvent(EmailOpenEvent $openEvent): self
{
if ($this->openEvents->removeElement($openEvent)) {
if ($openEvent->getRecipient() === $this) {
$openEvent->setRecipient(null);
}
}
return $this;
}
}