<?php
namespace App\Entity;
use App\Entity\Traits\CommonTrait;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
/**
* @ORM\Entity(repositoryClass="App\Repository\ItemSpecTypesRepository")
* @ORM\Table(name="itm_spec_types")
* @UniqueEntity({"uuid"})
* @ORM\HasLifecycleCallbacks()
*/
class ItemSpecTypes
{
const MODE_CHECKBOX = 'mode.checkbox';
const MODE_RANGE = 'mode.range';
const MODE_RADIO = 'mode.radio';
const MODE_TEXT = 'mode.text';
const MODE_DATE = 'mode.date';
const MODES = [
'Lista wielokrotnego wyboru' => self::MODE_CHECKBOX,
'Lista jednokrotnego wyboru' => self::MODE_RADIO,
'Zakres' => self::MODE_RANGE,
'Pole tekstowe' => self::MODE_TEXT,
'Kalendarz dostępności' => self::MODE_DATE,
];
const MODES_R = [
self::MODE_CHECKBOX => 'Lista wielokrotnego wyboru',
self::MODE_RADIO => 'Lista jednokrotnego wyboru',
self::MODE_RANGE => 'Zakres',
self::MODE_TEXT => 'Pole tekstowe',
self::MODE_DATE => 'Kanlendarz dostępności',
];
use CommonTrait;
/**
* @ORM\Column(type="string", length=255)
*/
private $name;
/**
* @ORM\OneToMany(targetEntity=ItemSpec::class, mappedBy="itemSpecType", orphanRemoval=true, cascade={"persist"})
*/
private $itemSpecValues;
/**
* @ORM\ManyToOne(targetEntity=ItemSpec::class, inversedBy="childSpecType", cascade={"persist"})
*/
private $parentSpec;
/**
* @ORM\ManyToMany(targetEntity=ItemCategory::class, inversedBy="itemSpecTypes")
*/
private $itemCategory;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $icon;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $color;
/**
* @ORM\Column(type="string", length=255)
*/
private $mode;
/**
* @ORM\Column(type="decimal", precision=10, scale=2, nullable=true)
*/
private $minValue;
/**
* @ORM\Column(type="decimal", precision=10, scale=0, nullable=true)
*/
private $max;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $viewPrefix;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $viewSuffix;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $adminName;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $systemType;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $isRangeOnFilter;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $isDate;
/**
* @ORM\Column(type="decimal", precision=10, scale=0, nullable=true, options={"default": 100})
*/
private $step;
public function __construct()
{
$this->itemSpecValues = new ArrayCollection();
$this->itemCategory = new ArrayCollection();
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getReadableMode()
{
return self::MODES_R[$this->getMode()];
}
/**
* @return Collection|ItemSpec[]
*/
public function getItemSpecValues()
{
return $this->itemSpecValues->getValues();
}
public function addItemSpecValue(ItemSpec $itemSpecValue): self
{
if (!$this->itemSpecValues->contains($itemSpecValue)) {
$this->itemSpecValues[] = $itemSpecValue;
$itemSpecValue->setItemSpecType($this);
}
return $this;
}
public function removeItemSpecValue(ItemSpec $itemSpecValue): self
{
if ($this->itemSpecValues->contains($itemSpecValue)) {
$this->itemSpecValues->removeElement($itemSpecValue);
// set the owning side to null (unless already changed)
if ($itemSpecValue->getItemSpecType() === $this) {
$itemSpecValue->setItemSpecType(null);
}
}
return $this;
}
public function __toString()
{
if($this->getAdminName()) {
return $this->getAdminName();
}
return $this->getName();
}
/**
* @return Collection|ItemCategory[]
*/
public function getItemCategory(): Collection
{
return $this->itemCategory;
}
public function addItemCategory(ItemCategory $itemCategory): self
{
if (!$this->itemCategory->contains($itemCategory)) {
$this->itemCategory[] = $itemCategory;
}
return $this;
}
public function removeItemCategory(ItemCategory $itemCategory): self
{
if ($this->itemCategory->contains($itemCategory)) {
$this->itemCategory->removeElement($itemCategory);
}
return $this;
}
public function getIcon(): ?string
{
return $this->icon;
}
public function setIcon(?string $icon): self
{
$this->icon = $icon;
return $this;
}
public function renderIcon($forTemplate = false){
if($this->icon) {
$color = '#000000';
if($this->color) {
$color = $this->color;
}
return '<i style="color: '.$color.'" class="'.$this->icon.'"></i>';
}
if(!$forTemplate) {
return '<span class="badge badge-secondary">Brak</span>';
}
}
public function getColor(): ?string
{
return $this->color;
}
public function setColor(?string $color): self
{
$this->color = $color;
return $this;
}
public function getMode(): ?string
{
return $this->mode;
}
public function setMode(string $mode): self
{
$this->mode = $mode;
return $this;
}
public function getMinValue(): ?string
{
return $this->minValue;
}
public function setMinValue(?string $minValue): self
{
$this->minValue = $minValue;
return $this;
}
public function getMax(): ?string
{
return $this->max;
}
public function setMax(?string $max): self
{
$this->max = $max;
return $this;
}
public function getViewSuffix(): ?string
{
return $this->viewSuffix;
}
public function setViewSuffix(?string $viewSuffix): self
{
$this->viewSuffix = $viewSuffix;
return $this;
}
public function getViewPrefix(): ?string
{
return $this->viewPrefix;
}
public function setViewPrefix(?string $viewPrefix): self
{
$this->viewPrefix = $viewPrefix;
return $this;
}
public function getAdminName(): ?string
{
return $this->adminName;
}
public function setAdminName(?string $adminName): self
{
$this->adminName = $adminName;
return $this;
}
public function getSystemType(): ?string
{
return $this->systemType;
}
public function setSystemType(?string $systemType): self
{
$this->systemType = $systemType;
return $this;
}
public function getIsRangeOnFilter(): ?bool
{
return $this->isRangeOnFilter;
}
public function setIsRangeOnFilter(?bool $isRangeOnFilter): self
{
$this->isRangeOnFilter = $isRangeOnFilter;
return $this;
}
public function getIsDate(): ?bool
{
return $this->isDate;
}
public function setIsDate(?bool $isDate): self
{
$this->isDate = $isDate;
return $this;
}
/**
* @return mixed
*/
public function getParentSpec()
{
return $this->parentSpec;
}
/**
* @param mixed $parentSpec
*/
public function setParentSpec($parentSpec): void
{
$this->parentSpec = $parentSpec;
}
public function getStep(): ?string
{
if(!$this->step) {
return 100;
}
return $this->step;
}
public function setStep(?string $step): self
{
$this->step = $step;
return $this;
}
}