src/Entity/ProductParameter.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\ProductParameterRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. /**
  8.  * @ORM\Entity(repositoryClass=ProductParameterRepository::class)
  9.  */
  10. class ProductParameter
  11. {
  12.     const PRODUCT_PARAM_TYPE_NUMBER 'number';
  13.     const PRODUCT_PARAM_TYPE_TEXT 'text';
  14.     const PRODUCT_PARAM_TYPE_RICH 'rich';
  15.     const PRODUCT_PARAM_TYPE_SELECTBOX 'option';
  16.     const PRODUCT_PARAM_TYPE_DATE 'date';
  17.     /**
  18.      * @ORM\Id
  19.      * @ORM\GeneratedValue
  20.      * @ORM\Column(type="integer")
  21.      */
  22.     private $id;
  23.     /**
  24.      * @ORM\Column(type="float", nullable=true)
  25.      */
  26.     private $valueNumber;
  27.     /**
  28.      * @ORM\Column(type="string", length=255, nullable=true)
  29.      */
  30.     private $valueText;
  31.     /**
  32.      * @ORM\Column(type="text", nullable=true)
  33.      */
  34.     private $valueRich;
  35.     /**
  36.      * @ORM\ManyToOne(targetEntity=Option::class, inversedBy="products", cascade={"persist"})
  37.      */
  38.     private $valueOption;
  39.     /**
  40.      * @ORM\ManyToOne(targetEntity=Parameter::class, inversedBy="products")
  41.      * @ORM\JoinColumn(nullable=false)
  42.      */
  43.     private $parameter;
  44.     /**
  45.      * @ORM\Column(type="string", length=255, nullable=true)
  46.      */
  47.     private $ip;
  48.     /**
  49.      * @ORM\ManyToOne(targetEntity=Product::class, inversedBy="productParameters")
  50.      */
  51.     private $product;
  52.     /**
  53.      * @ORM\Column(type="datetime", nullable=true)
  54.      */
  55.     private $created;
  56.     /**
  57.      * @ORM\Column(type="datetime", nullable=true)
  58.      */
  59.     private $changed;
  60.     public function __construct()
  61.     {
  62.     }
  63.     public function getId(): ?int
  64.     {
  65.         return $this->id;
  66.     }
  67.     public function getValueNumber(): ?float
  68.     {
  69.         return $this->valueNumber;
  70.     }
  71.     public function setValueNumber(?float $valueNumber): self
  72.     {
  73.         $this->valueNumber $valueNumber;
  74.         return $this;
  75.     }
  76.     public function getValueText(): ?string
  77.     {
  78.         return $this->valueText;
  79.     }
  80.     public function setValueText(?string $valueText): self
  81.     {
  82.         $this->valueText $valueText;
  83.         return $this;
  84.     }
  85.     public function getValueRich(): ?string
  86.     {
  87.         return $this->valueRich;
  88.     }
  89.     public function setValueRich(?string $valueRich): self
  90.     {
  91.         $this->valueRich $valueRich;
  92.         return $this;
  93.     }
  94.     public function getValueOption(): ?Option
  95.     {
  96.         return $this->valueOption;
  97.     }
  98.     public function setValueOption(?Option $valueOption): self
  99.     {
  100.         $this->valueOption $valueOption;
  101.         return $this;
  102.     }
  103.     public function getParameter(): ?Parameter
  104.     {
  105.         return $this->parameter;
  106.     }
  107.     public function setParameter(?Parameter $parameter): self
  108.     {
  109.         $this->parameter $parameter;
  110.         return $this;
  111.     }
  112.     public function getIp(): ?string
  113.     {
  114.         return $this->ip;
  115.     }
  116.     public function setIp(?string $ip): self
  117.     {
  118.         $this->ip $ip;
  119.         return $this;
  120.     }
  121.     public function getProduct(): ?Product
  122.     {
  123.         return $this->product;
  124.     }
  125.     public function setProduct(?Product $product): self
  126.     {
  127.         $this->product $product;
  128.         return $this;
  129.     }
  130.     public function getCreated(): ?\DateTimeInterface
  131.     {
  132.         return $this->created;
  133.     }
  134.     public function setCreated(?\DateTimeInterface $created): self
  135.     {
  136.         $this->created $created;
  137.         return $this;
  138.     }
  139.     public function getChanged(): ?\DateTimeInterface
  140.     {
  141.         return $this->changed;
  142.     }
  143.     public function setChanged(?\DateTimeInterface $changed): self
  144.     {
  145.         $this->changed $changed;
  146.         return $this;
  147.     }
  148.     public function getValue(){
  149.         switch ($this->getParameter()->getType()){
  150.             case self::PRODUCT_PARAM_TYPE_NUMBER:
  151.                 return $this->getValueNumber();
  152.             case self::PRODUCT_PARAM_TYPE_SELECTBOX:
  153.                 return $this->getValueOption();
  154.             case self::PRODUCT_PARAM_TYPE_DATE:
  155.                 return $this->getValueText();
  156.             default:
  157.                 return $this->getValueText();
  158.         }
  159.     }
  160.     public function setValue($value){
  161.         switch ($this->getParameter()->getType()){
  162.             case self::PRODUCT_PARAM_TYPE_NUMBER:
  163.                 return $this->setValueNumber($value);
  164.             case self::PRODUCT_PARAM_TYPE_SELECTBOX:
  165.                 return $this->setValueOption($value);
  166.             case self::PRODUCT_PARAM_TYPE_RICH:
  167.                 return $this->setValueRich($value);
  168.             case self::PRODUCT_PARAM_TYPE_DATE:
  169.                 return $this->setValueText('2023-01-01');
  170.             default:
  171.                 return $this->setValueText($value);
  172.         }
  173.     }
  174.     /**
  175.      * @return Option|float|string|null
  176.      */
  177.     public function __toString(){
  178.         return (string)$this->getValue();
  179.     }
  180. }