From d5762ebb744f5b4873e6ad779d96b694c8f0839f Mon Sep 17 00:00:00 2001 From: Silvio Date: Thu, 1 Jul 2010 14:30:21 -0300 Subject: Adding IsisConnector::getRows() and minor changes --- classes/IsisConnector.php | 22 +++++++++-- classes/IsisMethodIterator.php | 3 +- classes/IsisSubfieldIterator.php | 85 ++++++++++++++++++---------------------- 3 files changed, 59 insertions(+), 51 deletions(-) (limited to 'classes') diff --git a/classes/IsisConnector.php b/classes/IsisConnector.php index 237d139..071736b 100644 --- a/classes/IsisConnector.php +++ b/classes/IsisConnector.php @@ -55,6 +55,19 @@ class IsisConnector { return array(); } + /** + * Get the number of resulting rows for a given field. + * + * @param $field + * Field array. + * + * @return + * Number of rows. + */ + public function getRows($field) { + return count($this->result[$field['name']]); + } + /** * Get the value of a given field. * @@ -83,8 +96,8 @@ class IsisConnector { * Field data. */ public function getFields($field) { - for ($n = 0; $n >= count($this->result[$field['name']]); $n++) { - $values[$n] = $this->getField($field, $n); + for ($row = 0; $row >= $this->getRows($field); $row++) { + $values[$row] = $this->getField($field, $row); } return $values; @@ -124,8 +137,8 @@ class IsisConnector { * Subfield data. */ public function getSubfields($field, $subfield) { - for ($n = 0; $n >= count($this->result[$field['name']]); $n++) { - $values[$n] = $this->getSubfield($field, $subfield, $n); + for ($row = 0; $row >= $this->getRows($field); $row++) { + $values[$row] = $this->getSubfield($field, $subfield, $row); } return $values; @@ -141,6 +154,7 @@ class IsisConnector { if (isset($field['subfields'])) { return $field['subfields']; } + return array(); } diff --git a/classes/IsisMethodIterator.php b/classes/IsisMethodIterator.php index 0cb7dd4..51820ed 100644 --- a/classes/IsisMethodIterator.php +++ b/classes/IsisMethodIterator.php @@ -44,7 +44,8 @@ class IsisMethodIterator implements Iterator } /** - * Move forward to next element. + * Move forward to next element. The method should be callabe, otherwise + * we move to the next position. */ function next() { do { diff --git a/classes/IsisSubfieldIterator.php b/classes/IsisSubfieldIterator.php index 70ff07f..4c6086b 100644 --- a/classes/IsisSubfieldIterator.php +++ b/classes/IsisSubfieldIterator.php @@ -3,50 +3,43 @@ // TODO: not working class IsisSubfieldIterator implements Iterator { - private $position = 0; - private $class; - private $field; - private $subfields; - private $keys; - - 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); - } - - function subfield() - { - return $this->subfields[$this->key()]; - } - - function rewind() - { - $this->position = 0; - } - - function current() - { - $value = $this->class->getSubfield($this->field, $this->subfield()); - return $this->class->explodeValue($value); - } - - function key() - { - return $this->keys[$this->position]; - } - - function next() - { - ++$this->position; - } - - function valid() - { - return isset($this->keys[$this->position]) && ($this->current() != null); - } + private $position = 0; + private $class; + private $field; + private $subfields; + private $keys; + + 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); + } + + function subfield() { + return $this->subfields[$this->key()]; + } + + function rewind() { + $this->position = 0; + } + + function current() { + $value = $this->class->getSubfield($this->field, $this->subfield()); + return $this->class->explodeValue($value); + } + + function key() { + return $this->keys[$this->position]; + } + + function next() { + ++$this->position; + } + + function valid() { + return isset($this->keys[$this->position]) && ($this->current() != null); + } } -- cgit v1.2.3