/** * Walk $this->attrs array * and return a set of $k=$v * to be used in an update stmt * * @param $k string array key * @param $v string array value * @return void */ private function escape(&$value, $key) { $db = DB::getInstance(); $type = DataMapping::getDataType($this->table['table'], $key); if ($type == 'string') { if ($value == 'null' || $value == '') { $value = 'null'; } else { $value = "'" . $db->db_escape_string($value) . "'"; } } else { $value = $value == '' || is_null($value) ? 'NULL' : $value; } }
protected function processNode($node, $_dtd_element_id, $dom) { // Converts XML to DOM document format for display on screen foreach ($node->childNodes as $child_node) { if ($child_node->childNodes && $child_node->firstChild->nodeType == 3) { // Node has children but the child is a text node, so get the value // Might need to be aware of whitespace characters returning as empty text node // instead of the required value $node_value = trim($child_node->firstChild->nodeValue); } else { $node_value = ''; } $external_code = $node_value; $defdetail = new DataDefinitionDetail(); $defdetail->loadBy(array('parent_id', 'element'), array($_dtd_element_id, $child_node->tagName)); $datamap = $defdetail->data_map; $translation = $datamaprule = $datamapdetail = ''; if (!is_null($defdetail->data_mapping_rule_id)) { $datamaprule = new DataMappingRule(); $datamaprule->load($defdetail->data_mapping_rule_id); $translation = $node_value; if ($datamaprule->isLoaded()) { if (!is_null($datamaprule->external_format)) { $validate_errors = array(); $translation = $datamaprule->validate($node_value, $validate_errors); if (count($validate_errors) > 0) { $this->log_errors[] = $key . ' "' . $node_value . '" : ' . implode(',', $validate_errors); } } $datamapdetail = new DataMappingDetail(); // Do the mapping translation; returns original value if no translation found $translation = $datamapdetail->translateCode($datamaprule->id, $translation, 'IN'); // Need to check if the translated value exists and return display value if ($datamaprule->isLoaded() && !is_null($datamaprule->data_mapping_id)) { $mapvalue = new DataMapping(); $mapvalue->load($datamaprule->data_mapping_id); $display_value = $mapvalue->getValue($translation); } if ($display_value === FALSE) { $display_value = 'Missing Translation'; $this->missing_translation = true; } } } elseif ($datamap->isLoaded()) { if ($child_node->childNodes && !empty($child_node->firstChild->nodeType) && $child_node->firstChild->nodeType != 3) { $translation = serialize('<' . XML_ROOT . '>' . $dom->saveXML($child_node) . '</' . XML_ROOT . '>'); } else { $translation = $this->translateCode($datamap, $node_value, $child_node->tagName); if (empty($translation) && !is_null($defdetail->default_value)) { $translation = $defdetail->default_value; } $display_value = $node_value; } } elseif ($child_node->childNodes) { if (empty($node_value)) { $node_value = 'No value'; } $display_value = 'not used'; } if (!is_null($datamap->internal_type) && !is_null($datamap->internal_attribute)) { if (!is_null($defdetail->data_mapping_rule_id)) { $attribute = $dom->createAttribute('data_mapping_rule_id'); $attribute->value = $defdetail->data_mapping_rule_id; $child_node->appendChild($attribute); } if (!is_null($datamapdetail->id)) { $attribute = $dom->createAttribute('id'); $attribute->value = $datamapdetail->id; $child_node->appendChild($attribute); } $attribute = $dom->createAttribute('external_code'); $attribute->value = str_replace('&', '&', $external_code); $child_node->appendChild($attribute); $attribute = $dom->createAttribute('internal_code'); $attribute->value = str_replace('&', '&', $translation); $child_node->appendChild($attribute); $attribute = $dom->createAttribute('display_value'); $attribute->value = str_replace('&', '&', $display_value); $child_node->appendChild($attribute); $attribute = $dom->createAttribute('internal_type'); $attribute->value = $datamap->internal_type; $child_node->appendChild($attribute); $attribute = $dom->createAttribute('internal_attribute'); $attribute->value = $datamap->internal_attribute; $child_node->appendChild($attribute); } if ($child_node->childNodes && $child_node->firstChild->nodeType != 3) { $this->processNode($child_node, $defdetail->{$defdetail->idField}, $dom); } } }