src/Entity/Gos/RenewalOffer/RenewalOffer.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Gos\RenewalOffer;
  3. use App\Entity\Gos\EmailTemplate;
  4. use App\Entity\Gos\PortalSettings;
  5. use App\Entity\Gos\ProductVariant;
  6. use App\Entity\Gos\User;
  7. use App\Repository\Gos\RenewalOffer\RenewalOfferRepository;
  8. use App\Utils\RenewalOffer\RenewalOfferTypes;
  9. use Doctrine\Common\Collections\ArrayCollection;
  10. use Doctrine\Common\Collections\Collection;
  11. use Doctrine\ORM\Mapping as ORM;
  12. /**
  13.  * @ORM\Entity(repositoryClass=RenewalOfferRepository::class)
  14.  * @ORM\HasLifecycleCallbacks
  15.  */
  16. class RenewalOffer
  17. {
  18.     public const DAYS_TO_END_ACCESS 30;
  19.     /**
  20.      * @ORM\Id
  21.      * @ORM\GeneratedValue
  22.      * @ORM\Column(type="integer")
  23.      */
  24.     private $id;
  25.     /**
  26.      * @ORM\Column(type="string", length=255)
  27.      */
  28.     private $name;
  29.     /**
  30.      * @ORM\Column(type="text", nullable=true)
  31.      */
  32.     private $introductory;
  33.     /**
  34.      * @ORM\Column(type="boolean")
  35.      */
  36.     private $isActive true;
  37.     /**
  38.      * @ORM\Column(type="boolean")
  39.      */
  40.     private $isForNewOrdersOnly false;
  41.     /**
  42.      * @ORM\OneToMany(targetEntity=SuggestedVariant::class, mappedBy="renewalOffer", orphanRemoval=true, cascade={"persist", "remove"})
  43.      */
  44.     private $suggestedVariants;
  45.     /**
  46.      * @ORM\OneToOne(targetEntity=Discount::class, mappedBy="renewalOffer", cascade={"persist", "remove"})
  47.      */
  48.     private $discount;
  49.     /**
  50.      * @ORM\OneToMany(targetEntity=Freebie::class, mappedBy="renewalOffer", orphanRemoval=true, cascade={"persist", "remove"})
  51.      */
  52.     private $freebies;
  53.     /**
  54.      * @ORM\OneToMany(targetEntity=UserRenewalOffer::class, mappedBy="renewalOffer", orphanRemoval=true)
  55.      */
  56.     private $userRenewalOffers;
  57.     /**
  58.      * @ORM\Column(type="datetime")
  59.      */
  60.     private $createdAt;
  61.     /**
  62.      * @ORM\Column(type="datetime", nullable=true)
  63.      */
  64.     private $updatedAt;
  65.     /**
  66.      * @ORM\Column(type="json")
  67.      */
  68.     private $mailingSettings = [];
  69.     /**
  70.      * @ORM\Column(type="json", nullable=true)
  71.      */
  72.     private $smsSettings = [];
  73.     /**
  74.      * @ORM\ManyToOne(targetEntity=PortalSettings::class)
  75.      * @ORM\JoinColumn(nullable=false)
  76.      */
  77.     private $portalSettings;
  78.     /**
  79.      * @ORM\ManyToOne(targetEntity=EmailTemplate::class, inversedBy="renewalOffers")
  80.      */
  81.     private $emailTemplate;
  82.     /**
  83.      * @ORM\ManyToOne(targetEntity=EmailTemplate::class)
  84.      */
  85.     private $informationEmailTemplate;
  86.     /**
  87.      * @ORM\ManyToMany(targetEntity=ProductVariant::class)
  88.      */
  89.     private $informationEmailVariants;
  90.     /**
  91.      * @ORM\Column(type="string", length=255)
  92.      */
  93.     private $type RenewalOfferTypes::MULTI;
  94.     /**
  95.      * @ORM\Column(type="string", length=255, nullable=true)
  96.      */
  97.     private $source;
  98.     /**
  99.      * @ORM\ManyToOne(targetEntity=User::class)
  100.      */
  101.     private $user;
  102.     /**
  103.      * @ORM\Column(type="boolean", nullable=true)
  104.      */
  105.     private $isUsed;
  106.     public function __construct()
  107.     {
  108.         $this->suggestedVariants        = new ArrayCollection();
  109.         $this->freebies                 = new ArrayCollection();
  110.         $this->userRenewalOffers        = new ArrayCollection();
  111.         $this->informationEmailVariants = new ArrayCollection();
  112.     }
  113.     public function __toString()
  114.     {
  115.         return sprintf("%s_%d"$this->name$this->id);
  116.     }
  117.     public function __clone()
  118.     {
  119.         $this->id        null;
  120.         $this->createdAt null;
  121.         $this->updatedAt null;
  122.         $clonedSuggestedVariants = new ArrayCollection();
  123.         $clonedFreebies          = new ArrayCollection();
  124.         $this->userRenewalOffers = new ArrayCollection();
  125.         $this->discount          = (clone $this->discount)->setRenewalOffer($this);
  126.         foreach ($this->suggestedVariants as $suggestedVariant)
  127.         {
  128.             /** @var SuggestedVariant $clonedSuggestedVariant */
  129.             $clonedSuggestedVariant = clone $suggestedVariant;
  130.             $clonedSuggestedVariant->setRenewalOffer($this);
  131.             $clonedSuggestedVariants->add($clonedSuggestedVariant);
  132.         }
  133.         foreach ($this->freebies as $freebie)
  134.         {
  135.             /** @var Freebie $clonedFreebie */
  136.             $clonedFreebie = clone $freebie;
  137.             $clonedFreebie->setRenewalOffer($this);
  138.             $clonedFreebies->add($clonedFreebie);
  139.         }
  140.         $this->suggestedVariants $clonedSuggestedVariants;
  141.         $this->freebies          $clonedFreebies;
  142.     }
  143.     /**
  144.      * @ORM\PrePersist()
  145.      */
  146.     public function prePersist()
  147.     {
  148.         $this->createdAt = new \DateTime();
  149.     }
  150.     /**
  151.      * @ORM\PreUpdate()
  152.      */
  153.     public function preUpdate()
  154.     {
  155.         $this->updatedAt = new \DateTime();
  156.     }
  157.     public function getId(): ?int
  158.     {
  159.         return $this->id;
  160.     }
  161.     public function getName(): ?string
  162.     {
  163.         return $this->name;
  164.     }
  165.     public function setName(string $name): self
  166.     {
  167.         $this->name $name;
  168.         return $this;
  169.     }
  170.     public function getIntroductory(): ?string
  171.     {
  172.         return $this->introductory;
  173.     }
  174.     public function setIntroductory(?string $introductory): self
  175.     {
  176.         $this->introductory $introductory;
  177.         return $this;
  178.     }
  179.     public function isActive(): ?bool
  180.     {
  181.         return $this->isActive;
  182.     }
  183.     public function setIsActive(bool $isActive): self
  184.     {
  185.         $this->isActive $isActive;
  186.         return $this;
  187.     }
  188.     public function isForNewOrdersOnly(): ?bool
  189.     {
  190.         return $this->isForNewOrdersOnly;
  191.     }
  192.     public function setIsForNewOrdersOnly(bool $isForNewOrdersOnly): self
  193.     {
  194.         $this->isForNewOrdersOnly $isForNewOrdersOnly;
  195.         return $this;
  196.     }
  197.     public function toggleActive(): self
  198.     {
  199.         $this->isActive = !$this->isActive;
  200.         return $this;
  201.     }
  202.     /**
  203.      * @return Collection|SuggestedVariant[]
  204.      */
  205.     public function getSuggestedVariants(): Collection
  206.     {
  207.         return $this->suggestedVariants;
  208.     }
  209.     public function addSuggestedVariant(SuggestedVariant $suggestedVariant): self
  210.     {
  211.         if (!$this->suggestedVariants->contains($suggestedVariant)) {
  212.             $this->suggestedVariants[] = $suggestedVariant;
  213.             $suggestedVariant->setRenewalOffer($this);
  214.         }
  215.         return $this;
  216.     }
  217.     public function removeSuggestedVariant(SuggestedVariant $suggestedVariant): self
  218.     {
  219.         if ($this->suggestedVariants->contains($suggestedVariant)) {
  220.             $this->suggestedVariants->removeElement($suggestedVariant);
  221.             // set the owning side to null (unless already changed)
  222.             if ($suggestedVariant->getRenewalOffer() === $this) {
  223.                 $suggestedVariant->setRenewalOffer(null);
  224.             }
  225.         }
  226.         return $this;
  227.     }
  228.     public function getDiscount(): ?Discount
  229.     {
  230.         return $this->discount;
  231.     }
  232.     public function setDiscount(Discount $discount): self
  233.     {
  234.         $this->discount $discount;
  235.         // set the owning side of the relation if necessary
  236.         if ($discount->getRenewalOffer() !== $this) {
  237.             $discount->setRenewalOffer($this);
  238.         }
  239.         return $this;
  240.     }
  241.     /**
  242.      * @return Collection|Freebie[]
  243.      */
  244.     public function getFreebies(): Collection
  245.     {
  246.         return $this->freebies;
  247.     }
  248.     public function addFreeby(Freebie $freeby): self
  249.     {
  250.         if (!$this->freebies->contains($freeby)) {
  251.             $this->freebies[] = $freeby;
  252.             $freeby->setRenewalOffer($this);
  253.         }
  254.         return $this;
  255.     }
  256.     public function removeFreeby(Freebie $freeby): self
  257.     {
  258.         if ($this->freebies->contains($freeby)) {
  259.             $this->freebies->removeElement($freeby);
  260.             // set the owning side to null (unless already changed)
  261.             if ($freeby->getRenewalOffer() === $this) {
  262.                 $freeby->setRenewalOffer(null);
  263.             }
  264.         }
  265.         return $this;
  266.     }
  267.     /**
  268.      * @return Collection|UserRenewalOffer[]
  269.      */
  270.     public function getUserRenewalOffers(): Collection
  271.     {
  272.         return $this->userRenewalOffers;
  273.     }
  274.     public function addUserRenewalOffer(UserRenewalOffer $userRenewalOffer): self
  275.     {
  276.         if (!$this->userRenewalOffers->contains($userRenewalOffer)) {
  277.             $this->userRenewalOffers[] = $userRenewalOffer;
  278.             $userRenewalOffer->setRenewalOffer($this);
  279.         }
  280.         return $this;
  281.     }
  282.     public function removeUserRenewalOffer(UserRenewalOffer $userRenewalOffer): self
  283.     {
  284.         if ($this->userRenewalOffers->contains($userRenewalOffer)) {
  285.             $this->userRenewalOffers->removeElement($userRenewalOffer);
  286.             // set the owning side to null (unless already changed)
  287.             if ($userRenewalOffer->getRenewalOffer() === $this) {
  288.                 $userRenewalOffer->setRenewalOffer(null);
  289.             }
  290.         }
  291.         return $this;
  292.     }
  293.     public function getCreatedAt(): ?\DateTimeInterface
  294.     {
  295.         return $this->createdAt;
  296.     }
  297.     public function setCreatedAt(\DateTimeInterface $createdAt): self
  298.     {
  299.         $this->createdAt $createdAt;
  300.         return $this;
  301.     }
  302.     public function getUpdatedAt(): ?\DateTimeInterface
  303.     {
  304.         return $this->updatedAt;
  305.     }
  306.     public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
  307.     {
  308.         $this->updatedAt $updatedAt;
  309.         return $this;
  310.     }
  311.     public function getMailingSettings(): ?array
  312.     {
  313.         return $this->mailingSettings;
  314.     }
  315.     public function setMailingSettings(array $mailingSettings): self
  316.     {
  317.         $this->mailingSettings $mailingSettings;
  318.         return $this;
  319.     }
  320.     public function getSmsSettings(): ?array
  321.     {
  322.         return $this->smsSettings;
  323.     }
  324.     public function setSmsSettings(?array $smsSettings): self
  325.     {
  326.         $this->smsSettings $smsSettings;
  327.         return $this;
  328.     }
  329.     public function getPortalSettings(): ?PortalSettings
  330.     {
  331.         return $this->portalSettings;
  332.     }
  333.     public function setPortalSettings(?PortalSettings $domain): self
  334.     {
  335.         $this->portalSettings $domain;
  336.         return $this;
  337.     }
  338.     public function getEmailTemplate(): ?EmailTemplate
  339.     {
  340.         return $this->emailTemplate;
  341.     }
  342.     public function setEmailTemplate(?EmailTemplate $emailTemplate): self
  343.     {
  344.         $this->emailTemplate $emailTemplate;
  345.         return $this;
  346.     }
  347.     public function getInformationEmailTemplate(): ?EmailTemplate
  348.     {
  349.         return $this->informationEmailTemplate;
  350.     }
  351.     public function setInformationEmailTemplate(?EmailTemplate $informationEmailTemplate): self
  352.     {
  353.         $this->informationEmailTemplate $informationEmailTemplate;
  354.         return $this;
  355.     }
  356.     /**
  357.      * @return Collection|ProductVariant[]
  358.      */
  359.     public function getInformationEmailVariants(): Collection
  360.     {
  361.         return $this->informationEmailVariants;
  362.     }
  363.     public function addInformationEmailVariant(ProductVariant $informationEmailVariant): self
  364.     {
  365.         if (!$this->informationEmailVariants->contains($informationEmailVariant)) {
  366.             $this->informationEmailVariants[] = $informationEmailVariant;
  367.         }
  368.         return $this;
  369.     }
  370.     public function removeInformationEmailVariant(ProductVariant $informationEmailVariant): self
  371.     {
  372.         if ($this->informationEmailVariants->contains($informationEmailVariant)) {
  373.             $this->informationEmailVariants->removeElement($informationEmailVariant);
  374.         }
  375.         return $this;
  376.     }
  377.     public function getType(): ?string
  378.     {
  379.         return $this->type;
  380.     }
  381.     public function setType(string $type): self
  382.     {
  383.         $this->type $type;
  384.         return $this;
  385.     }
  386.     public function getSource(): ?string
  387.     {
  388.         return $this->source;
  389.     }
  390.     public function setSource(?string $source): self
  391.     {
  392.         $this->source $source;
  393.         return $this;
  394.     }
  395.     public function getUser(): ?User
  396.     {
  397.         return $this->user;
  398.     }
  399.     public function setUser(?User $user): self
  400.     {
  401.         $this->user $user;
  402.         return $this;
  403.     }
  404.     public function getIsUsed(): ?bool
  405.     {
  406.         return $this->isUsed;
  407.     }
  408.     public function setIsUsed(?bool $isUsed): self
  409.     {
  410.         $this->isUsed $isUsed;
  411.         return $this;
  412.     }
  413. }