aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSilvio <silvio@devlet.com.br>2010-07-07 17:45:05 -0300
committerSilvio <silvio@devlet.com.br>2010-07-07 17:45:05 -0300
commit28382b8eede5c593b984dcd2888e1f5f1c12b563 (patch)
treeb06dd1f11a5626824a19f596a78987b4092429d5
parent474a3e1b190e2e3dbc5806350f37d28001c9b222 (diff)
downloadcinisis-28382b8eede5c593b984dcd2888e1f5f1c12b563.tar.gz
cinisis-28382b8eede5c593b984dcd2888e1f5f1c12b563.tar.bz2
Adding normalizeFieldName() and mapName() at IsisConnector
-rw-r--r--classes/IsisConnector.php33
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);
+ }
}