aboutsummaryrefslogtreecommitdiff
path: root/classes/IsisRowIterator.php
diff options
context:
space:
mode:
authorSilvio <silvio@devlet.com.br>2010-07-01 15:00:10 -0300
committerSilvio <silvio@devlet.com.br>2010-07-01 15:00:10 -0300
commitc2381df90612de26f2b3524897a61f0d8ad8cb0b (patch)
tree85cf4f26afffc08fcfaf84c99c129c7bea41e260 /classes/IsisRowIterator.php
parentd5cf91aecdf508993820773530e03ba7d06c612e (diff)
downloadcinisis-c2381df90612de26f2b3524897a61f0d8ad8cb0b.tar.gz
cinisis-c2381df90612de26f2b3524897a61f0d8ad8cb0b.tar.bz2
Adding IsisRowIterator
Diffstat (limited to 'classes/IsisRowIterator.php')
-rw-r--r--classes/IsisRowIterator.php58
1 files changed, 58 insertions, 0 deletions
diff --git a/classes/IsisRowIterator.php b/classes/IsisRowIterator.php
new file mode 100644
index 0000000..a81373e
--- /dev/null
+++ b/classes/IsisRowIterator.php
@@ -0,0 +1,58 @@
+<?php
+
+/**
+ * Iterates over all rows from a field result.
+ */
+class IsisRowIterator implements Iterator
+{
+ private $position = 0;
+ private $total = 0;
+
+ /**
+ * Constructor.
+ *
+ * @param $class
+ * Instance of IsisConnector or child class.
+ *
+ * @param $field
+ * Field to iterate over.
+ */
+ public function __construct($class, $field) {
+ $this->total = $class->getRows($field);
+ }
+
+ /**
+ * Rewind the Iterator to the first element.
+ */
+ function rewind() {
+ $this->position = 0;
+ }
+
+ /**
+ * Return the key of the current element.
+ */
+ function key() {
+ return $this->position;
+ }
+
+ /**
+ * Return the current element.
+ */
+ function current() {
+ return $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 $this->position <= $this->total;
+ }
+}