From 4cfb71f1f5c302061a7188081a17f0366a2da963 Mon Sep 17 00:00:00 2001 From: Silvio Date: Thu, 19 Aug 2010 16:29:40 -0300 Subject: Adding IsisEntryIterator --- classes/IsisFinder.php | 51 ++++++++++++-------------------------------------- 1 file changed, 12 insertions(+), 39 deletions(-) (limited to 'classes/IsisFinder.php') diff --git a/classes/IsisFinder.php b/classes/IsisFinder.php index e4f228d..26430c6 100644 --- a/classes/IsisFinder.php +++ b/classes/IsisFinder.php @@ -17,22 +17,13 @@ class IsisFinder extends IsisConnector { * Next repetition entry and result. */ public function nextRepetition($entry = 1, $field) { - $entry--; - - // Query database. - do { - $result = $this->read(++$entry); - if ($entry == $entries) { - break; + foreach(new IsisEntryIterator($this, $entry) as $entry => $result) { + if (count($this->getValues($field)) >= 2) { + return array($entry, $result); } - $values = $this->getValues($field); - } while (count($values) < 2); - - if (count($values) < 2) { - return FALSE; } - return array($entry, $result); + return FALSE; } /** @@ -48,22 +39,13 @@ class IsisFinder extends IsisConnector { * Next occurrence. */ public function nextField($entry = 1, $field) { - $entry--; - - // Query database. - do { - $result = $this->read(++$entry); - if ($entry == $entries) { - break; + foreach(new IsisEntryIterator($this, $entry) as $entry => $result) { + if (count($this->getValues($field)) > 0) { + return array($entry, $result); } - $values = $this->getValues($field); - } while (empty($values)); - - if (empty($values)) { - return FALSE; } - return array($entry, $result); + return FALSE; } /** @@ -82,22 +64,13 @@ class IsisFinder extends IsisConnector { * Next occurrence. */ public function nextSubfield($entry = 1, $field, $subfield) { - $entry--; - - // Query database. - do { - $result = $this->read(++$entry); - if ($entry == $entries) { - break; + foreach(new IsisEntryIterator($this, $entry) as $entry => $result) { + if ($this->hasSubfieldInRows($field, $subfield) !== FALSE) { + return array($entry, $result); } - $has = $this->hasSubfieldInRows($field, $subfield); - } while ($has === FALSE); - - if (!$this->hasSubfield($field, $subfield, $has)) { - return FALSE; } - return array($entry, $result); + return FALSE; } /** -- cgit v1.2.3