diff options
Diffstat (limited to 'classes/iterators')
-rw-r--r-- | classes/iterators/IsisFieldIterator.php | 79 | ||||
-rw-r--r-- | classes/iterators/IsisMethodIterator.php | 63 | ||||
-rw-r--r-- | classes/iterators/IsisNormalSubfieldFilterIterator.php | 14 | ||||
-rw-r--r-- | classes/iterators/IsisRowIterator.php | 58 | ||||
-rw-r--r-- | classes/iterators/IsisSubfieldIterator.php | 75 | ||||
-rw-r--r-- | classes/iterators/IsisValueIterator.php | 62 |
6 files changed, 351 insertions, 0 deletions
diff --git a/classes/iterators/IsisFieldIterator.php b/classes/iterators/IsisFieldIterator.php new file mode 100644 index 0000000..11ed979 --- /dev/null +++ b/classes/iterators/IsisFieldIterator.php @@ -0,0 +1,79 @@ +<?php + +/** + * Isis field iterator. Iterates over all field values for + * each result row. + */ +class IsisFieldIterator implements Iterator +{ + private $valueset; + private $row = 0; + private $rows = 0; + + /** + * Constructor. + * + * @param $class + * Instance of IsisConnector or child class. + * + * @param $field + * Field to iterate over. + */ + public function __construct($class, $field) { + $this->rows = $class->getRows($field); + $this->valueset = $class->getValues($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() { + 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/IsisMethodIterator.php b/classes/iterators/IsisMethodIterator.php new file mode 100644 index 0000000..4e5871c --- /dev/null +++ b/classes/iterators/IsisMethodIterator.php @@ -0,0 +1,63 @@ +<?php + +/** + * Iterates over all callable methods for database mapping. + */ +class IsisMethodIterator implements Iterator +{ + private $total = 0; + private $class; + private $keys; + + /** + * Constructor. + * + * @param $class + * Instance of IsisConnector or child class. + */ + public function __construct($class) { + $this->class = $class; + $this->total = count($class->fields); + $this->keys = array_keys($class->fields); + } + + /** + * Rewind the Iterator to the first element. + */ + function rewind() { + $this->position = 0; + } + + /** + * Return the key of the current element. + */ + function key() { + $type = $this->class->getMapType($this->current()); + return $this->class->methodName($type); + } + + /** + * Return the current element. + */ + function current() { + return $this->class->fields[$this->keys[$this->position]]; + } + + /** + * Move forward to next element. The method should be callable, otherwise + * we move to the next position. + */ + function next() { + do { + ++$this->position; + } + while (!is_callable(array($this->class, $this->key())) && $this->valid()); + } + + /** + * Check if there is a current element after calls to rewind() or next(). + */ + function valid() { + return $this->position <= $this->total; + } +} diff --git a/classes/iterators/IsisNormalSubfieldFilterIterator.php b/classes/iterators/IsisNormalSubfieldFilterIterator.php new file mode 100644 index 0000000..98494a6 --- /dev/null +++ b/classes/iterators/IsisNormalSubfieldFilterIterator.php @@ -0,0 +1,14 @@ +<?php + +/** + * Isis normal subfield iterator. Filter out special subfields. + */ +class IsisNormalSubfieldFilterIterator extends FilterIterator { + public function accept() + { + $field = $this->getInnerIterator()->field; + $class = $this->getInnerIterator()->class; + $subfield = $this->getInnerIterator()->current(); + return !$class->specialSubfield($field, $subfield); + } +} diff --git a/classes/iterators/IsisRowIterator.php b/classes/iterators/IsisRowIterator.php new file mode 100644 index 0000000..739db22 --- /dev/null +++ b/classes/iterators/IsisRowIterator.php @@ -0,0 +1,58 @@ +<?php + +/** + * Iterates over all rows from a field result. + */ +class IsisRowIterator implements Iterator +{ + private $row = 0; + private $rows = 0; + + /** + * Constructor. + * + * @param $class + * Instance of IsisConnector or child class. + * + * @param $field + * Field to iterate over. + */ + public function __construct($class, $field) { + $this->rows = $class->getRows($field); + } + + /** + * Rewind the Iterator to the first element. + */ + function rewind() { + $this->row = 0; + } + + /** + * Return the key of the current element. + */ + function key() { + return $this->row; + } + + /** + * Return the current element. + */ + function current() { + return $this->row; + } + + /** + * Move forward to next element. + */ + function next() { + ++$this->row; + } + + /** + * 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/IsisSubfieldIterator.php b/classes/iterators/IsisSubfieldIterator.php new file mode 100644 index 0000000..36d3d06 --- /dev/null +++ b/classes/iterators/IsisSubfieldIterator.php @@ -0,0 +1,75 @@ +<?php + +/** + * Isis subfield iterator. Iterates over all subfields for + * each result row. + */ +class IsisSubfieldIterator implements Iterator +{ + private $keys; + private $fieldset; + private $row = 0; + private $rows = 0; + private $subfield = 0; + private $subfields = 0; + + /** + * Constructor. + * + * @param $class + * Instance of IsisConnector or child class. + * + * @param $field + * Field to iterate over. + */ + public function __construct($class, $field) { + $this->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/IsisValueIterator.php b/classes/iterators/IsisValueIterator.php new file mode 100644 index 0000000..f10125d --- /dev/null +++ b/classes/iterators/IsisValueIterator.php @@ -0,0 +1,62 @@ +<?php + +/** + * Isis value iterator. Iterates over all values for + * each result row. + */ +class IsisValueIterator implements Iterator +{ + private $valueset; + private $row = 0; + private $rows = 0; + + /** + * Constructor. + * + * @param $class + * Instance of IsisConnector or child class. + * + * @param $field + * Field to iterate over. + */ + public function __construct($class, $field) { + $this->rows = $class->getRows($field); + $this->valueset = $class->getValues($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() { + return $this->valueset[$this->row]; + } + + /** + * Move forward to next element. + */ + function next() { + ++$this->row; + } + + /** + * Check if there is a current element after calls to rewind() or next(). + */ + function valid() { + return $this->row <= $this->rows; + } +} |