aboutsummaryrefslogtreecommitdiff
path: root/classes/iterators
diff options
context:
space:
mode:
Diffstat (limited to 'classes/iterators')
-rw-r--r--classes/iterators/IsisItemIterator.php85
-rw-r--r--classes/iterators/IsisMainItemIterator.php (renamed from classes/iterators/IsisMainFieldIterator.php)4
-rw-r--r--classes/iterators/IsisNormalItemFilterIterator.php18
-rw-r--r--classes/iterators/IsisNormalSubfieldFilterIterator.php18
-rw-r--r--classes/iterators/IsisSubfieldIterator.php (renamed from classes/iterators/IsisFieldIterator.php)7
5 files changed, 107 insertions, 25 deletions
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 @@
+<?php
+
+/**
+ * Isis field iterator. Iterates over a field for each result row.
+ */
+class IsisItemIterator implements Iterator
+{
+ private $keys;
+ private $fieldset;
+ private $row = 0;
+ private $rows = 0;
+ private $item = 0;
+ private $items = 0;
+
+ /**
+ * Constructor.
+ *
+ * @param $class
+ * Instance of IsisConnector or child class.
+ *
+ * @param $field
+ * Field to iterate over.
+ *
+ * @param $main
+ * Control to which item the main field should be mapped to.
+ * By default no mapping is made.
+ */
+ public function __construct($class, $field, $main = false) {
+ $this->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/IsisMainItemIterator.php
index 5ec1cbc..02ab8d1 100644
--- a/classes/iterators/IsisMainFieldIterator.php
+++ b/classes/iterators/IsisMainItemIterator.php
@@ -7,7 +7,7 @@
* @todo
* Support for 'join_subfields'
*/
-class IsisMainFieldIterator implements Iterator
+class IsisMainItemIterator implements Iterator
{
private $class;
private $field;
@@ -50,7 +50,7 @@ class IsisMainFieldIterator implements Iterator
* Return the current element.
*/
function current() {
- $field = $this->class->getMainFieldName($this->field);
+ $field = $this->class->getMainItemName($this->field);
return $this->valueset[$this->row][$field];
}
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 @@
+<?php
+
+/**
+ * Isis normal subfield iterator. Filter out special subfields.
+ */
+class IsisNormalItemFilterIterator extends FilterIterator {
+
+ /**
+ * Filter out special subfields.
+ */
+ public function accept()
+ {
+ $field = $this->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 @@
-<?php
-
-/**
- * Isis normal subfield iterator. Filter out special subfields.
- */
-class IsisNormalSubfieldFilterIterator extends FilterIterator {
-
- /**
- * Filter out special subfields.
- */
- 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/IsisFieldIterator.php b/classes/iterators/IsisSubfieldIterator.php
index 26c5e88..2e213cf 100644
--- a/classes/iterators/IsisFieldIterator.php
+++ b/classes/iterators/IsisSubfieldIterator.php
@@ -1,12 +1,9 @@
<?php
/**
- * Isis field iterator. Iterates over a field for each result row.
- *
- * @todo
- * Support for 'join_subfields'
+ * Isis subfield iterator. Iterates over subfields for each result row.
*/
-class IsisFieldIterator implements Iterator
+class IsisSubfieldIterator implements Iterator
{
private $keys;
private $fieldset;