src/Entity/UserShared.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\UserSharedRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\DBAL\Types\Types;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Gedmo\Blameable\Traits\BlameableEntity;
  9. use Gedmo\Timestampable\Traits\TimestampableEntity;
  10. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  11. use Symfony\Component\Validator\Constraints as Assert;
  12. #[ORM\Entity(repositoryClassUserSharedRepository::class)]
  13. #[UniqueEntity('token')]
  14. #[UniqueEntity(fields: ["influencer""product"], errorPath'influencer'groups: ['influencerShared'])]
  15. class UserShared
  16. {
  17.     use BlameableEntity//Hook blameable behaviour. Updates createdBy, updatedBy fields
  18.     use TimestampableEntity//Hook timestampable behaviour. Updates createdAt, updatedAt fields 
  19.     const TOKEN_NAME 'UserSharedPublicToken';
  20.     const REFERRAL_USER_TYPE 'REFERRAL_USER_TYPE';
  21.     const REFERRAL_INFLUENCER_TYPE 'REFERRAL_INFLUENCER_TYPE';
  22.     #[ORM\Id]
  23.     #[ORM\GeneratedValue(strategy"IDENTITY")]
  24.     #[ORM\Column]
  25.     private ?int $id null;
  26.     #[ORM\Column(typeTypes::DECIMALprecision10scale'2')]
  27.     #[Assert\NotNull(groups: ['influencerShared'])]
  28.     #[Assert\PositiveOrZero(groups: ['influencerShared'])]
  29.     private ?float $referredPoints null;
  30.     #[ORM\Column(typeTypes::DECIMALprecision10scale'2')]
  31.     #[Assert\NotNull()]
  32.     #[Assert\PositiveOrZero()]
  33.     private ?float $extraReferredPoints null;
  34.     #[ORM\Column(length50uniquetrue)]
  35.     #[Assert\NotNull()]
  36.     #[Assert\Length(max50)]
  37.     private ?string $token null;
  38.     #[ORM\ManyToOne]
  39.     #[Assert\NotNull(groups: ['influencerShared'])]
  40.     private ?User $influencer null;
  41.     #[ORM\ManyToOne(inversedBy'influencerShareds')]
  42.     private ?Product $product null;
  43.     #[ORM\OneToOne(inversedBy'originUserShared'cascade: ['persist''remove'])]
  44.     #[ORM\JoinColumn(nullabletrue)]
  45.     private ?OrderDetail $originOrderDetail null;
  46.     #[ORM\OneToMany(mappedBy'destinationUserShared'targetEntityOrderDetail::class)]
  47.     private Collection $destitationOrderDetails;
  48.     #[ORM\Column]
  49.     private ?bool $isActive true;
  50.     public function __construct()
  51.     {
  52.         $this->destitationOrderDetails = new ArrayCollection();
  53.     }
  54.     public function getId(): ?int
  55.     {
  56.         return $this->id;
  57.     }
  58.     public function getTotalReferredPoints(): ?string
  59.     {
  60.         return (
  61.             ($this->getReferredPoints() ?? 0) +
  62.             ($this->getExtraReferredPoints() ?? 0)
  63.         );
  64.     }
  65.     public function getReferredPoints(): ?string
  66.     {
  67.         return $this->referredPoints;
  68.     }
  69.     public function setReferredPoints(string $referredPoints): self
  70.     {
  71.         $this->referredPoints $referredPoints;
  72.         return $this;
  73.     }
  74.     public function getExtraReferredPoints(): ?string
  75.     {
  76.         return $this->extraReferredPoints;
  77.     }
  78.     public function setExtraReferredPoints(string $extraReferredPoints): self
  79.     {
  80.         $this->extraReferredPoints $extraReferredPoints;
  81.         return $this;
  82.     }
  83.     public function getToken(): ?string
  84.     {
  85.         return $this->token;
  86.     }
  87.     public function setToken(string $token): self
  88.     {
  89.         $this->token $token;
  90.         return $this;
  91.     }
  92.     public function getReferralUserType(): string
  93.     {
  94.         //Check Influencer Token
  95.         if (
  96.             $this->getInfluencer()
  97.         ) {
  98.             return self::REFERRAL_INFLUENCER_TYPE;
  99.         }
  100.         //Check Influencer Token
  101.         if ($this->getOriginOrderDetail()) {
  102.             return self::REFERRAL_USER_TYPE;
  103.         }
  104.         return null;
  105.     }
  106.     public function getInfluencer(): ?User
  107.     {
  108.         return $this->influencer;
  109.     }
  110.     public function setInfluencer(?User $influencer): self
  111.     {
  112.         $this->influencer $influencer;
  113.         return $this;
  114.     }
  115.     public function getProduct(): ?Product
  116.     {
  117.         return $this->product;
  118.     }
  119.     public function setProduct(?Product $product): self
  120.     {
  121.         $this->product $product;
  122.         return $this;
  123.     }
  124.     public function getOriginOrderDetail(): ?OrderDetail
  125.     {
  126.         return $this->originOrderDetail;
  127.     }
  128.     public function setOriginOrderDetail(OrderDetail $originOrderDetail): self
  129.     {
  130.         $this->originOrderDetail $originOrderDetail;
  131.         return $this;
  132.     }
  133.     /**
  134.      * @return Collection<int, OrderDetail>
  135.      */
  136.     public function getDestitationOrderDetails(): Collection
  137.     {
  138.         return $this->destitationOrderDetails;
  139.     }
  140.     public function addDestitationOrderDetail(OrderDetail $destitationOrderDetail): self
  141.     {
  142.         if (!$this->destitationOrderDetails->contains($destitationOrderDetail)) {
  143.             $this->destitationOrderDetails->add($destitationOrderDetail);
  144.             $destitationOrderDetail->setDestinationUserShared($this);
  145.         }
  146.         return $this;
  147.     }
  148.     public function removeDestitationOrderDetail(OrderDetail $destitationOrderDetail): self
  149.     {
  150.         if ($this->destitationOrderDetails->removeElement($destitationOrderDetail)) {
  151.             // set the owning side to null (unless already changed)
  152.             if ($destitationOrderDetail->getDestinationUserShared() === $this) {
  153.                 $destitationOrderDetail->setDestinationUserShared(null);
  154.             }
  155.         }
  156.         return $this;
  157.     }
  158.     public function isActive(): ?bool
  159.     {
  160.         return $this->isActive;
  161.     }
  162.     public function setIsActive(bool $isActive): self
  163.     {
  164.         $this->isActive $isActive;
  165.         return $this;
  166.     }
  167. }