<?php
namespace App\Entity;
use App\Repository\ProductParameterRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=ProductParameterRepository::class)
*/
class ProductParameter
{
const PRODUCT_PARAM_TYPE_NUMBER = 'number';
const PRODUCT_PARAM_TYPE_TEXT = 'text';
const PRODUCT_PARAM_TYPE_RICH = 'rich';
const PRODUCT_PARAM_TYPE_SELECTBOX = 'option';
const PRODUCT_PARAM_TYPE_DATE = 'date';
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="float", nullable=true)
*/
private $valueNumber;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $valueText;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $valueRich;
/**
* @ORM\ManyToOne(targetEntity=Option::class, inversedBy="products", cascade={"persist"})
*/
private $valueOption;
/**
* @ORM\ManyToOne(targetEntity=Parameter::class, inversedBy="products")
* @ORM\JoinColumn(nullable=false)
*/
private $parameter;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $ip;
/**
* @ORM\ManyToOne(targetEntity=Product::class, inversedBy="productParameters")
*/
private $product;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $created;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $changed;
public function __construct()
{
}
public function getId(): ?int
{
return $this->id;
}
public function getValueNumber(): ?float
{
return $this->valueNumber;
}
public function setValueNumber(?float $valueNumber): self
{
$this->valueNumber = $valueNumber;
return $this;
}
public function getValueText(): ?string
{
return $this->valueText;
}
public function setValueText(?string $valueText): self
{
$this->valueText = $valueText;
return $this;
}
public function getValueRich(): ?string
{
return $this->valueRich;
}
public function setValueRich(?string $valueRich): self
{
$this->valueRich = $valueRich;
return $this;
}
public function getValueOption(): ?Option
{
return $this->valueOption;
}
public function setValueOption(?Option $valueOption): self
{
$this->valueOption = $valueOption;
return $this;
}
public function getParameter(): ?Parameter
{
return $this->parameter;
}
public function setParameter(?Parameter $parameter): self
{
$this->parameter = $parameter;
return $this;
}
public function getIp(): ?string
{
return $this->ip;
}
public function setIp(?string $ip): self
{
$this->ip = $ip;
return $this;
}
public function getProduct(): ?Product
{
return $this->product;
}
public function setProduct(?Product $product): self
{
$this->product = $product;
return $this;
}
public function getCreated(): ?\DateTimeInterface
{
return $this->created;
}
public function setCreated(?\DateTimeInterface $created): self
{
$this->created = $created;
return $this;
}
public function getChanged(): ?\DateTimeInterface
{
return $this->changed;
}
public function setChanged(?\DateTimeInterface $changed): self
{
$this->changed = $changed;
return $this;
}
public function getValue(){
switch ($this->getParameter()->getType()){
case self::PRODUCT_PARAM_TYPE_NUMBER:
return $this->getValueNumber();
case self::PRODUCT_PARAM_TYPE_SELECTBOX:
return $this->getValueOption();
case self::PRODUCT_PARAM_TYPE_DATE:
return $this->getValueText();
default:
return $this->getValueText();
}
}
public function setValue($value){
switch ($this->getParameter()->getType()){
case self::PRODUCT_PARAM_TYPE_NUMBER:
return $this->setValueNumber($value);
case self::PRODUCT_PARAM_TYPE_SELECTBOX:
return $this->setValueOption($value);
case self::PRODUCT_PARAM_TYPE_RICH:
return $this->setValueRich($value);
case self::PRODUCT_PARAM_TYPE_DATE:
return $this->setValueText('2023-01-01');
default:
return $this->setValueText($value);
}
}
/**
* @return Option|float|string|null
*/
public function __toString(){
return (string)$this->getValue();
}
}