From 70d0c6f95279f67f863cf6cb8e2a0528534c4519 Mon Sep 17 00:00:00 2001 From: Silvio Date: Wed, 18 Aug 2010 18:29:51 -0300 Subject: Enhancing nextSubfield() from IsisFinder --- classes/IsisConnector.php | 2 +- classes/IsisFinder.php | 30 ++++++++++++++++++++++++++---- 2 files changed, 27 insertions(+), 5 deletions(-) (limited to 'classes') diff --git a/classes/IsisConnector.php b/classes/IsisConnector.php index e0c87c2..64a6c59 100644 --- a/classes/IsisConnector.php +++ b/classes/IsisConnector.php @@ -633,7 +633,7 @@ class IsisConnector { } /** - * Check if a field result has a given subfield. + * Check if a field result and row has a given subfield. * * @param $field * Field data. diff --git a/classes/IsisFinder.php b/classes/IsisFinder.php index 80057c1..1f8ed0f 100644 --- a/classes/IsisFinder.php +++ b/classes/IsisFinder.php @@ -80,8 +80,7 @@ class IsisFinder extends IsisConnector { * Next occurrence. * * @todo - * The subfield might be in any now and not just - * in the first one. + * Test. */ public function nextSubfield($entry = 1, $field, $subfield) { $entry--; @@ -92,12 +91,35 @@ class IsisFinder extends IsisConnector { if ($entry == $entries) { break; } - } while (!isset($result[$field][0][$subfield])); + $has = $this->hasSubfieldInRows($field, $subfield); + } while ($has === FALSE); - if (!isset($result[$field][0][$subfield])) { + if (!isset($result[$field][$has][$subfield])) { return FALSE; } return array($entry, $result); } + + /** + * Check if a field result has a given subfield. + * + * @param $field + * Field data. + * + * @param $subfield + * Subfield. + * + * @return + * True if result has the subfield, false otherwise. + */ + public function hasSubfieldInRows($field, $subfield) { + foreach (new IsisRowIterator($this, $field) as $row) { + if ($this->hasSubfield($field, $subfield, $row)) { + return $row; + } + } + + return FALSE; + } } -- cgit v1.2.3