type = $type; $this->setValue($value); } /** * Get id * * @return int * * @since 1.0.0 */ public function getId() : int { return $this->id; } /** * Set l11n * * @param string|TaskAttributeValueL11n $l11n Tag article l11n * @param string $lang Language * * @return void * * @since 1.0.0 */ public function setL11n(string | TaskAttributeValueL11n $l11n, string $lang = ISO639x1Enum::_EN) : void { if ($l11n instanceof TaskAttributeValueL11n) { $this->l11n = $l11n; } elseif (isset($this->l11n) && $this->l11n instanceof TaskAttributeValueL11n) { $this->l11n->title = $l11n; } else { $this->l11n = new TaskAttributeValueL11n(); $this->l11n->title = $l11n; $this->l11n->setLanguage($lang); } } /** * Get localization * * @return null|string * * @since 1.0.0 */ public function getL11n() : ?string { return $this->l11n instanceof TaskAttributeValueL11n ? $this->l11n->title : $this->l11n; } /** * Set value * * @param int|string|float|\DateTimeInterface $value Value * * @return void * * @since 1.0.0 */ public function setValue(mixed $value) : void { if (\is_string($value)) { $this->valueStr = $value; } elseif (\is_int($value)) { $this->valueInt = $value; } elseif (\is_float($value)) { $this->valueDec = $value; } elseif ($value instanceof \DateTimeInterface) { $this->valueDat = $value; } } /** * Get value * * @return null|int|string|float|\DateTimeInterface * * @since 1.0.0 */ public function getValue() : mixed { if (!empty($this->valueStr)) { return $this->valueStr; } elseif (!empty($this->valueInt)) { return $this->valueInt; } elseif (!empty($this->valueDec)) { return $this->valueDec; } elseif ($this->valueDat instanceof \DateTimeInterface) { return $this->valueDat; } return null; } /** * {@inheritdoc} */ public function toArray() : array { return [ 'id' => $this->id, 'type' => $this->type, 'valueInt' => $this->valueInt, 'valueStr' => $this->valueStr, 'valueDec' => $this->valueDec, 'valueDat' => $this->valueDat, 'isDefault' => $this->isDefault, ]; } /** * {@inheritdoc} */ public function jsonSerialize() : mixed { return $this->toArray(); } }