From 6491b4a4dc9257348fdb3674cffb7b9fc89f40d0 Mon Sep 17 00:00:00 2001 From: Silvio Date: Fri, 2 Jul 2010 15:05:09 -0300 Subject: Adding IsisValueIterator --- classes/IsisValueIterator.php | 73 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 classes/IsisValueIterator.php (limited to 'classes/IsisValueIterator.php') diff --git a/classes/IsisValueIterator.php b/classes/IsisValueIterator.php new file mode 100644 index 0000000..04b3d92 --- /dev/null +++ b/classes/IsisValueIterator.php @@ -0,0 +1,73 @@ +rows = $class->getRows($field); + $this->valueset = $class->getValues($field); + $this->keys = array_keys($this->valueset); + $this->values = count($this->keys); + } + + /** + * Rewind the Iterator to the first element. + */ + function rewind() { + $this->row = 0; + $this->value = 0; + } + + /** + * Return the key of the current element. + */ + function key() { + return $this->row; + } + + /** + * Return the current element. + */ + function current() { + return $this->valueset[$this->keys[$this->value]]; + } + + /** + * Move forward to next element. + */ + function next() { + if ($this->value >= $this->values) { + $this->value = 0; + ++$this->row; + } + else { + ++$this->value; + } + } + + /** + * Check if there is a current element after calls to rewind() or next(). + */ + function valid() { + return $this->row <= $this->rows; + } +} -- cgit v1.2.3