src/Entity/Gos/AdditionalAccess/UserAdditionalAccessOffer.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Gos\AdditionalAccess;
  3. use App\Entity\Gos\Cart;
  4. use App\Entity\Gos\OrderPart;
  5. use App\Entity\Gos\Orders;
  6. use App\Entity\Gos\User;
  7. use App\Repository\Gos\AdditionalAccess\UserAdditionalAccessRepository;
  8. use Doctrine\Common\Collections\ArrayCollection;
  9. use Doctrine\Common\Collections\Collection;
  10. use Doctrine\ORM\Mapping as ORM;
  11. /**
  12.  * @ORM\Entity(repositoryClass=UserAdditionalAccessRepository::class)
  13.  * @ORM\HasLifecycleCallbacks
  14.  */
  15. class UserAdditionalAccessOffer
  16. {
  17.     public const OFFER_VALIDITY_DURATION 30// in days
  18.     /**
  19.      * @ORM\Id
  20.      * @ORM\GeneratedValue
  21.      * @ORM\Column(type="integer")
  22.      */
  23.     private $id;
  24.     /**
  25.      * @ORM\Column(type="string", length=32, unique=true)
  26.      */
  27.     private $hash;
  28.     /**
  29.      * @ORM\ManyToOne(targetEntity=User::class)
  30.      * @ORM\JoinColumn(nullable=false)
  31.      */
  32.     private $user;
  33.     /**
  34.      * @ORM\Column(type="date")
  35.      */
  36.     private $endDate;
  37.     /**
  38.      * @ORM\Column(type="integer")
  39.      */
  40.     private $subscriptionId;
  41.     /**
  42.      * @ORM\ManyToOne(targetEntity=OrderPart::class)
  43.      * @ORM\JoinColumn(nullable=false)
  44.      */
  45.     private $orderPart;
  46.     /**
  47.      * @ORM\Column(type="string", length=255)
  48.      */
  49.     private $productVariantNoComplete;
  50.     /**
  51.      * @ORM\OneToOne(targetEntity=Cart::class, cascade={"persist"})
  52.      * @ORM\JoinColumn(onDelete="SET NULL")
  53.      */
  54.     private $cart;
  55.     /**
  56.      * @ORM\Column(type="datetime")
  57.      */
  58.     private $createdAt;
  59.     /**
  60.      * @ORM\Column(type="datetime", nullable=true)
  61.      */
  62.     private $updatedAt;
  63.     /**
  64.      * @ORM\OneToMany(targetEntity=Orders::class, mappedBy="userAdditionalAccessOffer")
  65.      */
  66.     private $orders;
  67.     public function __construct()
  68.     {
  69.         $this->orders = new ArrayCollection();
  70.     }
  71.     /**
  72.      * @ORM\PrePersist()
  73.      */
  74.     public function prePersist()
  75.     {
  76.         $this->createdAt = new \DateTime();
  77.         $this->hash      md5(
  78.             sprintf(
  79.                 "%d-%s-%s-%s",
  80.                 $this->subscriptionId,
  81.                 $this->user->getEmailCanonical(),
  82.                 $this->orderPart->getOrdTran(),
  83.                 $this->productVariantNoComplete
  84.             )
  85.         );
  86.     }
  87.     /**
  88.      * @ORM\PreUpdate()
  89.      */
  90.     public function preUpdate()
  91.     {
  92.         $this->updatedAt = new \DateTime();
  93.     }
  94.     public function getId(): ?int
  95.     {
  96.         return $this->id;
  97.     }
  98.     public function getHash(): ?string
  99.     {
  100.         return $this->hash;
  101.     }
  102.     public function setHash(string $hash): self
  103.     {
  104.         $this->hash $hash;
  105.         return $this;
  106.     }
  107.     public function getUser(): ?User
  108.     {
  109.         return $this->user;
  110.     }
  111.     public function setUser(?User $user): self
  112.     {
  113.         $this->user $user;
  114.         return $this;
  115.     }
  116.     public function getEndDate(): ?\DateTimeInterface
  117.     {
  118.         return $this->endDate;
  119.     }
  120.     public function setEndDate(\DateTimeInterface $endDate): self
  121.     {
  122.         $this->endDate $endDate;
  123.         return $this;
  124.     }
  125.     public function getSubscriptionId(): ?int
  126.     {
  127.         return $this->subscriptionId;
  128.     }
  129.     public function setSubscriptionId(int $subscriptionId): self
  130.     {
  131.         $this->subscriptionId $subscriptionId;
  132.         return $this;
  133.     }
  134.     public function getOrderPart(): ?OrderPart
  135.     {
  136.         return $this->orderPart;
  137.     }
  138.     public function setOrderPart(?OrderPart $orderPart): self
  139.     {
  140.         $this->orderPart $orderPart;
  141.         return $this;
  142.     }
  143.     public function getProductVariantNoComplete(): ?string
  144.     {
  145.         return $this->productVariantNoComplete;
  146.     }
  147.     public function setProductVariantNoComplete(string $productVariantNoComplete): self
  148.     {
  149.         $this->productVariantNoComplete $productVariantNoComplete;
  150.         return $this;
  151.     }
  152.     public function getCart(): ?Cart
  153.     {
  154.         return $this->cart;
  155.     }
  156.     public function setCart(?Cart $cart): self
  157.     {
  158.         $this->cart $cart;
  159.         return $this;
  160.     }
  161.     public function getCreatedAt(): ?\DateTimeInterface
  162.     {
  163.         return $this->createdAt;
  164.     }
  165.     public function setCreatedAt(\DateTimeInterface $createdAt): self
  166.     {
  167.         $this->createdAt $createdAt;
  168.         return $this;
  169.     }
  170.     public function getUpdatedAt(): ?\DateTimeInterface
  171.     {
  172.         return $this->updatedAt;
  173.     }
  174.     public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
  175.     {
  176.         $this->updatedAt $updatedAt;
  177.         return $this;
  178.     }
  179.     /**
  180.      * @return Collection|Orders[]
  181.      */
  182.     public function getOrders(): Collection
  183.     {
  184.         return $this->orders;
  185.     }
  186.     public function addOrder(Orders $order): self
  187.     {
  188.         if (!$this->orders->contains($order)) {
  189.             $this->orders[] = $order;
  190.             $order->setUserAdditionalAccessOffer($this);
  191.         }
  192.         return $this;
  193.     }
  194.     public function removeOrder(Orders $order): self
  195.     {
  196.         if ($this->orders->contains($order)) {
  197.             $this->orders->removeElement($order);
  198.             // set the owning side to null (unless already changed)
  199.             if ($order->getUserAdditionalAccessOffer() === $this) {
  200.                 $order->setUserAdditionalAccessOffer(null);
  201.             }
  202.         }
  203.         return $this;
  204.     }
  205.     /**
  206.      *
  207.      * CUSTOM METHODS
  208.      *
  209.      */
  210.     public function isActive(): bool
  211.     {
  212.         return $this->createdAt > new \DateTime(sprintf("-%d days"self::OFFER_VALIDITY_DURATION));
  213.     }
  214. }