File: D:/HostingSpaces/SBogers10/blije-gasten.komma.pro/app/Komma/Kms/Core/Attributes/Number.php
<?php
namespace App\Komma\Kms\Core\Attributes;
use App\Komma\Kms\Core\Attributes\Traits\ExplanationTrait;
use App\Komma\Kms\Core\Attributes\Traits\LabelTrait;
use App\Komma\Kms\Core\Attributes\Traits\PlaceholderTextTrait;
use App\Komma\Kms\Core\Attributes\Traits\ReadOnlyTrait;
use App\Komma\Kms\Core\Sections\AttributeKey;
/**
* Class TextField
* @package App\Komma\Kms\Core\Attributes
*/
class Number extends Attribute
{
use LabelTrait;
use PlaceholderTextTrait;
use ReadOnlyTrait;
use ExplanationTrait;
/** @var $min int The minimum allowed value */
private $min;
/** @var $max int The maximum allowed value */
private $max;
/** @var $step float The legal number intervals */
private $step;
/**
* TextField constructor.
* @param string $labelText
*/
public function __construct(string $labelText)
{
$this->setLabelText($labelText);
$this->readOnly = false;
parent::__construct();
}
/**
* Returns a view that visually represents this attribute
*
* @return \Illuminate\Contracts\View\View
*/
public function render()
{
return view('kms/attributes.number', [
'attribute' => $this
]);
}
/**
* @return int
*/
public function getMin(): ?int
{
return $this->min;
}
/**
* @param int $min
* @return self
*/
public function setMin(int $min):self
{
$this->min = $min;
return $this;
}
/**
* @return int
*/
public function getMax(): ?int
{
return $this->max;
}
/**
* @param int $max
* @return self
*/
public function setMax(int $max):self
{
$this->max = $max;
return $this;
}
/**
* @return float
*/
public function getStep(): ?float
{
return $this->step;
}
/**
* @param float $step
* @return self
*/
public function setStep(float $step):self
{
$this->step = $step;
return $this;
}
/**
* Get value overwrite
* because the value may not be an empty string but should be 0 then
*
* @param $asFloat
* @return string
*/
public function getValue(bool $asFloat = false): string
{
$value = $this->value;
if(empty($value)) $value = 0;
if($asFloat) $value /= 100;
else $value *= 100;
return $value;
}
}