<?php

namespace Opentalent\OtTemplating\ViewHelpers\Utilities;

use Closure;
use Opentalent\OtCore\ViewHelpers\OtAbstractViewHelper;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;

/**
 *   Returns an array of integers going from i to j
 *
 *     {namespace ot=Opentalent\OtTemplating\ViewHelpers}
 *
 *     {ot:utilities.range(i: 0, j: 10)}
 *
 * @package Opentalent\OtTemplating\ViewHelpers
 */
class RangeViewHelper extends OtAbstractViewHelper {

    /**
     * -- This method is expected by Fluid --
     * Declares the viewhelper's parameters
     */
    public function initializeArguments()
    {
        $this->registerArgument('i',
            'integer',
            "Low limit",
            true);
        $this->registerArgument('j',
            'integer',
            "High limit",
            true);
    }

    /**
     * -- This method is expected by Fluid --
     * Renders the content as html
     *
     * @param array $arguments
     * @param Closure $renderChildrenClosure
     * @param RenderingContextInterface $renderingContext
     * @return string|null
     */
    public static function renderStatic(
        array $arguments,
        Closure $renderChildrenClosure,
        RenderingContextInterface $renderingContext
    ) {
        $i = $arguments['i'];
        $j = $arguments['j'];
        $array = [];
        for($x=$i;$x<=$j;$x++) {
            $array[] = $x;
        }
        return $array;
    }
}
