diff options
-rw-r--r-- | classes/BiblioIsisDb.php | 8 | ||||
-rw-r--r-- | classes/IsisConnector.php | 49 | ||||
-rw-r--r-- | classes/iterators/IsisFieldIterator.php | 3 | ||||
-rw-r--r-- | classes/iterators/IsisMainFieldIterator.php | 7 |
4 files changed, 56 insertions, 11 deletions
diff --git a/classes/BiblioIsisDb.php b/classes/BiblioIsisDb.php index d32f548..eabf892 100644 --- a/classes/BiblioIsisDb.php +++ b/classes/BiblioIsisDb.php @@ -352,6 +352,9 @@ class BiblioIsisDb implements IsisDb { * * @return * Boolean. + * + * @todo + * Should be added at IsisDb interface? */ public function join_subfields() { if ($this->format['db']['join_subfields']) { @@ -368,7 +371,10 @@ class BiblioIsisDb implements IsisDb { * Field key. * * @return - * Main field name, 'field' by default; + * Main field name, 'field' by default. + * + * @todo + * Should be added at IsisDb interface? */ public function main_field_name($key) { if ($this->join_subfields()) { diff --git a/classes/IsisConnector.php b/classes/IsisConnector.php index e7eb4c6..a5b5227 100644 --- a/classes/IsisConnector.php +++ b/classes/IsisConnector.php @@ -39,6 +39,34 @@ class IsisConnector { } /** + * Get the main field name. + * + * @param $field + * Field data from ISIS database schema. + * + * @return + * Main field name. + */ + public function getMainFieldName($field) { + $key = $this->getFieldKey($field); + return $this->isis->db->main_field_name($key); + } + + /** + * Whether to join field and subfields in a single array. + * + * @return + * Boolean. + */ + public function joinSubfields() { + if ($this->isis->db->join_subfields()) { + return TRUE; + } + + return FALSE; + } + + /** * Get all values of a given field. * * @param $field @@ -81,8 +109,10 @@ class IsisConnector { * Field data. */ public function getField($field, $row = 0) { - if (isset($this->result[$field['name']][$row]['field'])) { - return $this->result[$field['name']][$row]['field']; + $name = $this->getMainFieldName($field); + + if (isset($this->result[$field['name']][$row][$name])) { + return $this->result[$field['name']][$row][$name]; } } @@ -119,8 +149,15 @@ class IsisConnector { * Subfield data. */ public function getSubfield($field, $subfield, $row = 0) { - if (isset($this->result[$field['name']][$row]['subfields'][$subfield])) { - return $this->result[$field['name']][$row]['subfields'][$subfield]; + if ($this->joinSubfields()) { + $subfields = $this->result[$field['name']][$row]; + } + else { + $subfields = $this->result[$field['name']][$row]['subfields']; + } + + if (isset($subfields[$subfield])) { + return $subfields[$subfield]; } } @@ -536,8 +573,8 @@ class IsisConnector { public function hasFieldSubfieldCondition($field, $subfield, $key, $subkey) { $field_key = $this->getFieldKey($field); $subdield_key = $this->getSubfieldKey($field, $subfield); - if ($field_key == $key && $subfield_key == $subkey) - { + + if ($field_key == $key && $subfield_key == $subkey) { return true; } diff --git a/classes/iterators/IsisFieldIterator.php b/classes/iterators/IsisFieldIterator.php index 09f4867..26c5e88 100644 --- a/classes/iterators/IsisFieldIterator.php +++ b/classes/iterators/IsisFieldIterator.php @@ -27,9 +27,6 @@ class IsisFieldIterator implements Iterator * @param $main * Control to which subfield the main field should be mapped to. * By default no mapping is made. - * - * @todo - * Implement $main mapping. */ public function __construct($class, $field, $main = false) { $this->class = $class; diff --git a/classes/iterators/IsisMainFieldIterator.php b/classes/iterators/IsisMainFieldIterator.php index 68430b8..5ec1cbc 100644 --- a/classes/iterators/IsisMainFieldIterator.php +++ b/classes/iterators/IsisMainFieldIterator.php @@ -9,6 +9,8 @@ */ class IsisMainFieldIterator implements Iterator { + private $class; + private $field; private $valueset; private $row = 0; private $rows = 0; @@ -25,6 +27,8 @@ class IsisMainFieldIterator implements Iterator public function __construct($class, $field) { $this->rows = $class->getRows($field); $this->valueset = $class->getValues($field); + $this->class = $class; + $this->field = $field; } /** @@ -46,7 +50,8 @@ class IsisMainFieldIterator implements Iterator * Return the current element. */ function current() { - return $this->valueset[$this->row]['field']; + $field = $this->class->getMainFieldName($this->field); + return $this->valueset[$this->row][$field]; } /** |