<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass="App\Repository\ProductOptionRepository")
*/
class ProductOption
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="bigint")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $title;
/**
* @ORM\Column(type="text")
*/
private $description;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Product", inversedBy="productOptions")
* @ORM\JoinColumn(name="product_id", referencedColumnName="id", onDelete="SET NULL")
*/
private $product;
/**
* @ORM\OneToMany(targetEntity="App\Entity\ProductOptionValue", mappedBy="productOption", orphanRemoval=true, cascade={"persist", "remove"}, fetch="EAGER")
*/
private $productOptionValues;
/**
* @ORM\Column(type="boolean")
*/
private $required;
/**
* @ORM\Column(type="boolean")
*/
private $allow_multiple;
public function __construct ()
{
$this->title = "";
$this->description = "";
$this->required = false;
$this->allow_multiple = false;
$this->productOptionValues = new ArrayCollection();
}
public function getId()
{
return $this->id;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(string $title = null): self
{
$this->title = $title ? $title : "";
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(string $description = null): self
{
$this->description = $description ? $description : "";
return $this;
}
public function getProduct(): ?Product
{
return $this->product;
}
public function setProduct(?Product $product = null): self
{
$this->product = $product;
return $this;
}
/**
* @return Collection|ProductOptionValue[]
*/
public function getProductOptionValues(): Collection
{
return $this->productOptionValues;
}
public function addProductOptionValue(ProductOptionValue $productOptionValue): self
{
if (!$this->productOptionValues->contains($productOptionValue)) {
$this->productOptionValues[] = $productOptionValue;
$productOptionValue->setProductOption($this);
}
return $this;
}
public function removeProductOptionValue(ProductOptionValue $productOptionValue): self
{
if ($this->productOptionValues->contains($productOptionValue)) {
$this->productOptionValues->removeElement($productOptionValue);
// set the owning side to null (unless already changed)
if ($productOptionValue->getProductOption() === $this) {
$productOptionValue->setProductOption(null);
}
}
return $this;
}
public function getRequired(): ?bool
{
return $this->required == 1;
}
public function setRequired(bool $required): self
{
$this->required = $required ? 1 : 0;
return $this;
}
public function getAllowMultiple(): ?bool
{
return $this->allow_multiple == 1;
}
public function setAllowMultiple(bool $allow_multiple): self
{
$this->allow_multiple = $allow_multiple ? 1 : 0;
return $this;
}
public function __toString ()
{
return $this->title ? $this->title : '';
}
}