Skip to content

Instantly share code, notes, and snippets.

@lozcalver
Created September 23, 2016 10:52
Show Gist options
  • Save lozcalver/bf1ea91fd49d8b7248743dab17c7ac5a to your computer and use it in GitHub Desktop.
Save lozcalver/bf1ea91fd49d8b7248743dab17c7ac5a to your computer and use it in GitHub Desktop.
<?php
class CustomIteratorSupport implements TemplateIteratorProvider {
protected $iteratorPos;
protected $iteratorTotalItems;
/**
* Set the current iterator properties - where we are on the iterator.
*
* @param int $pos position in iterator
* @param int $totalItems total number of items
*/
public function iteratorProperties($pos, $totalItems) {
$this->iteratorPos = $pos;
$this->iteratorTotalItems = $totalItems;
}
/**
* @return array
*/
public static function get_template_iterator_variables() {
return array('MultiplyPos');
}
/**
* Return the numerical position of this object in the container set, multiplied by the given amount
*
* @param int $startIndex Number to start count from.
* @param int $multiple Number to multiply the position by
* @return int
*/
public function MultiplyPos($startIndex = 1, $multiple = 1) {
return ($this->iteratorPos + $startIndex) * $multiple;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment