コード例 #1
0
ファイル: EdiInterface.php プロジェクト: uzerpllp/uzerp
 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('&', '&#38;', $external_code);
             $child_node->appendChild($attribute);
             $attribute = $dom->createAttribute('internal_code');
             $attribute->value = str_replace('&', '&#38;', $translation);
             $child_node->appendChild($attribute);
             $attribute = $dom->createAttribute('display_value');
             $attribute->value = str_replace('&', '&#38;', $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);
         }
     }
 }
コード例 #2
0
 public function _new()
 {
     $datamapdetail = $this->_uses[$this->modeltype];
     if ($datamapdetail->isLoaded()) {
         $this->_data['data_mapping_rule_id'] = $datamapdetail->data_mapping_rule_id;
         $this->_data['parent_id'] = $datamapdetail->parent_id;
         $datamappingrule = $datamapdetail->data_map_rule;
     } elseif (isset($this->_data['data_mapping_rule_id'])) {
         $datamappingrule = new DataMappingRule();
         $datamappingrule->load($this->_data['data_mapping_rule_id']);
     }
     if (!$this->CheckParams('data_mapping_rule_id')) {
         sendBack();
     }
     parent::_new();
     $cc = new ConstraintChain();
     $datamap = $datamappingrule->data_map;
     $options = array();
     if (!empty($this->_data['parent_id'])) {
         // get the parent mapping detail
         $parent_detail = new DataMappingDetail();
         $parent_detail->load($this->_data['parent_id']);
         // get the parent mapping
         $parent_mapping = $parent_detail->data_map_rule->data_map;
         $parent_id = $parent_detail->internal_code;
         // Rules need simplifying and/or explaining
         // perhaps move these to the DataMapping model
         $x = $datamap->getModel();
         $hasmany = $x->getHasMany();
         if (isset($hasmany[$datamap->internal_attribute])) {
             $x->load($parent_detail->internal_code);
             foreach ($x->{$datamap->internal_attribute} as $detail) {
                 $options[$detail->{$detail->idField}] = $detail->{$detail->getIdentifier()};
             }
         } elseif ($parent_mapping->isHasOne()) {
             $hasone = $parent_mapping->getHasOne();
             $x = new $hasone['model']();
             $hasmany = $x->getHasMany();
             if (isset($hasmany[$datamap->internal_attribute])) {
                 $x->load($parent_detail->internal_code);
                 foreach ($x->{$datamap->internal_attribute} as $detail) {
                     $options[$detail->{$detail->idField}] = $detail->{$detail->getIdentifier()};
                 }
             }
         } else {
             $belongsto = $x->belongsTo;
             foreach ($belongsto as $parent) {
                 if ($parent['model'] == $parent_mapping->internal_type) {
                     $cc->add(new Constraint($parent['field'], '=', $parent_id));
                     break;
                 }
             }
         }
         // If no constraints found from fk definitions and the parent class is the
         // same as the child class, then the parent is the child i.e. data specific
         // to the parent
         if (empty($cc->constraints) && $parent_mapping->internal_type == get_class($x)) {
             $cc->add(new Constraint($x->idField, '=', $parent_id));
         }
     }
     //		elseif (!is_null($datamappingrule->parent_id)) {
     // Get the list of parent options
     // from the parent mapping details via the parent mapping rule
     $parentmappingrule = new datamappingrule();
     $parentmappingrule->load($datamappingrule->parent_id);
     $parent_options = array();
     foreach ($parentmappingrule->data_translations as $parent_detail) {
         $parent_options[$parent_detail->id] = $parent_detail->displayValue();
     }
     $this->view->set('parent_options', $parent_options);
     $this->view->set('parent_label', $datamappingrule->parent);
     //		}
     if (is_null($datamap->internal_type)) {
         $errors[] = 'No Internal Type defined for Data Mapping ' . $datamappingrule->name;
     } else {
         if (empty($options)) {
             $options = $datamap->getDataOptions($datamap->getModel(), $cc);
         }
         $this->view->set('data_mapping_rule_id', $this->_data['data_mapping_rule_id']);
         if (!$datamap->isLoaded()) {
             $errors[] = 'Invalid Data Type';
         } else {
             if (!is_null($datamap->internal_type)) {
                 $model = $datamap->getModel();
                 if (!$model) {
                     $errors[] = 'Data Mapping for Internal Data Type is invalid';
                 } else {
                     $this->view->set('model', $model);
                     $this->view->set('internal_codes', $options);
                     $this->view->set('internal_name', $datamappingrule->name);
                 }
             }
         }
     }
     $datatranslations = new DataMappingDetailCollection(new DataMappingDetail());
     $sh = $this->setSearchHandler($datatranslations);
     $sh->addConstraint(new Constraint('data_mapping_rule_id', '=', $this->_data['data_mapping_rule_id']));
     if (isset($this->_data['parent_id'])) {
         $sh->addConstraint(new Constraint('parent_id', '=', $this->_data['parent_id']));
     }
     parent::index($datatranslations, $sh);
     $this->view->set('clickaction', 'view');
 }