=1 && $itemsPerPage>=1) { $this->page = $page; } else { $this->page = 1; $this->itemsPerPage = max(count($this->theArray),1); } $this->theArray = &$theArray; $this->count = $totalItems; $this->itemsPerPage = $itemsPerPage; $this->wasEmpty = count($this->theArray)==0; reset($this->theArray); } /** * Return the next item in the iterator. * @return object */ function &next() { $value = ¤t($this->theArray); if (next($this->theArray)==null) { $this->theArray = null; } return $value; } /** * Return the next item in the iterator, with key. * @return array (key, value) */ function &nextWithKey() { $key = key($this->theArray); $value = $this->next(); return array($key, $value); } function atFirstPage() { return $this->page==1; } function atLastPage() { return ($this->page * $this->itemsPerPage) + 1 > $this->count; } function getPage() { return $this->page; } function getCount() { return $this->count; } function getPageCount() { return max(1, ceil($this->count / $this->itemsPerPage)); } /** * Return a boolean indicating whether or not we've reached the end of results * Note: This implementation requires that next() be called before every eof() will * function properly (except the first call). * @return boolean */ function eof() { return (($this->theArray == null) || (count($this->theArray)==0)); } /** * Return a boolean indicating whether or not this iterator was empty from the beginning * @return boolean */ function wasEmpty() { return $this->wasEmpty; } function &toArray() { return $this->theArray; } function array_slice_key($array, $offset, $len=-1) { // A version of array_slice that takes keys into account. // Thanks to pies at sputnik dot pl. (Retrieved from // http://ca3.php.net/manual/en/function.array-slice.php) // This is made redundant by PHP 5.0.2's updated // array_slice, but we can't assume everyone has that. if (!is_array($array)) return false; $return = array(); $length = $len >= 0? $len: count($array); $keys = array_slice(array_keys($array), $offset, $length); foreach($keys as $key) { $return[$key] = $array[$key]; } return $return; } } ?>