From fdff8aba1a0040ca47a0370b8b099b021754a3bd Mon Sep 17 00:00:00 2001 From: Silvio Date: Thu, 1 Jul 2010 18:36:48 -0300 Subject: Fixing IsisSubfieldIterator --- classes/IsisSubfieldIterator.php | 61 +++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 32 deletions(-) (limited to 'classes/IsisSubfieldIterator.php') diff --git a/classes/IsisSubfieldIterator.php b/classes/IsisSubfieldIterator.php index 6f70d87..8a35399 100644 --- a/classes/IsisSubfieldIterator.php +++ b/classes/IsisSubfieldIterator.php @@ -1,18 +1,17 @@ class = $class; - $this->field = $field; - $this->subfields = $class->getSubfields($field); - $this->keys = array_values($this->subfields); - $this->total = count($this->class->result[$field['name']); - } - - /** - * Get the current subfield. - */ - function subfield() { - return $this->subfields[$this->key()]; + $this->rows = $class->getRows($field); + $this->fieldset = $class->getSubfieldList($field); + $this->keys = array_keys($this->fieldset); + $this->subfields = count($this->keys); } /** * Rewind the Iterator to the first element. */ function rewind() { - $this->position = 0; + $this->row = 0; + $this->subfield = 0; } /** - * Return the current element. + * Return the key of the current element. */ - function current() { - $value = $this->class->getSubfield($this->field, $this->subfield()); - return $this->class->explodeValue($value); + function key() { + return $this->row; } /** - * Return the key of the current element. + * Return the current element. */ - function key() { - return $this->keys[$this->position]; + function current() { + return $this->fieldset[$this->keys[$this->subfield]]; } /** * Move forward to next element. */ function next() { - ++$this->position; + if ($this->subfield >= $this->subfields) { + $this->subfield = 0; + ++$this->row; + } + else { + ++$this->subfield; + } } /** * Check if there is a current element after calls to rewind() or next(). */ function valid() { - return isset($this->keys[$this->position]) && ($this->current() != null); - } + return $this->row <= $this->rows; + } } -- cgit v1.2.3