aboutsummaryrefslogtreecommitdiff
path: root/classes/IsisSubfieldIterator.php
diff options
context:
space:
mode:
Diffstat (limited to 'classes/IsisSubfieldIterator.php')
-rw-r--r--classes/IsisSubfieldIterator.php35
1 files changed, 33 insertions, 2 deletions
diff --git a/classes/IsisSubfieldIterator.php b/classes/IsisSubfieldIterator.php
index 4c6086b..6f70d87 100644
--- a/classes/IsisSubfieldIterator.php
+++ b/classes/IsisSubfieldIterator.php
@@ -1,6 +1,11 @@
<?php
-// TODO: not working
+/**
+ * Isis subfield iterator.
+ *
+ * @todo
+ * It's not working.
+ */
class IsisSubfieldIterator implements Iterator
{
private $position = 0;
@@ -9,36 +14,62 @@ class IsisSubfieldIterator implements Iterator
private $subfields;
private $keys;
+ /**
+ * 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->subfields = $class->getSubfields($field);
$this->keys = array_values($this->subfields);
$this->total = count($this->class->result[$field['name']);
- print_r($field);
}
+ /**
+ * Get the current subfield.
+ */
function subfield() {
return $this->subfields[$this->key()];
}
+ /**
+ * Rewind the Iterator to the first element.
+ */
function rewind() {
$this->position = 0;
}
+ /**
+ * Return the current element.
+ */
function current() {
$value = $this->class->getSubfield($this->field, $this->subfield());
return $this->class->explodeValue($value);
}
+ /**
+ * Return the key of the current element.
+ */
function key() {
return $this->keys[$this->position];
}
+ /**
+ * Move forward to next element.
+ */
function next() {
++$this->position;
}
+ /**
+ * Check if there is a current element after calls to rewind() or next().
+ */
function valid() {
return isset($this->keys[$this->position]) && ($this->current() != null);
}