aboutsummaryrefslogtreecommitdiff
path: root/classes
diff options
context:
space:
mode:
authorSilvio <silvio@devlet.com.br>2010-07-07 12:17:34 -0300
committerSilvio <silvio@devlet.com.br>2010-07-07 12:17:34 -0300
commit4263906bee5e85ad067f9f752c5698ccdcc13d67 (patch)
tree29cb840fd2f4cc6e522be6a0df36cd7cbab852b1 /classes
parentffa45903b951f08df999bfd74a70a813852f8419 (diff)
downloadcinisis-4263906bee5e85ad067f9f752c5698ccdcc13d67.tar.gz
cinisis-4263906bee5e85ad067f9f752c5698ccdcc13d67.tar.bz2
Adding IsisFieldIterator
Diffstat (limited to 'classes')
-rw-r--r--classes/IsisFieldIterator.php65
1 files changed, 65 insertions, 0 deletions
diff --git a/classes/IsisFieldIterator.php b/classes/IsisFieldIterator.php
new file mode 100644
index 0000000..fb67b65
--- /dev/null
+++ b/classes/IsisFieldIterator.php
@@ -0,0 +1,65 @@
+<?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->valid());
+ }
+
+ /**
+ * Check if there is a current element after calls to rewind() or next().
+ */
+ function valid() {
+ return $this->row <= $this->rows;
+ }
+}