<?php
namespace App\Entity;
use App\Repository\DiscountRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=DiscountRepository::class)
*/
class Discount
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $content;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $postContent;
/**
* @ORM\ManyToMany(targetEntity=Restriction::class, inversedBy="discounts", cascade={"persist"})
*/
private $restrictions;
/**
* @ORM\ManyToOne(targetEntity=DiscountName::class, inversedBy="discounts", cascade={"persist"})
*/
private $discountName;
/**
* @ORM\ManyToOne(targetEntity=DiscountType::class, inversedBy="discounts")
*/
private $discountType;
/**
* @ORM\ManyToOne(targetEntity=Provider::class, inversedBy="discounts")
*/
private $provider;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $isActivo;
public function __construct()
{
$this->restrictions = new ArrayCollection();
$this->providers = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getContent(): ?string
{
return $this->content;
}
public function setContent(?string $content): self
{
$this->content = $content;
return $this;
}
public function getPostContent(): ?string
{
return $this->postContent;
}
public function setPostContent(?string $postContent): self
{
$this->postContent = $postContent;
return $this;
}
/**
* @return Collection|Restriction[]
*/
public function getRestrictions(): Collection
{
return $this->restrictions;
}
/**
* @return Collection|Restriction[]
*/
public function getFeatures(): Collection
{
$arr = [];
$rs = $this->getRestrictions();
foreach ($rs as $r){
if($r->getIsFeature()) $arr[] = $r->getIfFeature();
}
return new ArrayCollection($arr);
}
public function addRestriction(Restriction $restriction): self
{
if (!$this->restrictions->contains($restriction)) {
$this->restrictions[] = $restriction;
}
return $this;
}
public function removeRestriction(Restriction $restriction): self
{
if ($this->restrictions->contains($restriction)) {
$this->restrictions->removeElement($restriction);
}
return $this;
}
public function getDiscountName(): ?DiscountName
{
return $this->discountName;
}
public function setDiscountName(?DiscountName $discountName): self
{
$this->discountName = $discountName;
return $this;
}
public function getDiscountType(): ?DiscountType
{
return $this->discountType;
}
public function setDiscountType(?DiscountType $discountType): self
{
$this->discountType = $discountType;
return $this;
}
public function __toString()
{
$arr = [
$this->content,
$this->getDiscountName(),
$this->postContent
];
return join(' ', $arr);
}
public function getFullName()
{
$provider = $this->getProvider()? $this->getProvider()->getContent() : '';
return join(" ", [$provider . ': ', $this->content, $this->discountName, $this->postContent]);
}
public function getNombreParcial()
{
return join(" ", [$this->content, $this->discountName, $this->postContent]);
}
public function getProvider(): ?Provider
{
return $this->provider;
}
public function setProvider(?Provider $provider): self
{
$this->provider = $provider;
return $this;
}
public function getIsActivo(): ?bool
{
return $this->isActivo;
}
public function setIsActivo(?bool $isActivo): self
{
$this->isActivo = $isActivo;
return $this;
}
}