import v1.1.0_beta1 | 2009-08-21
This commit is contained in:
54
libs/Monkeys/Iterator.php
Normal file
54
libs/Monkeys/Iterator.php
Normal file
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This iterator builds a collection filled with zeroes, except for the range it knows
|
||||
* the paginator will query it for.
|
||||
*/
|
||||
class Monkeys_Iterator implements Iterator, Countable
|
||||
{
|
||||
private $_numItems;
|
||||
private $_items;
|
||||
private $_index = 0;
|
||||
|
||||
public function __construct($items, $numItems, $recordsPerPage, $page)
|
||||
{
|
||||
if ($items) {
|
||||
$this->_items = array_fill(0, $numItems- 1, 0);
|
||||
} else {
|
||||
$this->_items = array();
|
||||
}
|
||||
|
||||
array_splice($this->_items, $recordsPerPage * ($page - 1), $recordsPerPage, $items);
|
||||
$this->_numItems = $numItems;
|
||||
}
|
||||
|
||||
public function current()
|
||||
{
|
||||
return $this->_items[$this->_index];
|
||||
}
|
||||
|
||||
public function key()
|
||||
{
|
||||
return $this->_index;
|
||||
}
|
||||
|
||||
public function next()
|
||||
{
|
||||
$this->_index++;
|
||||
}
|
||||
|
||||
public function rewind()
|
||||
{
|
||||
$this->_index = 0;
|
||||
}
|
||||
|
||||
public function valid()
|
||||
{
|
||||
return isset($this->_items[$this->_index]);
|
||||
}
|
||||
|
||||
public function count()
|
||||
{
|
||||
return $this->_numItems;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user