RangeViewHelper.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace Opentalent\OtTemplating\ViewHelpers\Utilities;
  3. use Closure;
  4. use Opentalent\OtCore\ViewHelpers\OtAbstractViewHelper;
  5. use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
  6. /**
  7. * Returns an array of integers going from i to j
  8. *
  9. * {namespace ot=Opentalent\OtTemplating\ViewHelpers}
  10. *
  11. * {ot:utilities.range(i: 0, j: 10)}
  12. *
  13. * @package Opentalent\OtTemplating\ViewHelpers
  14. */
  15. class RangeViewHelper extends OtAbstractViewHelper {
  16. /**
  17. * -- This method is expected by Fluid --
  18. * Declares the viewhelper's parameters
  19. */
  20. public function initializeArguments()
  21. {
  22. $this->registerArgument('i',
  23. 'integer',
  24. "Low limit",
  25. true);
  26. $this->registerArgument('j',
  27. 'integer',
  28. "High limit",
  29. true);
  30. }
  31. /**
  32. * -- This method is expected by Fluid --
  33. * Renders the content as html
  34. *
  35. * @param array $arguments
  36. * @param Closure $renderChildrenClosure
  37. * @param RenderingContextInterface $renderingContext
  38. * @return string|null
  39. */
  40. public static function renderStatic(
  41. array $arguments,
  42. Closure $renderChildrenClosure,
  43. RenderingContextInterface $renderingContext
  44. ) {
  45. $i = $arguments['i'];
  46. $j = $arguments['j'];
  47. $array = [];
  48. for($x=$i;$x<=$j;$x++) {
  49. $array[] = $x;
  50. }
  51. return $array;
  52. }
  53. }