<?php
namespace App\Entity;
use App\Repository\App\NotificationRepository;
use App\Validator\Constraints\NotificationUserListFormat;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\File\File;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use App\Validator\NotificationUseInternal;
/**
* @NotificationUseInternal
*
* @ORM\Entity(repositoryClass=NotificationRepository::class)
*
* @Vich\Uploadable
*
* @UniqueEntity(fields={"campaignName"}, message="notification.campaign_name.already_exist")
*/
class Notification
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
* @Assert\Length(max=255)
*/
private $campaignName;
/**
* @ORM\Column(type="datetime")
*/
private $createdAt;
/**
* Used to trigger doctrine hydration when uploading files with VichUploader
* @see https://github.com/dustin10/VichUploaderBundle/issues/297
*
* @ORM\Column(type="datetime", nullable=true)
*/
private $updatedAt;
/**
* @ORM\Column(type="string", length=200)
* @Assert\Length(max=200)
*/
private $messageName;
/**
* @ORM\Column(type="text")
* @Assert\NotBlank ()
*/
private $messageBody;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $image;
/**
* @Vich\UploadableField(mapping="notification", fileNameProperty="image")
* @Assert\File(
* mimeTypes = {"image/jpeg", "image/png"},
* mimeTypesMessage = "Le fichier n'est pas au bon format. ( Seulement jpg, jpeg, ou png )"
* )
* @var File
*/
protected $imageFile;
/**
* @ORM\Column(type="boolean", options = { "default" : false })
*/
private $sendEmail;
/**
* @ORM\Column(type="boolean", options = { "default" : false })
*/
private $setPopUp;
/**
* @ORM\Column(type="datetime", options = { "default" : "CURRENT_TIMESTAMP" })
* @Assert\GreaterThanOrEqual("today", message="La date de début ne peut pas être inférieure à la date du jour en cours", groups={"create", "update_unpublishedAndInactive"})
* @Assert\Expression(
* "this.getEndAt() > this.getStartAt()",
* message="La date de début doit être antérieure à la date de fin"
* )
*/
private $startAt;
/**
* @ORM\Column(type="datetime")
* @Assert\Expression(
* "this.getEndAt() > this.getStartAt()",
* message="La date de fin doit être postérieure à la date de début"
* )
* @Assert\GreaterThanOrEqual ("today", message="La date ne peut pas être inférieure à la date du jour")
*/
private $endAt;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $targetedUsersFilename = '';
/**
* @Vich\UploadableField(mapping="notification_excel_file", fileNameProperty="targetedUsersFilename")
* @Assert\File(
* mimeTypes = {"application/vnd.ms-excel", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"},
* mimeTypesMessage = "Le fichier n'est pas au bon format. ( Seulement xls, ou xlsx )"
* )
* @var File
* @NotificationUserListFormat
*/
private $targetedUsersUploadedFile;
/**
* @ORM\Column(type="boolean", nullable=true, options = { "default": false})
*/
private $requiredCheckboxToggle;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Assert\Expression(
* "(this.getRequiredCheckboxToggle() and value) or (!this.getRequiredCheckboxToggle() and !value)",
* message="Ce champs doit être renseigné si l'option case à cocher est activée"
* )
*/
private $requiredCheckboxText;
/**
* @ORM\Column(type="boolean", nullable=true, options = { "default": false})
*/
private $requiredUserChoiceToggle;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Assert\Expression(
* "(this.getRequiredUserChoiceToggle() and value) or (!this.getRequiredUserChoiceToggle() and !value)",
* message="Ce champs doit être renseigné si l'option boutons de validation est activée"
* )
*/
private $requiredUserChoiceAcceptanceText;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Assert\Expression(
* "(this.getRequiredUserChoiceToggle() and value) or (!this.getRequiredUserChoiceToggle() and !value)",
* message="Ce champs doit être renseigné si l'option boutons de validation est activée"
* )
*/
private $requiredUserChoiceRefusalText;
/**
* @ORM\OneToMany(targetEntity=NotificationStatistics::class, mappedBy="notification", orphanRemoval=true)
*/
private $notificationStatistics;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $insistenceCoefficient;
/**
* @ORM\Column(type="string", length=255)
*/
private $author;
/**
* @ORM\Column(type="boolean")
*/
private $published;
/**
* @ORM\Column(type="string", length=255)
*/
private $seeLaterButtonText = "Voir plus tard";
/**
* @ORM\Column(type="boolean", name="use_internal", nullable=true, options={"default": false})
*/
private ?bool $useInternal = false;
public function __construct()
{
$this->createdAt = new \DateTime();
$this->startAt = new \DateTime();
$this->endAt = new \DateTime('tomorrow');
$this->notificationStatistics = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getCampaignName(): ?string
{
return $this->campaignName;
}
public function setCampaignName(string $campaignName): self
{
$this->campaignName = $campaignName;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getMessageName(): ?string
{
return $this->messageName;
}
public function setMessageName(string $messageName): self
{
$this->messageName = $messageName;
return $this;
}
public function getMessageBody(): ?string
{
return $this->messageBody;
}
public function setMessageBody(string $messageBody): self
{
$this->messageBody = $messageBody;
return $this;
}
public function getImage(): ?string
{
return $this->image;
}
public function setImage(?string $image): self
{
$this->image = $image;
return $this;
}
public function getImageFile(): ?File
{
return $this->imageFile;
}
/**
* @return Dashboard
* @throws \Exception
*
*/
public function setImageFile(?File $imageFile): self
{
$this->imageFile = $imageFile;
if ($imageFile) {
$this->updatedAt = new \DateTime('now');
}
return $this;
}
public function getSendEmail(): ?bool
{
return $this->sendEmail;
}
public function setSendEmail(bool $sendEmail): self
{
$this->sendEmail = $sendEmail;
return $this;
}
public function getSetPopUp(): ?bool
{
return $this->setPopUp;
}
public function setSetPopUp(bool $setPopUp): self
{
$this->setPopUp = $setPopUp;
return $this;
}
public function getStartAt(): ?\DateTimeInterface
{
return $this->startAt;
}
public function setStartAt(?\DateTimeInterface $startAt): self
{
$this->startAt = $startAt;
return $this;
}
public function getEndAt(): ?\DateTimeInterface
{
return $this->endAt;
}
public function setEndAt(?\DateTimeInterface $endAt): self
{
$this->endAt = $endAt;
return $this;
}
public function getTargetedUsersFilename(): ?string
{
return $this->targetedUsersFilename;
}
public function setTargetedUsersFilename(?string $targetedUsersFilename): self
{
$this->targetedUsersFilename = $targetedUsersFilename;
return $this;
}
public function getTargetedUsersUploadedFile(): ?File
{
return $this->targetedUsersUploadedFile;
}
public function setTargetedUsersUploadedFile(?File $targetedUsersUploadedFile): self
{
$this->targetedUsersUploadedFile = $targetedUsersUploadedFile;
if ($targetedUsersUploadedFile) {
$this->updatedAt = new \DateTime();
}
return $this;
}
public function getRequiredCheckboxToggle(): ?bool
{
return $this->requiredCheckboxToggle;
}
public function setRequiredCheckboxToggle(?bool $requiredCheckboxToggle): self
{
$this->requiredCheckboxToggle = $requiredCheckboxToggle;
return $this;
}
public function getRequiredCheckboxText(): ?string
{
return $this->requiredCheckboxText;
}
public function setRequiredCheckboxText(?string $requiredCheckboxText): self
{
$this->requiredCheckboxText = $requiredCheckboxText;
return $this;
}
public function getRequiredUserChoiceToggle(): ?bool
{
return $this->requiredUserChoiceToggle;
}
public function setRequiredUserChoiceToggle(?bool $requiredUserChoiceToggle): self
{
$this->requiredUserChoiceToggle = $requiredUserChoiceToggle;
return $this;
}
public function getRequiredUserChoiceAcceptanceText(): ?string
{
return $this->requiredUserChoiceAcceptanceText;
}
public function setRequiredUserChoiceAcceptanceText(?string $requiredUserChoiceAcceptanceText): self
{
$this->requiredUserChoiceAcceptanceText = $requiredUserChoiceAcceptanceText;
return $this;
}
public function getRequiredUserChoiceRefusalText(): ?string
{
return $this->requiredUserChoiceRefusalText;
}
public function setRequiredUserChoiceRefusalText(?string $requiredUserChoiceRefusalText): self
{
$this->requiredUserChoiceRefusalText = $requiredUserChoiceRefusalText;
return $this;
}
/**
* @return Collection|NotificationStatistics[]
*/
public function getNotificationStatistics(): Collection
{
return $this->notificationStatistics;
}
public function addNotificationStatistic(NotificationStatistics $notificationStatistic): self
{
if (!$this->notificationStatistics->contains($notificationStatistic)) {
$this->notificationStatistics[] = $notificationStatistic;
$notificationStatistic->setNotification($this);
}
return $this;
}
public function removeNotificationStatistic(NotificationStatistics $notificationStatistic): self
{
if ($this->notificationStatistics->removeElement($notificationStatistic)) {
// set the owning side to null (unless already changed)
if ($notificationStatistic->getNotification() === $this) {
$notificationStatistic->setNotification(null);
}
}
return $this;
}
public function getInsistenceCoefficient(): ?int
{
return $this->insistenceCoefficient;
}
public function setInsistenceCoefficient(?int $insistenceCoefficient): self
{
$this->insistenceCoefficient = $insistenceCoefficient;
return $this;
}
public function getAuthor(): ?string
{
return $this->author;
}
public function setAuthor(string $author): self
{
$this->author = $author;
return $this;
}
public function getPublished(): ?bool
{
return $this->published;
}
public function setPublished(bool $published): self
{
$this->published = $published;
return $this;
}
public function isActive(): bool
{
$date = new \DateTime();
return $this->getStartAt() <= $date && $this->getEndAt() > $date;
}
public function isEnded():bool
{
$date = new \DateTime();
return $this->getEndAt() < $date;
}
public function getSeeLaterButtonText(): ?string
{
return $this->seeLaterButtonText;
}
public function setSeeLaterButtonText(string $seeLaterButtonText): self
{
$this->seeLaterButtonText = $seeLaterButtonText;
return $this;
}
public function useInternal(): bool
{
return $this->useInternal;
}
public function setUseInternal(bool $useInternal): self
{
$this->useInternal = $useInternal;
return $this;
}
/**
* @return bool
*/
public function isEmailReminderPossible(): bool
{
return $this->getSendEmail()
&& $this->getPublished()
&& $this->isActive();
}
/**
* Clear the id when the entity is cloned to avoid conflicts
*/
public function __clone()
{
/**
* Check required by doctrine
* @see https://www.doctrine-project.org/projects/doctrine-orm/en/2.7/cookbook/implementing-wakeup-or-clone.html#safely-implementing-clone
*/
if ($this->id) {
$this->id = null;
$this->notificationStatistics = new ArrayCollection();
}
}
}