From 6b2c196c75b8b11cc9f9ffc645c25a555532f2f8 Mon Sep 17 00:00:00 2001 From: Silvio Date: Tue, 8 Jun 2010 12:00:29 -0300 Subject: Broken repetitive field handling in two methods at BiblioIsis --- classes/BiblioIsisDb.php | 72 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 50 insertions(+), 22 deletions(-) (limited to 'classes/BiblioIsisDb.php') diff --git a/classes/BiblioIsisDb.php b/classes/BiblioIsisDb.php index 4c4e5ce..8f341bd 100644 --- a/classes/BiblioIsisDb.php +++ b/classes/BiblioIsisDb.php @@ -165,27 +165,33 @@ class BiblioIsisDb implements IsisDb { $data[$name] = $this->repetition($key, $value); // Subfield handling. - if (isset($this->format['fields'][$key]['subfields']) && is_array($data[$name])) { - foreach ($data[$name] as $subkey => $subvalue) { - if (isset($this->format['fields'][$key]['subfields'][$subkey])) { - $subname = $this->format['fields'][$key]['subfields'][$subkey]; - } else { - $subname = $subkey; - } - - $data[$name][$subname] = $subvalue; - - if ($subkey != $subname) { - unset($data[$name][$subkey]); - } - } - } + $this->subfield($data, $name, $key); } } return $data; } + function subfield(&$data, $name, $key) { + if (isset($this->format['fields'][$key]['subfields']) && is_array($data[$name])) { + + foreach ($data[$name] as $subkey => $subvalue) { + if (isset($this->format['fields'][$key]['subfields'][$subkey])) { + $subname = $this->format['fields'][$key]['subfields'][$subkey]; + } else { + $subname = $subkey; + } + + $data[$name][$subname] = $subvalue; + + if ($subkey != $subname) { + unset($data[$name][$subkey]); + } + } + + } + } + /** * Deals with repetition. * @@ -196,19 +202,41 @@ class BiblioIsisDb implements IsisDb { * @param $field * Database field. * - * @param $value - * Query field result. - * * @return - * The value according to the repetition config. + * True if repetitive, false otherwise. */ - function repetition($field, $value) { + function is_repetitive($field, $value) { if (isset($this->format['fields'][$field]['repeat']) && $this->format['fields'][$field]['repeat'] == FALSE && is_array($value)) { - return $value[0]; + return FALSE; } - return $value; + return TRUE; + } + + /** + * Deals with repetition. + * + * As Biblio::Isis always return field values as arrays, we + * have to check the database schema to see if we have to + * convert then to a single value. + * + * @param $field + * Database field. + * + * @param $value + * Query field result. + * + * @return + * The value according to the repetition config. + */ + function repetition($key, $value) { + if ($this->is_repetitive($key, $value)) { + return $value; + } + else { + return $value[0]; + } } /** -- cgit v1.2.3