From 1d84217ed97be237d2696c85a997c9e52114b984 Mon Sep 17 00:00:00 2001 From: Silvio Date: Mon, 19 Jul 2010 18:04:40 -0300 Subject: Lots of API changes at IsisConnector and iterators --- classes/iterators/IsisFieldIterator.php | 81 -------------------- classes/iterators/IsisItemIterator.php | 85 +++++++++++++++++++++ classes/iterators/IsisMainFieldIterator.php | 87 ---------------------- classes/iterators/IsisMainItemIterator.php | 87 ++++++++++++++++++++++ classes/iterators/IsisNormalItemFilterIterator.php | 18 +++++ .../iterators/IsisNormalSubfieldFilterIterator.php | 18 ----- classes/iterators/IsisSubfieldIterator.php | 78 +++++++++++++++++++ 7 files changed, 268 insertions(+), 186 deletions(-) delete mode 100644 classes/iterators/IsisFieldIterator.php create mode 100644 classes/iterators/IsisItemIterator.php delete mode 100644 classes/iterators/IsisMainFieldIterator.php create mode 100644 classes/iterators/IsisMainItemIterator.php create mode 100644 classes/iterators/IsisNormalItemFilterIterator.php delete mode 100644 classes/iterators/IsisNormalSubfieldFilterIterator.php create mode 100644 classes/iterators/IsisSubfieldIterator.php (limited to 'classes/iterators') diff --git a/classes/iterators/IsisFieldIterator.php b/classes/iterators/IsisFieldIterator.php deleted file mode 100644 index 26c5e88..0000000 --- a/classes/iterators/IsisFieldIterator.php +++ /dev/null @@ -1,81 +0,0 @@ -class = $class; - $this->field = $field; - $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->row = 0; - $this->subfield = 0; - } - - /** - * Return the key of the current element. - */ - function key() { - return $this->row; - } - - /** - * Return the current element. - */ - function current() { - return $this->fieldset[$this->keys[$this->subfield]]; - } - - /** - * Move forward to next element. - */ - function next() { - 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 $this->row <= $this->rows; - } -} diff --git a/classes/iterators/IsisItemIterator.php b/classes/iterators/IsisItemIterator.php new file mode 100644 index 0000000..5c28b2c --- /dev/null +++ b/classes/iterators/IsisItemIterator.php @@ -0,0 +1,85 @@ +class = $class; + $this->field = $field; + $this->rows = $class->getRows($field); + + // Handle subfields + $this->fieldset = $class->getSubfieldList($field); + $this->keys = array_keys($this->fieldset); + $this->items = count($this->keys); + + // Sum up main item + $this->fieldset[] = $class->getMainItem($field); + $this->keys[] = $class->getMainItemName($field); + $this->items++; + } + + /** + * Rewind the Iterator to the first element. + */ + function rewind() { + $this->row = 0; + $this->item = 0; + } + + /** + * Return the key of the current element. + */ + function key() { + return $this->row; + } + + /** + * Return the current element. + */ + function current() { + return $this->fieldset[$this->keys[$this->item]]; + } + + /** + * Move forward to next element. + */ + function next() { + if ($this->item >= $this->items) { + $this->item = 0; + ++$this->row; + } + else { + ++$this->item; + } + } + + /** + * Check if there is a current element after calls to rewind() or next(). + */ + function valid() { + return $this->row <= $this->rows; + } +} diff --git a/classes/iterators/IsisMainFieldIterator.php b/classes/iterators/IsisMainFieldIterator.php deleted file mode 100644 index 5ec1cbc..0000000 --- a/classes/iterators/IsisMainFieldIterator.php +++ /dev/null @@ -1,87 +0,0 @@ -rows = $class->getRows($field); - $this->valueset = $class->getValues($field); - $this->class = $class; - $this->field = $field; - } - - /** - * 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() { - $field = $this->class->getMainFieldName($this->field); - return $this->valueset[$this->row][$field]; - } - - /** - * Move forward to next element. - */ - function next() { - do { - ++$this->row; - } - while ($this->current_null() && $this->has_more_rows()); - } - - /** - * Check if there are more rows. - */ - function has_more_rows() { - return $this->row <= $this->rows; - } - - /** - * Check if the current value is null. - */ - function current_null() { - return $this->current() == NULL; - } - - /** - * Check if there is a current element after calls to rewind() or next(). - */ - function valid() { - return $this->has_more_rows() && !$this->current_null(); - } -} diff --git a/classes/iterators/IsisMainItemIterator.php b/classes/iterators/IsisMainItemIterator.php new file mode 100644 index 0000000..02ab8d1 --- /dev/null +++ b/classes/iterators/IsisMainItemIterator.php @@ -0,0 +1,87 @@ +rows = $class->getRows($field); + $this->valueset = $class->getValues($field); + $this->class = $class; + $this->field = $field; + } + + /** + * 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() { + $field = $this->class->getMainItemName($this->field); + return $this->valueset[$this->row][$field]; + } + + /** + * Move forward to next element. + */ + function next() { + do { + ++$this->row; + } + while ($this->current_null() && $this->has_more_rows()); + } + + /** + * Check if there are more rows. + */ + function has_more_rows() { + return $this->row <= $this->rows; + } + + /** + * Check if the current value is null. + */ + function current_null() { + return $this->current() == NULL; + } + + /** + * Check if there is a current element after calls to rewind() or next(). + */ + function valid() { + return $this->has_more_rows() && !$this->current_null(); + } +} diff --git a/classes/iterators/IsisNormalItemFilterIterator.php b/classes/iterators/IsisNormalItemFilterIterator.php new file mode 100644 index 0000000..e59d7c6 --- /dev/null +++ b/classes/iterators/IsisNormalItemFilterIterator.php @@ -0,0 +1,18 @@ +getInnerIterator()->field; + $class = $this->getInnerIterator()->class; + $item = $this->getInnerIterator()->current(); + return !$class->specialItem($field, $item); + } +} diff --git a/classes/iterators/IsisNormalSubfieldFilterIterator.php b/classes/iterators/IsisNormalSubfieldFilterIterator.php deleted file mode 100644 index 5a3f4ce..0000000 --- a/classes/iterators/IsisNormalSubfieldFilterIterator.php +++ /dev/null @@ -1,18 +0,0 @@ -getInnerIterator()->field; - $class = $this->getInnerIterator()->class; - $subfield = $this->getInnerIterator()->current(); - return !$class->specialSubfield($field, $subfield); - } -} diff --git a/classes/iterators/IsisSubfieldIterator.php b/classes/iterators/IsisSubfieldIterator.php new file mode 100644 index 0000000..2e213cf --- /dev/null +++ b/classes/iterators/IsisSubfieldIterator.php @@ -0,0 +1,78 @@ +class = $class; + $this->field = $field; + $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->row = 0; + $this->subfield = 0; + } + + /** + * Return the key of the current element. + */ + function key() { + return $this->row; + } + + /** + * Return the current element. + */ + function current() { + return $this->fieldset[$this->keys[$this->subfield]]; + } + + /** + * Move forward to next element. + */ + function next() { + 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 $this->row <= $this->rows; + } +} -- cgit v1.2.3