src/Entity/Notification.php line 26

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\App\NotificationRepository;
  4. use App\Validator\Constraints\NotificationUserListFormat;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Symfony\Component\HttpFoundation\File\File;
  9. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  10. use Symfony\Component\Validator\Constraints as Assert;
  11. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  12. use App\Validator\NotificationUseInternal;
  13. /**
  14.  * @NotificationUseInternal
  15.  *
  16.  * @ORM\Entity(repositoryClass=NotificationRepository::class)
  17.  *
  18.  * @Vich\Uploadable
  19.  *
  20.  * @UniqueEntity(fields={"campaignName"}, message="notification.campaign_name.already_exist")
  21.  */
  22. class Notification
  23. {
  24.     /**
  25.      * @ORM\Id
  26.      * @ORM\GeneratedValue
  27.      * @ORM\Column(type="integer")
  28.      */
  29.     private $id;
  30.     /**
  31.      * @ORM\Column(type="string", length=255)
  32.      * @Assert\Length(max=255)
  33.      */
  34.     private $campaignName;
  35.     /**
  36.      * @ORM\Column(type="datetime")
  37.      */
  38.     private $createdAt;
  39.     /**
  40.      * Used to trigger doctrine hydration when uploading files with VichUploader
  41.      * @see https://github.com/dustin10/VichUploaderBundle/issues/297
  42.      *
  43.      * @ORM\Column(type="datetime", nullable=true)
  44.      */
  45.     private $updatedAt;
  46.     /**
  47.      * @ORM\Column(type="string", length=200)
  48.      * @Assert\Length(max=200)
  49.      */
  50.     private $messageName;
  51.     /**
  52.      * @ORM\Column(type="text")
  53.      * @Assert\NotBlank ()
  54.      */
  55.     private $messageBody;
  56.     /**
  57.      * @ORM\Column(type="string", length=255, nullable=true)
  58.      */
  59.     private $image;
  60.     /**
  61.      * @Vich\UploadableField(mapping="notification", fileNameProperty="image")
  62.      * @Assert\File(
  63.      *     mimeTypes = {"image/jpeg", "image/png"},
  64.      *     mimeTypesMessage = "Le fichier n'est pas au bon format. ( Seulement jpg, jpeg, ou png )"
  65.      * )
  66.      * @var File
  67.      */
  68.     protected $imageFile;
  69.     /**
  70.      * @ORM\Column(type="boolean", options = { "default" : false })
  71.      */
  72.     private $sendEmail;
  73.     /**
  74.      * @ORM\Column(type="boolean", options = { "default" : false })
  75.      */
  76.     private $setPopUp;
  77.     /**
  78.      * @ORM\Column(type="datetime", options = { "default" : "CURRENT_TIMESTAMP" })
  79.      * @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"})
  80.      * @Assert\Expression(
  81.      *     "this.getEndAt() > this.getStartAt()",
  82.      *     message="La date de début doit être antérieure à la date de fin"
  83.      * )
  84.      */
  85.     private $startAt;
  86.     /**
  87.      * @ORM\Column(type="datetime")
  88.      * @Assert\Expression(
  89.      *     "this.getEndAt() > this.getStartAt()",
  90.      *     message="La date de fin doit être postérieure à la date de début"
  91.      * )
  92.      * @Assert\GreaterThanOrEqual  ("today", message="La date ne peut pas être inférieure à la date du jour")
  93.      */
  94.     private $endAt;
  95.     /**
  96.      * @ORM\Column(type="string", length=255, nullable=true)
  97.      */
  98.     private ?string $targetedUsersFilename '';
  99.     /**
  100.      * @Vich\UploadableField(mapping="notification_excel_file", fileNameProperty="targetedUsersFilename")
  101.      * @Assert\File(
  102.      *     mimeTypes = {"application/vnd.ms-excel", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"},
  103.      *     mimeTypesMessage = "Le fichier n'est pas au bon format. ( Seulement xls, ou xlsx )"
  104.      * )
  105.      * @var File
  106.      * @NotificationUserListFormat
  107.      */
  108.     private $targetedUsersUploadedFile;
  109.     /**
  110.      * @ORM\Column(type="boolean", nullable=true, options = { "default": false})
  111.      */
  112.     private $requiredCheckboxToggle;
  113.     /**
  114.      * @ORM\Column(type="string", length=255, nullable=true)
  115.      * @Assert\Expression(
  116.      *      "(this.getRequiredCheckboxToggle() and value) or (!this.getRequiredCheckboxToggle() and !value)",
  117.      *      message="Ce champs doit être renseigné si l'option case à cocher est activée"
  118.      *  )
  119.      */
  120.     private $requiredCheckboxText;
  121.     /**
  122.      * @ORM\Column(type="boolean", nullable=true, options = { "default": false})
  123.      */
  124.     private $requiredUserChoiceToggle;
  125.     /**
  126.      * @ORM\Column(type="string", length=255, nullable=true)
  127.      * @Assert\Expression(
  128.      *      "(this.getRequiredUserChoiceToggle() and value) or (!this.getRequiredUserChoiceToggle() and !value)",
  129.      *      message="Ce champs doit être renseigné si l'option boutons de validation est activée"
  130.      *  )
  131.      */
  132.     private $requiredUserChoiceAcceptanceText;
  133.     /**
  134.      * @ORM\Column(type="string", length=255, nullable=true)
  135.      * @Assert\Expression(
  136.      *      "(this.getRequiredUserChoiceToggle() and value) or (!this.getRequiredUserChoiceToggle() and !value)",
  137.      *      message="Ce champs doit être renseigné si l'option boutons de validation est activée"
  138.      *  )
  139.      */
  140.     private $requiredUserChoiceRefusalText;
  141.     /**
  142.      * @ORM\OneToMany(targetEntity=NotificationStatistics::class, mappedBy="notification", orphanRemoval=true)
  143.      */
  144.     private $notificationStatistics;
  145.     /**
  146.      * @ORM\Column(type="integer", nullable=true)
  147.      */
  148.     private $insistenceCoefficient;
  149.     /**
  150.      * @ORM\Column(type="string", length=255)
  151.      */
  152.     private $author;
  153.     /**
  154.      * @ORM\Column(type="boolean")
  155.      */
  156.     private $published;
  157.     /**
  158.      * @ORM\Column(type="string", length=255)
  159.      */
  160.     private $seeLaterButtonText "Voir plus tard";
  161.     /**
  162.      * @ORM\Column(type="boolean", name="use_internal", nullable=true, options={"default": false})
  163.      */
  164.     private ?bool $useInternal false;
  165.     public function __construct()
  166.     {
  167.         $this->createdAt = new \DateTime();
  168.         $this->startAt = new \DateTime();
  169.         $this->endAt = new \DateTime('tomorrow');
  170.         $this->notificationStatistics = new ArrayCollection();
  171.     }
  172.     public function getId(): ?int
  173.     {
  174.         return $this->id;
  175.     }
  176.     public function getCampaignName(): ?string
  177.     {
  178.         return $this->campaignName;
  179.     }
  180.     public function setCampaignName(string $campaignName): self
  181.     {
  182.         $this->campaignName $campaignName;
  183.         return $this;
  184.     }
  185.     public function getCreatedAt(): ?\DateTimeInterface
  186.     {
  187.         return $this->createdAt;
  188.     }
  189.     public function setCreatedAt(\DateTimeInterface $createdAt): self
  190.     {
  191.         $this->createdAt $createdAt;
  192.         return $this;
  193.     }
  194.     public function getMessageName(): ?string
  195.     {
  196.         return $this->messageName;
  197.     }
  198.     public function setMessageName(string $messageName): self
  199.     {
  200.         $this->messageName $messageName;
  201.         return $this;
  202.     }
  203.     public function getMessageBody(): ?string
  204.     {
  205.         return $this->messageBody;
  206.     }
  207.     public function setMessageBody(string $messageBody): self
  208.     {
  209.         $this->messageBody $messageBody;
  210.         return $this;
  211.     }
  212.     public function getImage(): ?string
  213.     {
  214.         return $this->image;
  215.     }
  216.     public function setImage(?string $image): self
  217.     {
  218.         $this->image $image;
  219.         return $this;
  220.     }
  221.     public function getImageFile(): ?File
  222.     {
  223.         return $this->imageFile;
  224.     }
  225.     /**
  226.      * @return Dashboard
  227.      * @throws \Exception
  228.      *
  229.      */
  230.     public function setImageFile(?File $imageFile): self
  231.     {
  232.         $this->imageFile $imageFile;
  233.         if ($imageFile) {
  234.             $this->updatedAt = new \DateTime('now');
  235.         }
  236.         return $this;
  237.     }
  238.     public function getSendEmail(): ?bool
  239.     {
  240.         return $this->sendEmail;
  241.     }
  242.     public function setSendEmail(bool $sendEmail): self
  243.     {
  244.         $this->sendEmail $sendEmail;
  245.         return $this;
  246.     }
  247.     public function getSetPopUp(): ?bool
  248.     {
  249.         return $this->setPopUp;
  250.     }
  251.     public function setSetPopUp(bool $setPopUp): self
  252.     {
  253.         $this->setPopUp $setPopUp;
  254.         return $this;
  255.     }
  256.     public function getStartAt(): ?\DateTimeInterface
  257.     {
  258.         return $this->startAt;
  259.     }
  260.     public function setStartAt(?\DateTimeInterface $startAt): self
  261.     {
  262.         $this->startAt $startAt;
  263.         return $this;
  264.     }
  265.     public function getEndAt(): ?\DateTimeInterface
  266.     {
  267.         return $this->endAt;
  268.     }
  269.     public function setEndAt(?\DateTimeInterface $endAt): self
  270.     {
  271.         $this->endAt $endAt;
  272.         return $this;
  273.     }
  274.     public function getTargetedUsersFilename(): ?string
  275.     {
  276.         return $this->targetedUsersFilename;
  277.     }
  278.     public function setTargetedUsersFilename(?string $targetedUsersFilename): self
  279.     {
  280.         $this->targetedUsersFilename $targetedUsersFilename;
  281.         return $this;
  282.     }
  283.     public function getTargetedUsersUploadedFile(): ?File
  284.     {
  285.         return $this->targetedUsersUploadedFile;
  286.     }
  287.     public function setTargetedUsersUploadedFile(?File $targetedUsersUploadedFile): self
  288.     {
  289.         $this->targetedUsersUploadedFile $targetedUsersUploadedFile;
  290.         if ($targetedUsersUploadedFile) {
  291.             $this->updatedAt = new \DateTime();
  292.         }
  293.         return $this;
  294.     }
  295.     public function getRequiredCheckboxToggle(): ?bool
  296.     {
  297.         return $this->requiredCheckboxToggle;
  298.     }
  299.     public function setRequiredCheckboxToggle(?bool $requiredCheckboxToggle): self
  300.     {
  301.         $this->requiredCheckboxToggle $requiredCheckboxToggle;
  302.         return $this;
  303.     }
  304.     public function getRequiredCheckboxText(): ?string
  305.     {
  306.         return $this->requiredCheckboxText;
  307.     }
  308.     public function setRequiredCheckboxText(?string $requiredCheckboxText): self
  309.     {
  310.         $this->requiredCheckboxText $requiredCheckboxText;
  311.         return $this;
  312.     }
  313.     public function getRequiredUserChoiceToggle(): ?bool
  314.     {
  315.         return $this->requiredUserChoiceToggle;
  316.     }
  317.     public function setRequiredUserChoiceToggle(?bool $requiredUserChoiceToggle): self
  318.     {
  319.         $this->requiredUserChoiceToggle $requiredUserChoiceToggle;
  320.         return $this;
  321.     }
  322.     public function getRequiredUserChoiceAcceptanceText(): ?string
  323.     {
  324.         return $this->requiredUserChoiceAcceptanceText;
  325.     }
  326.     public function setRequiredUserChoiceAcceptanceText(?string $requiredUserChoiceAcceptanceText): self
  327.     {
  328.         $this->requiredUserChoiceAcceptanceText $requiredUserChoiceAcceptanceText;
  329.         return $this;
  330.     }
  331.     public function getRequiredUserChoiceRefusalText(): ?string
  332.     {
  333.         return $this->requiredUserChoiceRefusalText;
  334.     }
  335.     public function setRequiredUserChoiceRefusalText(?string $requiredUserChoiceRefusalText): self
  336.     {
  337.         $this->requiredUserChoiceRefusalText $requiredUserChoiceRefusalText;
  338.         return $this;
  339.     }
  340.     /**
  341.      * @return Collection|NotificationStatistics[]
  342.      */
  343.     public function getNotificationStatistics(): Collection
  344.     {
  345.         return $this->notificationStatistics;
  346.     }
  347.     public function addNotificationStatistic(NotificationStatistics $notificationStatistic): self
  348.     {
  349.         if (!$this->notificationStatistics->contains($notificationStatistic)) {
  350.             $this->notificationStatistics[] = $notificationStatistic;
  351.             $notificationStatistic->setNotification($this);
  352.         }
  353.         return $this;
  354.     }
  355.     public function removeNotificationStatistic(NotificationStatistics $notificationStatistic): self
  356.     {
  357.         if ($this->notificationStatistics->removeElement($notificationStatistic)) {
  358.             // set the owning side to null (unless already changed)
  359.             if ($notificationStatistic->getNotification() === $this) {
  360.                 $notificationStatistic->setNotification(null);
  361.             }
  362.         }
  363.         return $this;
  364.     }
  365.     public function getInsistenceCoefficient(): ?int
  366.     {
  367.         return $this->insistenceCoefficient;
  368.     }
  369.     public function setInsistenceCoefficient(?int $insistenceCoefficient): self
  370.     {
  371.         $this->insistenceCoefficient $insistenceCoefficient;
  372.         return $this;
  373.     }
  374.     public function getAuthor(): ?string
  375.     {
  376.         return $this->author;
  377.     }
  378.     public function setAuthor(string $author): self
  379.     {
  380.         $this->author $author;
  381.         return $this;
  382.     }
  383.     public function getPublished(): ?bool
  384.     {
  385.         return $this->published;
  386.     }
  387.     public function setPublished(bool $published): self
  388.     {
  389.         $this->published $published;
  390.         return $this;
  391.     }
  392.     public function isActive(): bool
  393.     {
  394.         $date = new \DateTime();
  395.         return $this->getStartAt() <= $date && $this->getEndAt() > $date;
  396.     }
  397.     public function isEnded():bool
  398.     {
  399.         $date = new \DateTime();
  400.         return $this->getEndAt() < $date;
  401.     }
  402.     public function getSeeLaterButtonText(): ?string
  403.     {
  404.         return $this->seeLaterButtonText;
  405.     }
  406.     public function setSeeLaterButtonText(string $seeLaterButtonText): self
  407.     {
  408.         $this->seeLaterButtonText $seeLaterButtonText;
  409.         return $this;
  410.     }
  411.     public function useInternal(): bool
  412.     {
  413.         return $this->useInternal;
  414.     }
  415.     public function setUseInternal(bool $useInternal): self
  416.     {
  417.         $this->useInternal $useInternal;
  418.         return $this;
  419.     }
  420.     /**
  421.      * @return bool
  422.      */
  423.     public function isEmailReminderPossible(): bool
  424.     {
  425.         return $this->getSendEmail()
  426.             && $this->getPublished()
  427.             && $this->isActive();
  428.     }
  429.     /**
  430.      * Clear the id when the entity is cloned to avoid conflicts
  431.      */
  432.     public function __clone()
  433.     {
  434.         /**
  435.          * Check required by doctrine
  436.          * @see https://www.doctrine-project.org/projects/doctrine-orm/en/2.7/cookbook/implementing-wakeup-or-clone.html#safely-implementing-clone
  437.          */
  438.         if ($this->id) {
  439.             $this->id null;
  440.             $this->notificationStatistics = new ArrayCollection();
  441.         }
  442.     }
  443. }