TYPO3 CMS  TYPO3_6-2
CycleViewHelper.php
Go to the documentation of this file.
1 <?php
3 
4 /* *
5  * This script is backported from the TYPO3 Flow package "TYPO3.Fluid". *
6  * *
7  * It is free software; you can redistribute it and/or modify it under *
8  * the terms of the GNU Lesser General Public License, either version 3 *
9  * of the License, or (at your option) any later version. *
10  * *
11  * The TYPO3 project - inspiring people to share! *
12  * */
13 
49 
55  protected $values = NULL;
56 
62  protected $currentCycleIndex = NULL;
63 
70  public function render($values, $as) {
71  if ($values === NULL) {
72  return $this->renderChildren();
73  }
74  if ($this->values === NULL) {
75  $this->initializeValues($values);
76  }
77  if ($this->currentCycleIndex === NULL || $this->currentCycleIndex >= count($this->values)) {
78  $this->currentCycleIndex = 0;
79  }
80 
81  $currentValue = isset($this->values[$this->currentCycleIndex]) ? $this->values[$this->currentCycleIndex] : NULL;
82  $this->templateVariableContainer->add($as, $currentValue);
83  $output = $this->renderChildren();
84  $this->templateVariableContainer->remove($as);
85 
86  $this->currentCycleIndex ++;
87 
88  return $output;
89  }
90 
98  protected function initializeValues($values) {
99  if (is_object($values)) {
100  if (!$values instanceof \Traversable) {
101  throw new \TYPO3\CMS\Fluid\Core\ViewHelper\Exception('CycleViewHelper only supports arrays and objects implementing \Traversable interface' , 1248728394);
102  }
103  $this->values = iterator_to_array($values, FALSE);
104  } else {
105  $this->values = array_values($values);
106  }
107  $this->currentCycleIndex = 0;
108  }
109 }