src/Entity/PromoCode.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\PromoCodeRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. /**
  8.  * @ORM\Entity(repositoryClass=PromoCodeRepository::class)
  9.  */
  10. class PromoCode
  11. {
  12.     /**
  13.      * @ORM\Id
  14.      * @ORM\GeneratedValue
  15.      * @ORM\Column(type="integer")
  16.      */
  17.     private $id;
  18.     /**
  19.      * @ORM\Column(type="string", length=255)
  20.      */
  21.     private $content;
  22.     /**
  23.      * @ORM\OneToMany(targetEntity=PromoCodeUsage::class, mappedBy="promoCode")
  24.      */
  25.     private $promoCodeUsages;
  26.     /**
  27.      * @ORM\ManyToOne(targetEntity=Commission::class)
  28.      */
  29.     private $commission;
  30.     /**
  31.      * @ORM\ManyToOne(targetEntity=PercentOff::class)
  32.      */
  33.     private $percentOff;
  34.     /**
  35.      * @ORM\Column(type="boolean", options={"default"=1})
  36.      */
  37.     private $isActivo;
  38.     /**
  39.      * @ORM\Column(type="datetime_immutable", nullable=true)
  40.      */
  41.     private $createdAt;
  42.     /**
  43.      * @ORM\Column(type="integer", nullable=true)
  44.      */
  45.     private $venceDias;
  46.     /**
  47.      * @ORM\Column(type="boolean", options={"default" = 0})
  48.      */
  49.     private $isSendgrid;
  50.     /**
  51.      * @ORM\Column(type="datetime_immutable", nullable=true)
  52.      */
  53.     private $expiresAt;
  54.     /**
  55.      * @ORM\Column(type="boolean", options={"default" = 0})
  56.      */
  57.     private $ofTheDay;
  58.     /**
  59.      * @ORM\Column(type="boolean", options={"default" = 0})
  60.      */
  61.     private $isExpired;
  62.     /**
  63.      * @ORM\OneToMany(targetEntity=User::class, mappedBy="PromoCode")
  64.      */
  65.     private $users;
  66.     /**
  67.      * @ORM\OneToMany(targetEntity=User::class, mappedBy="usedPromoCode")
  68.      */
  69.     private $usedUsers;
  70.     /**
  71.      * @ORM\ManyToOne(targetEntity=User::class, inversedBy="promoCodes")
  72.      */
  73.     private $user;
  74.     public function __construct()
  75.     {
  76.         $this->promoCodeUsages = new ArrayCollection();
  77.         if(!$this->createdAt$this->createdAt = new \DateTimeImmutable();
  78.         $this->content strtoupper($this->content);
  79.         $this->users = new ArrayCollection();
  80.         $this->usedUsers = new ArrayCollection();
  81.         if(!$this->isSendgrid$this->isSendgrid 0;
  82.         if(!$this->ofTheDay$this->ofTheDay 0;
  83.         if(!$this->isExpired$this->isExpired 0;
  84.     }
  85.     public function getId(): ?int
  86.     {
  87.         return $this->id;
  88.     }
  89.     public function getContent(): ?string
  90.     {
  91.         return $this->content;
  92.     }
  93.     public function setContent(string $content): self
  94.     {
  95.         $this->content strtoupper($content);
  96.         return $this;
  97.     }
  98.     public function getUser(): ?User
  99.     {
  100.         return $this->user;
  101.     }
  102.     public function setUser(?User $user): self
  103.     {
  104.         $this->user $user;
  105.         return $this;
  106.     }
  107.     /**
  108.      * @return Collection<int, PromoCodeUsage>
  109.      */
  110.     public function getPromoCodeUsages(): Collection
  111.     {
  112.         return $this->promoCodeUsages;
  113.     }
  114.     public function addPromoCodeUsage(PromoCodeUsage $promoCodeUsage): self
  115.     {
  116.         if (!$this->promoCodeUsages->contains($promoCodeUsage)) {
  117.             $this->promoCodeUsages[] = $promoCodeUsage;
  118.             $promoCodeUsage->setPromoCode($this);
  119.         }
  120.         return $this;
  121.     }
  122.     public function removePromoCodeUsage(PromoCodeUsage $promoCodeUsage): self
  123.     {
  124.         if ($this->promoCodeUsages->removeElement($promoCodeUsage)) {
  125.             // set the owning side to null (unless already changed)
  126.             if ($promoCodeUsage->getPromoCode() === $this) {
  127.                 $promoCodeUsage->setPromoCode(null);
  128.             }
  129.         }
  130.         return $this;
  131.     }
  132.     public function __toString()
  133.     {
  134.         return $this->content;
  135.     }
  136.     public function getUnpaidCommission()
  137.     {
  138.         $r 0$total 0;
  139.         $us $this->getPromoCodeUsages();
  140.         if($us){
  141.             foreach ($us as $u){
  142. //                $u = new PromoCodeUsage();
  143.                 if($u->getCurrentPlace() == 'Unpaid'){
  144.                     ++$r;
  145.                 }
  146.             }
  147.             $total $r $this->getCommission()->getValor();
  148.         }
  149.         return $total;
  150.     }
  151.     public function getCommission(): ?Commission
  152.     {
  153.         return $this->commission;
  154.     }
  155.     public function setCommission(?Commission $commission): self
  156.     {
  157.         $this->commission $commission;
  158.         return $this;
  159.     }
  160.     public function getPercentOff(): ?PercentOff
  161.     {
  162.         return $this->percentOff;
  163.     }
  164.     public function setPercentOff(?PercentOff $percentOff): self
  165.     {
  166.         $this->percentOff $percentOff;
  167.         return $this;
  168.     }
  169.     public function getIsActivo(): ?bool
  170.     {
  171.         return $this->isActivo;
  172.     }
  173.     public function setIsActivo(bool $isActivo): self
  174.     {
  175.         $this->isActivo $isActivo;
  176.         return $this;
  177.     }
  178.     public function getCreatedAt(): ?\DateTimeImmutable
  179.     {
  180.         return $this->createdAt;
  181.     }
  182.     public function setCreatedAt(?\DateTimeImmutable $createdAt): self
  183.     {
  184.         $this->createdAt $createdAt;
  185.         return $this;
  186.     }
  187.     public function getVenceDias(): ?int
  188.     {
  189.         return $this->venceDias;
  190.     }
  191.     public function setVenceDias(?int $venceDias): self
  192.     {
  193.         $this->venceDias $venceDias;
  194.         return $this;
  195.     }
  196.     public function getIsSendgrid(): ?bool
  197.     {
  198.         return $this->isSendgrid;
  199.     }
  200.     public function setIsSendgrid(?bool $isSendgrid): self
  201.     {
  202.         $this->isSendgrid $isSendgrid;
  203.         return $this;
  204.     }
  205.     public function getExpiresAt(): ?\DateTimeImmutable
  206.     {
  207.         return $this->expiresAt;
  208.     }
  209.     public function setExpiresAt(?\DateTimeImmutable $expiresAt): self
  210.     {
  211.         $this->expiresAt $expiresAt;
  212.         return $this;
  213.     }
  214.     public function isOfTheDay(): ?bool
  215.     {
  216.         return $this->ofTheDay;
  217.     }
  218.     public function setOfTheDay(bool $ofTheDay): self
  219.     {
  220.         $this->ofTheDay $ofTheDay;
  221.         return $this;
  222.     }
  223.     public function getIsExpired(): ?bool
  224.     {
  225.         return $this->isExpired;
  226.     }
  227.     public function setIsExpired(bool $isExpired): self
  228.     {
  229.         $this->isExpired $isExpired;
  230.         return $this;
  231.     }
  232.     /**
  233.      * @return Collection<int, User>
  234.      */
  235.     public function getUsedUsers(): Collection
  236.     {
  237.         return $this->usedUsers;
  238.     }
  239.     public function addUsedUser(User $usedUser): self
  240.     {
  241.         if (!$this->usedUsers->contains($usedUser)) {
  242.             $this->usedUsers[] = $usedUser;
  243.             $usedUser->setUsedPromoCode($this);
  244.         }
  245.         return $this;
  246.     }
  247.     public function removeUsedUser(User $usedUser): self
  248.     {
  249.         if ($this->usedUsers->removeElement($usedUser)) {
  250.             // set the owning side to null (unless already changed)
  251.             if ($usedUser->getUsedPromoCode() === $this) {
  252.                 $usedUser->setUsedPromoCode(null);
  253.             }
  254.         }
  255.         return $this;
  256.     }
  257. }