aboutsummaryrefslogtreecommitdiff
path: root/classes
diff options
context:
space:
mode:
authorSilvio <silvio@devlet.com.br>2010-07-01 18:36:48 -0300
committerSilvio <silvio@devlet.com.br>2010-07-01 18:36:48 -0300
commitfdff8aba1a0040ca47a0370b8b099b021754a3bd (patch)
treedd44fbdafc1caee4cce631be97b0d75a4306dc0a /classes
parentd1ba6eb119236ba38c50b07c75d5ff433f5221d6 (diff)
downloadcinisis-fdff8aba1a0040ca47a0370b8b099b021754a3bd.tar.gz
cinisis-fdff8aba1a0040ca47a0370b8b099b021754a3bd.tar.bz2
Fixing IsisSubfieldIterator
Diffstat (limited to 'classes')
-rw-r--r--classes/IsisRowIterator.php16
-rw-r--r--classes/IsisSubfieldIterator.php61
2 files changed, 37 insertions, 40 deletions
diff --git a/classes/IsisRowIterator.php b/classes/IsisRowIterator.php
index a81373e..739db22 100644
--- a/classes/IsisRowIterator.php
+++ b/classes/IsisRowIterator.php
@@ -5,8 +5,8 @@
*/
class IsisRowIterator implements Iterator
{
- private $position = 0;
- private $total = 0;
+ private $row = 0;
+ private $rows = 0;
/**
* Constructor.
@@ -18,41 +18,41 @@ class IsisRowIterator implements Iterator
* Field to iterate over.
*/
public function __construct($class, $field) {
- $this->total = $class->getRows($field);
+ $this->rows = $class->getRows($field);
}
/**
* Rewind the Iterator to the first element.
*/
function rewind() {
- $this->position = 0;
+ $this->row = 0;
}
/**
* Return the key of the current element.
*/
function key() {
- return $this->position;
+ return $this->row;
}
/**
* Return the current element.
*/
function current() {
- return $this->position;
+ return $this->row;
}
/**
* Move forward to next element.
*/
function next() {
- ++$this->position;
+ ++$this->row;
}
/**
* Check if there is a current element after calls to rewind() or next().
*/
function valid() {
- return $this->position <= $this->total;
+ return $this->row <= $this->rows;
}
}
diff --git a/classes/IsisSubfieldIterator.php b/classes/IsisSubfieldIterator.php
index 6f70d87..8a35399 100644
--- a/classes/IsisSubfieldIterator.php
+++ b/classes/IsisSubfieldIterator.php
@@ -1,18 +1,17 @@
<?php
/**
- * Isis subfield iterator.
- *
- * @todo
- * It's not working.
+ * Isis subfield iterator. Iterates over all subfields for
+ * each result row.
*/
class IsisSubfieldIterator implements Iterator
{
- private $position = 0;
- private $class;
- private $field;
- private $subfields;
private $keys;
+ private $fieldset;
+ private $row = 0;
+ private $rows = 0;
+ private $subfield = 0;
+ private $subfields = 0;
/**
* Constructor.
@@ -22,55 +21,53 @@ class IsisSubfieldIterator implements Iterator
*
* @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']);
- }
-
- /**
- * Get the current subfield.
- */
- function subfield() {
- return $this->subfields[$this->key()];
+ $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->position = 0;
+ $this->row = 0;
+ $this->subfield = 0;
}
/**
- * Return the current element.
+ * Return the key of the current element.
*/
- function current() {
- $value = $this->class->getSubfield($this->field, $this->subfield());
- return $this->class->explodeValue($value);
+ function key() {
+ return $this->row;
}
/**
- * Return the key of the current element.
+ * Return the current element.
*/
- function key() {
- return $this->keys[$this->position];
+ function current() {
+ return $this->fieldset[$this->keys[$this->subfield]];
}
/**
* Move forward to next element.
*/
function next() {
- ++$this->position;
+ 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 isset($this->keys[$this->position]) && ($this->current() != null);
- }
+ return $this->row <= $this->rows;
+ }
}