From 4bc6c646b13f6172a0b8df309b5bce7b30d0d67f Mon Sep 17 00:00:00 2001 From: Silvio Date: Mon, 19 Jul 2010 14:19:57 -0300 Subject: Introducing 'join_subfields' config parameter --- classes/BiblioIsisDb.php | 54 ++++++++++++++++++++++++++++++++++++++++++++---- classes/MaleteDb.php | 5 +++++ classes/PhpIsisDb.php | 5 +++++ schemas/fbe.yaml | 7 ++++--- 4 files changed, 64 insertions(+), 7 deletions(-) diff --git a/classes/BiblioIsisDb.php b/classes/BiblioIsisDb.php index c86af0b..d32f548 100644 --- a/classes/BiblioIsisDb.php +++ b/classes/BiblioIsisDb.php @@ -261,7 +261,7 @@ class BiblioIsisDb implements IsisDb { } else { foreach ($name as $value) { - $data[] = array('field' => $value); + $data[] = array($this->main_field_name($key) => $value); } } @@ -269,7 +269,12 @@ class BiblioIsisDb implements IsisDb { } /** - * Subfield handling for data read by 'to_hash' method. + * Subfield handling for data read by 'to_hash' method. This method + * is not fully supported and therefore not recommended. + * + * It does not deal very well when data has "main" fields and + * subfields (like "data1^adata2^bdata3") and doesn't deal with + * advanced configuration such as 'join_subfields'. * * @param $name * Dataset. @@ -311,9 +316,11 @@ class BiblioIsisDb implements IsisDb { if (substr($value, 0, 1) != '^') { $field = preg_replace('/\^.*/', '', $value); $subfields = substr($value, strlen($field) + 1); + $subfields = (!empty($subfields)) ? $subfields = explode('^', $subfields) : array(); - $data[$entry]['field'] = $field; - $subfields = (!empty($subfields)) ? $subfields = explode('^', $subfields) : array(); + if (isset($field)) { + $data[$entry]['field'] = $field; + } } else { $subfields = explode('^', substr($value, 1)); @@ -327,11 +334,50 @@ class BiblioIsisDb implements IsisDb { } $data[$entry]['subfields'][$subkey] = substr($subvalue, 1); } + + // Join subfields and main field if needed. + if ($this->join_subfields()) { + $data[$entry] = $data[$entry]['subfields']; + if (isset($field)) { + $data[$entry][$this->main_field_name($key)] = $field; + } + } } return $data; } + /** + * Whether to join field and subfields in a single array. + * + * @return + * Boolean. + */ + public function join_subfields() { + if ($this->format['db']['join_subfields']) { + return TRUE; + } + + return FALSE; + } + + /** + * Determine the main field name depending on db configuration. + * + * @param $key + * Field key. + * + * @return + * Main field name, 'field' by default; + */ + public function main_field_name($key) { + if ($this->join_subfields()) { + return $this->format['fields'][$key]['name']; + } + + return 'field'; + } + /** * Deals with repetition. * diff --git a/classes/MaleteDb.php b/classes/MaleteDb.php index 201ddc0..e7d50a5 100644 --- a/classes/MaleteDb.php +++ b/classes/MaleteDb.php @@ -2,6 +2,11 @@ /** * Malete implementation of IsisDb. + * + * @todo + * This implementation is currently outdated and lacks + * basic functionalities such as subfield handling and + * therefore it's use is not recommended. */ class MaleteDb implements IsisDb { /** diff --git a/classes/PhpIsisDb.php b/classes/PhpIsisDb.php index 6d39d6e..03e9b7c 100644 --- a/classes/PhpIsisDb.php +++ b/classes/PhpIsisDb.php @@ -2,6 +2,11 @@ /** * PHP-Isis implementation of IsisDb. + * + * @todo + * This implementation is currently outdated and lacks + * basic functionalities such as subfield handling and + * therefore it's use is not recommended. */ class PhpIsisDb implements IsisDb { /** diff --git a/schemas/fbe.yaml b/schemas/fbe.yaml index d3337e0..d4ecad6 100644 --- a/schemas/fbe.yaml +++ b/schemas/fbe.yaml @@ -1,8 +1,9 @@ --- db: - name: fbe - charset: cp850 - base_model: Film + name: fbe + charset: cp850 + base_model: Film + join_subfields: Yes fields: # # General -- cgit v1.2.3