_pattern = $rowPattern; $this->_count = $count; $this->_patternRowsCount = $this->_pattern->getRowsCount(); $this->_limit = (int)$count * $this->_patternRowsCount; parent::__construct($this->_pattern->getHeaders()); } /** * Get row index for template * * @param int $key * * @return float */ public function getIndex($key) { return floor($key / $this->_patternRowsCount) + 1; } /** * Whether limit of generated elements is reached (according to "Iterator" interface) * * @return bool */ public function valid() { return $this->_key + 1 <= $this->_limit; } /** * Get next row in set * * @return array|bool */ protected function _getNextRow() { $key = $this->key(); $this->_index = $this->getIndex($key); if ($key > $this->_limit) { return false; } return $this->_pattern->getRow($this->_index, $key); } /** * Return the current element * * Returns the row in associative array format: array( => , ...) * * @return array */ public function current() { return $this->_row; } }