src/Entity/ItemSpecTypes.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Traits\CommonTrait;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  8. /**
  9.  * @ORM\Entity(repositoryClass="App\Repository\ItemSpecTypesRepository")
  10.  * @ORM\Table(name="itm_spec_types")
  11.  * @UniqueEntity({"uuid"})
  12.  * @ORM\HasLifecycleCallbacks()
  13.  */
  14. class ItemSpecTypes
  15. {
  16.     const MODE_CHECKBOX 'mode.checkbox';
  17.     const MODE_RANGE 'mode.range';
  18.     const MODE_RADIO 'mode.radio';
  19.     const MODE_TEXT 'mode.text';
  20.     const MODE_DATE 'mode.date';
  21.     const MODES = [
  22.         'Lista wielokrotnego wyboru' => self::MODE_CHECKBOX,
  23.         'Lista jednokrotnego wyboru' => self::MODE_RADIO,
  24.         'Zakres' => self::MODE_RANGE,
  25.         'Pole tekstowe' => self::MODE_TEXT,
  26.         'Kalendarz dostępności' => self::MODE_DATE,
  27.     ];
  28.     const MODES_R = [
  29.         self::MODE_CHECKBOX => 'Lista wielokrotnego wyboru',
  30.         self::MODE_RADIO => 'Lista jednokrotnego wyboru',
  31.         self::MODE_RANGE => 'Zakres',
  32.         self::MODE_TEXT => 'Pole tekstowe',
  33.         self::MODE_DATE => 'Kanlendarz dostępności',
  34.     ];
  35.     use CommonTrait;
  36.     /**
  37.      * @ORM\Column(type="string", length=255)
  38.      */
  39.     private $name;
  40.     /**
  41.      * @ORM\OneToMany(targetEntity=ItemSpec::class, mappedBy="itemSpecType", orphanRemoval=true, cascade={"persist"})
  42.      */
  43.     private $itemSpecValues;
  44.     /**
  45.      * @ORM\ManyToOne(targetEntity=ItemSpec::class, inversedBy="childSpecType", cascade={"persist"})
  46.      */
  47.     private $parentSpec;
  48.     /**
  49.      * @ORM\ManyToMany(targetEntity=ItemCategory::class, inversedBy="itemSpecTypes")
  50.      */
  51.     private $itemCategory;
  52.     /**
  53.      * @ORM\Column(type="string", length=255, nullable=true)
  54.      */
  55.     private $icon;
  56.     /**
  57.      * @ORM\Column(type="string", length=255, nullable=true)
  58.      */
  59.     private $color;
  60.     /**
  61.      * @ORM\Column(type="string", length=255)
  62.      */
  63.     private $mode;
  64.     /**
  65.      * @ORM\Column(type="decimal", precision=10, scale=2, nullable=true)
  66.      */
  67.     private $minValue;
  68.     /**
  69.      * @ORM\Column(type="decimal", precision=10, scale=0, nullable=true)
  70.      */
  71.     private $max;
  72.     /**
  73.      * @ORM\Column(type="string", length=255, nullable=true)
  74.      */
  75.     private $viewPrefix;
  76.     /**
  77.      * @ORM\Column(type="string", length=255, nullable=true)
  78.      */
  79.     private $viewSuffix;
  80.     /**
  81.      * @ORM\Column(type="string", length=255, nullable=true)
  82.      */
  83.     private $adminName;
  84.     /**
  85.      * @ORM\Column(type="string", length=255, nullable=true)
  86.      */
  87.     private $systemType;
  88.     /**
  89.      * @ORM\Column(type="boolean", nullable=true)
  90.      */
  91.     private $isRangeOnFilter;
  92.     /**
  93.      * @ORM\Column(type="boolean", nullable=true)
  94.      */
  95.     private $isDate;
  96.     /**
  97.      * @ORM\Column(type="decimal", precision=10, scale=0, nullable=true, options={"default": 100})
  98.      */
  99.     private $step;
  100.     public function __construct()
  101.     {
  102.         $this->itemSpecValues = new ArrayCollection();
  103.         $this->itemCategory = new ArrayCollection();
  104.     }
  105.     public function getName(): ?string
  106.     {
  107.         return $this->name;
  108.     }
  109.     public function setName(string $name): self
  110.     {
  111.         $this->name $name;
  112.         return $this;
  113.     }
  114.     public function getReadableMode()
  115.     {
  116.         return self::MODES_R[$this->getMode()];
  117.     }
  118.     /**
  119.      * @return Collection|ItemSpec[]
  120.      */
  121.     public function getItemSpecValues()
  122.     {
  123.         return $this->itemSpecValues->getValues();
  124.     }
  125.     public function addItemSpecValue(ItemSpec $itemSpecValue): self
  126.     {
  127.         if (!$this->itemSpecValues->contains($itemSpecValue)) {
  128.             $this->itemSpecValues[] = $itemSpecValue;
  129.             $itemSpecValue->setItemSpecType($this);
  130.         }
  131.         return $this;
  132.     }
  133.     public function removeItemSpecValue(ItemSpec $itemSpecValue): self
  134.     {
  135.         if ($this->itemSpecValues->contains($itemSpecValue)) {
  136.             $this->itemSpecValues->removeElement($itemSpecValue);
  137.             // set the owning side to null (unless already changed)
  138.             if ($itemSpecValue->getItemSpecType() === $this) {
  139.                 $itemSpecValue->setItemSpecType(null);
  140.             }
  141.         }
  142.         return $this;
  143.     }
  144.     public function __toString()
  145.     {
  146.         if($this->getAdminName()) {
  147.             return $this->getAdminName();
  148.         }
  149.         return $this->getName();
  150.     }
  151.     /**
  152.      * @return Collection|ItemCategory[]
  153.      */
  154.     public function getItemCategory(): Collection
  155.     {
  156.         return $this->itemCategory;
  157.     }
  158.     public function addItemCategory(ItemCategory $itemCategory): self
  159.     {
  160.         if (!$this->itemCategory->contains($itemCategory)) {
  161.             $this->itemCategory[] = $itemCategory;
  162.         }
  163.         return $this;
  164.     }
  165.     public function removeItemCategory(ItemCategory $itemCategory): self
  166.     {
  167.         if ($this->itemCategory->contains($itemCategory)) {
  168.             $this->itemCategory->removeElement($itemCategory);
  169.         }
  170.         return $this;
  171.     }
  172.     public function getIcon(): ?string
  173.     {
  174.         return $this->icon;
  175.     }
  176.     public function setIcon(?string $icon): self
  177.     {
  178.         $this->icon $icon;
  179.         return $this;
  180.     }
  181.     public function renderIcon($forTemplate false){
  182.         if($this->icon) {
  183.             $color '#000000';
  184.             if($this->color) {
  185.                 $color $this->color;
  186.             }
  187.             return '<i style="color: '.$color.'" class="'.$this->icon.'"></i>';
  188.         }
  189.         if(!$forTemplate) {
  190.             return '<span class="badge badge-secondary">Brak</span>';
  191.         }
  192.     }
  193.     public function getColor(): ?string
  194.     {
  195.         return $this->color;
  196.     }
  197.     public function setColor(?string $color): self
  198.     {
  199.         $this->color $color;
  200.         return $this;
  201.     }
  202.     public function getMode(): ?string
  203.     {
  204.         return $this->mode;
  205.     }
  206.     public function setMode(string $mode): self
  207.     {
  208.         $this->mode $mode;
  209.         return $this;
  210.     }
  211.     public function getMinValue(): ?string
  212.     {
  213.         return $this->minValue;
  214.     }
  215.     public function setMinValue(?string $minValue): self
  216.     {
  217.         $this->minValue $minValue;
  218.         return $this;
  219.     }
  220.     public function getMax(): ?string
  221.     {
  222.         return $this->max;
  223.     }
  224.     public function setMax(?string $max): self
  225.     {
  226.         $this->max $max;
  227.         return $this;
  228.     }
  229.     public function getViewSuffix(): ?string
  230.     {
  231.         return $this->viewSuffix;
  232.     }
  233.     public function setViewSuffix(?string $viewSuffix): self
  234.     {
  235.         $this->viewSuffix $viewSuffix;
  236.         return $this;
  237.     }
  238.     public function getViewPrefix(): ?string
  239.     {
  240.         return $this->viewPrefix;
  241.     }
  242.     public function setViewPrefix(?string $viewPrefix): self
  243.     {
  244.         $this->viewPrefix $viewPrefix;
  245.         return $this;
  246.     }
  247.     public function getAdminName(): ?string
  248.     {
  249.         return $this->adminName;
  250.     }
  251.     public function setAdminName(?string $adminName): self
  252.     {
  253.         $this->adminName $adminName;
  254.         return $this;
  255.     }
  256.     public function getSystemType(): ?string
  257.     {
  258.         return $this->systemType;
  259.     }
  260.     public function setSystemType(?string $systemType): self
  261.     {
  262.         $this->systemType $systemType;
  263.         return $this;
  264.     }
  265.     public function getIsRangeOnFilter(): ?bool
  266.     {
  267.         return $this->isRangeOnFilter;
  268.     }
  269.     public function setIsRangeOnFilter(?bool $isRangeOnFilter): self
  270.     {
  271.         $this->isRangeOnFilter $isRangeOnFilter;
  272.         return $this;
  273.     }
  274.     public function getIsDate(): ?bool
  275.     {
  276.         return $this->isDate;
  277.     }
  278.     public function setIsDate(?bool $isDate): self
  279.     {
  280.         $this->isDate $isDate;
  281.         return $this;
  282.     }
  283.     /**
  284.      * @return mixed
  285.      */
  286.     public function getParentSpec()
  287.     {
  288.         return $this->parentSpec;
  289.     }
  290.     /**
  291.      * @param mixed $parentSpec
  292.      */
  293.     public function setParentSpec($parentSpec): void
  294.     {
  295.         $this->parentSpec $parentSpec;
  296.     }
  297.     public function getStep(): ?string
  298.     {
  299.         if(!$this->step) {
  300.             return 100;
  301.         }
  302.         return $this->step;
  303.     }
  304.     public function setStep(?string $step): self
  305.     {
  306.         $this->step $step;
  307.         return $this;
  308.     }
  309. }