diff options
author | Silvio <silvio@devlet.com.br> | 2010-07-07 17:45:05 -0300 |
---|---|---|
committer | Silvio <silvio@devlet.com.br> | 2010-07-07 17:45:05 -0300 |
commit | 28382b8eede5c593b984dcd2888e1f5f1c12b563 (patch) | |
tree | b06dd1f11a5626824a19f596a78987b4092429d5 /classes | |
parent | 474a3e1b190e2e3dbc5806350f37d28001c9b222 (diff) | |
download | cinisis-28382b8eede5c593b984dcd2888e1f5f1c12b563.tar.gz cinisis-28382b8eede5c593b984dcd2888e1f5f1c12b563.tar.bz2 |
Adding normalizeFieldName() and mapName() at IsisConnector
Diffstat (limited to 'classes')
-rw-r--r-- | classes/IsisConnector.php | 33 |
1 files changed, 26 insertions, 7 deletions
diff --git a/classes/IsisConnector.php b/classes/IsisConnector.php index 9cbb1a6..7eb7bf9 100644 --- a/classes/IsisConnector.php +++ b/classes/IsisConnector.php @@ -196,19 +196,16 @@ class IsisConnector { * * @return * A map destination to the field or subfield. - * - * @todo - * Convert field and subfield names to valid field names. */ public function getMap($field, $subfield = NULL) { if ($subfield == NULL) { if (isset($field['map']['field'])) { // Custom map provided. - $dest = 'set'. ucfirst($field['map']['field']); + $dest = $this->mapName($field['map']['field']); } else { // Default map. - $dest = 'set'. ucfirst($field['name']); + $dest = $this->mapName($field['name']); } } else { @@ -216,11 +213,11 @@ class IsisConnector { if (isset($field['map']['subfields'][$key])) { // Custom map provided. - $dest = 'set'. ucfirst($field['map']['subfields'][$key]); + $dest = $this->mapName($field['map']['subfields'][$key]); } else { // Default map. - $dest = 'set'. ucfirst($subfield); + $dest = $this->mapName($subfield); } } @@ -449,4 +446,26 @@ class IsisConnector { public function filterSubfield($field, $subfield, $row) { return $this->filterBrackets($this->getSubfield($field, $subfield, $row)); } + + /** + * Normalize field names. + * + * @param string $name Field name + * @return string Normalized field name + */ + static function normalizeFieldName($name) + { + return ucfirst(preg_replace('/[^a-z0-9_]/', '', strtolower($name))); + } + + /** + * Build a map name. + * + * @param string $name Field name + * @return string Map name + */ + static function mapName($name) + { + return 'set'. self::normalizeFieldName($name); + } } |