HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/reiskick.komma.nl/vendor/komma/kms/src/Core/Attributes/Numeric.php
<?php
namespace Komma\KMS\Core\Attributes;
use Komma\KMS\Core\Attributes\Interfaces\HasLabelInterface;
use Komma\KMS\Core\Attributes\Traits\ExplanationTrait;
use Komma\KMS\Core\Attributes\Traits\LabelTrait;
use Komma\KMS\Core\Attributes\Traits\ReadOnlyTrait;

/**
 * Class TextField
 * @package App\Kms\Core\Attributes
 */
class Numeric extends Attribute implements HasLabelInterface
{
    use LabelTrait;
    use ExplanationTrait;
    use ReadOnlyTrait;

    /**  The max amount of decimals allowed */
    private int $fractionLength = 0;

    /** A string that is put between the whole and max  */
    private string $separator = ',';

    /** A string that is put before the whole part */
    private string $prefix = '';

    /** A string that is put after the fraction part */
    private string $suffix = '';
    
    private int $wholeStep = 1;

    private int $wholeMin = 0;
    
    private ?int $wholeMax = null;

    private int $fractionStep = 1;

    private int $fractionMin = 0;

    private ?int $fractionMax = null;

    private bool $zeropadFraction = false;

    /**
     * @return string
     * @throws \Throwable
     */
    public function render(): string
    {
        return view('KMS::attributes.numeric', [
            'attribute' => $this,
            'key' => $this->getKey(),
            'styleClass' => $this->getStyleClass(),
            'value' => $this->value,
            'dataAttributes' => $this->getDataAttributes(),
            'fractionLength' => $this->fractionLength,
            'separator' => $this->separator,
            'prefix' => $this->prefix,
            'suffix' => $this->suffix,
            'wholeMin' => $this->wholeMin,
            'wholeMax' => $this->wholeMax,
            'wholeStep' => $this->wholeStep,
            'fractionMin' => $this->fractionMin,
            'fractionMax' => $this->fractionMax,
            'fractionStep' => $this->fractionStep,
            'zeroPadFraction' => $this->zeropadFraction,
        ])->render();
    }

    /**
     * @return int
     */
    public function getFractionLength(): int
    {
        return $this->fractionLength;
    }

    /**
     * @param int $fractionLength
     * @return Numeric
     */
    public function setFractionLength(int $fractionLength): Numeric
    {
        $this->fractionLength = $fractionLength;
        return $this;
    }

    /**
     * @return string
     */
    public function getSeparator(): string
    {
        return $this->separator;
    }

    /**
     * @param string $separator
     * @return Numeric
     */
    public function setSeparator(string $separator): Numeric
    {
        $this->separator = $separator;
        return $this;
    }

    /**
     * @return string
     */
    public function getPrefix(): string
    {
        return $this->prefix;
    }

    /**
     * @param string $prefix
     * @return Numeric
     */
    public function setPrefix(string $prefix): Numeric
    {
        $this->prefix = $prefix;
        return $this;
    }

    /**
     * @return string
     */
    public function getSuffix(): string
    {
        return $this->suffix;
    }

    /**
     * @param string $suffix
     * @return Numeric
     */
    public function setSuffix(string $suffix): Numeric
    {
        $this->suffix = $suffix;
        return $this;
    }

    /**
     * @return int
     */
    public function getWholeStep(): int
    {
        return $this->wholeStep;
    }

    /**
     * @param int $wholeStep
     * @return Numeric
     */
    public function setWholeStep(int $wholeStep): Numeric
    {
        $this->wholeStep = $wholeStep;
        return $this;
    }

    /**
     * @return int
     */
    public function getWholeMin(): int
    {
        return $this->wholeMin;
    }

    /**
     * @param int $wholeMin
     * @return Numeric
     */
    public function setWholeMin(int $wholeMin): Numeric
    {
        $this->wholeMin = $wholeMin;
        return $this;
    }

    /**
     * @return int
     */
    public function getWholeMax(): int
    {
        return $this->wholeMax;
    }

    /**
     * @param int $wholeMax
     * @return Numeric
     */
    public function setWholeMax(int $wholeMax): Numeric
    {
        $this->wholeMax = $wholeMax;
        return $this;
    }

    /**
     * @return int
     */
    public function getFractionStep(): int
    {
        return $this->fractionStep;
    }

    /**
     * @param int $fractionStep
     * @return Numeric
     */
    public function setFractionStep(int $fractionStep): Numeric
    {
        $this->fractionStep = $fractionStep;
        return $this;
    }

    /**
     * @return int
     */
    public function getFractionMin(): int
    {
        return $this->fractionMin;
    }

    /**
     * @param int $fractionMin
     * @return Numeric
     */
    public function setFractionMin(int $fractionMin): Numeric
    {
        $this->fractionMin = $fractionMin;
        return $this;
    }

    /**
     * @return int
     */
    public function getFractionMax(): int
    {
        return $this->fractionMax;
    }

    /**
     * @param int $fractionMax
     * @return Numeric
     */
    public function setFractionMax(int $fractionMax): Numeric
    {
        $this->fractionMax = $fractionMax;
        return $this;
    }

    /**
     * Call this function to prepend leading zeros to the fraction till it does match the fraction length.
     *
     * @param bool $pad
     * @return Numeric
     */
    public function setFractionZeroPadding($pad = true) {
        $this->zeropadFraction = $pad;
        return $this;
    }

    public function getReadOnlyValue(): string
    {
        $valueString = '';

        if(!empty($this->prefix)) $valueString .= $this->prefix . ' ';

        if($this->getFractionLength() != 0) {
            $numericValue = explode('.', $this->value / (10 * $this->getFractionLength()));
            $valueString .= $numericValue[0] . $this->separator . $numericValue[1];
        }
        else $valueString .= $this->value;

        if(!empty($this->suffix)) $valueString .= ' ' . $this->suffix;

        return $valueString;
    }

}