src/Entity/Email/EmailMessageStatus.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Email;
  3. use App\Entity\Email\EmailMessage;
  4. use App\Enum\EmailMessageStatusEnum;
  5. use App\Repository\Email\EmailMessageStatusRepository;
  6. use DateTime;
  7. use DateTimeInterface;
  8. use Doctrine\ORM\Mapping as ORM;
  9. /**
  10.  * @ORM\Table(name="vulco_email_message_status")
  11.  * @ORM\Entity(repositoryClass=EmailMessageStatusRepository::class)
  12.  *
  13.  * @see https://developers.brevo.com/docs/transactional-webhooks
  14.  * @see https://developers.brevo.com/reference/gettransacemailcontent
  15.  */
  16. class EmailMessageStatus
  17. {
  18.     /**
  19.      * @ORM\Id
  20.      * @ORM\GeneratedValue
  21.      * @ORM\Column(type="integer")
  22.      */
  23.     protected int $id;
  24.     /**
  25.      * @ORM\ManyToOne(targetEntity="EmailMessage", inversedBy="statuses")
  26.      */
  27.     private EmailMessage $emailMessage;
  28.     /**
  29.      * @ORM\Column(type="string", length=255, nullable=false, options={"default": "unknown"})
  30.      */
  31.     private string $status EmailMessageStatusEnum::UNKNOWN;
  32.     /**
  33.      * @ORM\Column(type="datetime")
  34.      */
  35.     private DateTimeInterface $date;
  36.     /**
  37.      * @ORM\Column(type="string", length=1023, nullable=true)
  38.      */
  39.     private ?string $link null// URL accessed by recipient
  40.     /**
  41.      * @ORM\Column(type="string", length=255, nullable=true)
  42.      */
  43.     private ?string $deviceUsed null// Details about the device from which the action originated (DESKTOP, MOBILE, ...)
  44.     /**
  45.      * @ORM\Column(type="string", length=255, nullable=true)
  46.      */
  47.     private ?string $reason null// The reason the message has been deferred, soft_bounced or hard_bounce
  48.     public function __construct(
  49.         string $status EmailMessageStatusEnum::UNKNOWN,
  50.         DateTimeInterface $date = new DateTime())
  51.     {
  52.         $this->status $status;
  53.         $this->date $date;
  54.     }
  55.     public function getId(): int
  56.     {
  57.         return $this->id;
  58.     }
  59.     public function getEmailMessage(): EmailMessage
  60.     {
  61.         return $this->emailMessage;
  62.     }
  63.     public function setEmailMessage(EmailMessage $emailMessage): self
  64.     {
  65.         $this->emailMessage $emailMessage;
  66.         return $this;
  67.     }
  68.     public function getStatus(): string
  69.     {
  70.         return $this->status;
  71.     }
  72.     public function getStatusAsTranslationKey(): string
  73.     {
  74.         if (array_key_exists($this->statusEmailMessageStatusEnum::getTranslations())) {
  75.             return EmailMessageStatusEnum::getTranslations()[$this->status];
  76.         }
  77.         return $this->status;
  78.     }
  79.     public function setStatus(string $status): self
  80.     {
  81.         $this->status $status;
  82.         return $this;
  83.     }
  84.     public function getDate(): DateTimeInterface
  85.     {
  86.         return $this->date;
  87.     }
  88.     public function setDate(DateTimeInterface $date): self
  89.     {
  90.         $this->date $date;
  91.         return $this;
  92.     }
  93.     public function getLink(): ?string
  94.     {
  95.         return $this->link;
  96.     }
  97.     public function setLink(?string $link): EmailMessageStatus
  98.     {
  99.         $this->link $link;
  100.         return $this;
  101.     }
  102.     public function getDeviceUsed(): ?string
  103.     {
  104.         return $this->deviceUsed;
  105.     }
  106.     public function setDeviceUsed(?string $deviceUsed): self
  107.     {
  108.         $this->deviceUsed $deviceUsed;
  109.         return $this;
  110.     }
  111.     public function getReason(): ?string
  112.     {
  113.         return $this->reason;
  114.     }
  115.     public function setReason(?string $reason): self
  116.     {
  117.         $this->reason $reason;
  118.         return $this;
  119.     }
  120.     public function isUnknown(): bool
  121.     {
  122.         if ($this->isSent()
  123.             || $this->isClicked()
  124.             || $this->isDeferred()
  125.             || $this->isDelivered()
  126.             || $this->isSoftBounced()
  127.             || $this->isHardBounced()
  128.             || $this->isSpam()
  129.             || $this->isOpened()
  130.             || $this->isInvalidEmail()
  131.             || $this->isBlocked()
  132.             || $this->isError()
  133.         ) {
  134.             return false;
  135.         }
  136.         return true;
  137.     }
  138.     public function isSent(): bool
  139.     {
  140.         if (EmailMessageStatusEnum::SENT === $this->getStatus()) {
  141.             return true;
  142.         }
  143.         return false;
  144.     }
  145.     public function isClicked(): bool
  146.     {
  147.         if (EmailMessageStatusEnum::CLICKED === $this->getStatus()) {
  148.             return true;
  149.         }
  150.         return false;
  151.     }
  152.     public function isDeferred(): bool
  153.     {
  154.         if (EmailMessageStatusEnum::DEFERRED === $this->getStatus()) {
  155.             return true;
  156.         }
  157.         return false;
  158.     }
  159.     public function isDelivered(): bool
  160.     {
  161.         if (EmailMessageStatusEnum::DELIVERED === $this->getStatus()) {
  162.             return true;
  163.         }
  164.         return false;
  165.     }
  166.     public function isSoftBounced(): bool
  167.     {
  168.         if (EmailMessageStatusEnum::SOFT_BOUNCED === $this->getStatus()) {
  169.             return true;
  170.         }
  171.         return false;
  172.     }
  173.     public function isHardBounced(): bool
  174.     {
  175.         if (EmailMessageStatusEnum::HARD_BOUNCED === $this->getStatus()) {
  176.             return true;
  177.         }
  178.         return false;
  179.     }
  180.     public function isSpam(): bool
  181.     {
  182.         if (EmailMessageStatusEnum::SPAM === $this->getStatus()) {
  183.             return true;
  184.         }
  185.         return false;
  186.     }
  187.     public function isOpened(): bool
  188.     {
  189.         if (EmailMessageStatusEnum::OPENED === $this->getStatus()) {
  190.             return true;
  191.         }
  192.         return false;
  193.     }
  194.     public function isInvalidEmail(): bool
  195.     {
  196.         if (EmailMessageStatusEnum::INVALID_EMAIL === $this->getStatus()) {
  197.             return true;
  198.         }
  199.         return false;
  200.     }
  201.     public function isBlocked(): bool
  202.     {
  203.         if (EmailMessageStatusEnum::BLOCKED === $this->getStatus()) {
  204.             return true;
  205.         }
  206.         return false;
  207.     }
  208.     public function isError(): bool
  209.     {
  210.         if (EmailMessageStatusEnum::ERROR === $this->getStatus()) {
  211.             return true;
  212.         }
  213.         return false;
  214.     }
  215. }