src/Entity/Restriction.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\RestrictionRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. /**
  8.  * @ORM\Entity(repositoryClass=RestrictionRepository::class)
  9.  */
  10. class Restriction
  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\ManyToOne(targetEntity=Color::class)
  24.      */
  25.     private $color;
  26.     /**
  27.      * @ORM\ManyToMany(targetEntity=Discount::class, mappedBy="restrictions")
  28.      */
  29.     private $discounts;
  30.     /**
  31.      * @ORM\Column(type="boolean", nullable=true)
  32.      */
  33.     private $isFeature;
  34.     public function __construct()
  35.     {
  36.         $this->products = new ArrayCollection();
  37.         $this->discounts = new ArrayCollection();
  38.     }
  39.     public function getId(): ?int
  40.     {
  41.         return $this->id;
  42.     }
  43.     public function getContent(): ?string
  44.     {
  45.         return $this->content;
  46.     }
  47.     public function setContent(string $content): self
  48.     {
  49.         $this->content $content;
  50.         return $this;
  51.     }
  52.     public function __toString()
  53.     {
  54.         return $this->content;
  55.     }
  56.     public function getColor(): ?Color
  57.     {
  58.         return $this->color;
  59.     }
  60.     public function setColor(?Color $color): self
  61.     {
  62.         $this->color $color;
  63.         return $this;
  64.     }
  65.     /**
  66.      * @return Collection|Discount[]
  67.      */
  68.     public function getDiscounts(): Collection
  69.     {
  70.         return $this->discounts;
  71.     }
  72.     public function addDiscount(Discount $discount): self
  73.     {
  74.         if (!$this->discounts->contains($discount)) {
  75.             $this->discounts[] = $discount;
  76.             $discount->addRestriction($this);
  77.         }
  78.         return $this;
  79.     }
  80.     public function removeDiscount(Discount $discount): self
  81.     {
  82.         if ($this->discounts->contains($discount)) {
  83.             $this->discounts->removeElement($discount);
  84.             $discount->removeRestriction($this);
  85.         }
  86.         return $this;
  87.     }
  88.     public function getIsFeature(): ?bool
  89.     {
  90.         return $this->isFeature;
  91.     }
  92.     public function getIfFeature()
  93.     {
  94.         if($this->getIsFeature()){
  95.             return $this->getContent();
  96.         }else{
  97.             return '';
  98.         }
  99.     }
  100.     public function setIsFeature(?bool $isFeature): self
  101.     {
  102.         $this->isFeature $isFeature;
  103.         return $this;
  104.     }
  105. }