示例#1
0
 public static function generateFDML($finalArr, $legendArr, $valuesMapArr, $userDataArr, $art1, $art2)
 {
     //pole pro uložení vazby mezi jednotlivymi field
     $art1_NameIdMap = array();
     $xml = simplexml_load_string('<FDML xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://keg.vse.cz/ns/fdml0_2 http://sewebar.vse.cz/schemas/FDML0_2.xsd" xmlns="http://keg.vse.cz/ns/fdml0_2"></FDML>');
     //vygenerujeme hlavicku
     $header = $xml->addChild('Header');
     $header->addChild('Timestamp', date('c'));
     //TODO doplnit jmeno uzivatele atp.
     /**informace o prvnim ze zdroju**************************************************************/
     $dictionary1 = $xml->addChild('Dictionary');
     //TODO $dictionary1->addAttribute('numberOfFields');
     $dictionary1->addAttribute('sourceFormat', 'PMML');
     $dictionary1->addAttribute('sourceDictType', 'DataDictionary');
     $dictionary1->addAttribute('id', 'a');
     //vypsani identifikatoru
     if ($art1['taskId']) {
         //jde o generovani na zaklade ulohy
         $identifierId = $dictionary1->addChild('Identifier');
         $identifierId->addAttribute('taskId', $art1['taskId']);
         $dictionary1->addAttribute('sourceName', $art1['title']);
     } elseif ($art1['id']) {
         //jde o generovani na zaklade clanku
         $identifierId = $dictionary1->addChild('Identifier');
         $identifierId->addAttribute('articleId', $art1['id']);
         $dictionary1->addAttribute('sourceName', $art1['title']);
     }
     /**informace o druhem ze zdroju**************************************************************/
     if ((string) $art2["sourceType"] == "BKEF") {
         //TODO doplnit pro BKEF
         $dictionary2 = $xml->addChild('Dictionary');
         $dictionary2->addAttribute('sourceFormat', "BKEF");
         $dictionary2->addAttribute('sourceName', $art2['title']);
         $dictionary2->addAttribute('sourceDictType', 'Range');
         $dictionary2->addAttribute('id', 'b');
         $identifier2Id = $dictionary2->addChild('Identifier');
         $identifier2Id->addAttribute('articleId', $art2['id']);
     } else {
         $dictionary2 = $xml->addChild('Dictionary');
         $dictionary2->addAttribute('sourceFormat', "PMML");
         $dictionary2->addAttribute('sourceName', $art2['title']);
         $dictionary2->addAttribute('sourceDictType', 'DataDictionary');
         $dictionary2->addAttribute('id', 'b');
         $identifier2Id = $dictionary2->addChild('Identifier');
         $identifier2Id->addAttribute('articleId', $art2['id']);
     }
     //TODO - KONTROLA, jestli to takhle muze fungovat!
     /********************************************************************************************/
     $dictionaryMapping = $xml->addChild('DictionaryMapping');
     /********************************************************************************************/
     //pomocna pole pro info o tom, ktere klice uz byly vytvoreny
     $writtenFieldsA = array();
     $writtenFieldsB = array();
     $writtenValues = array();
     if (count($finalArr) > 0) {
         foreach ($finalArr as $key => $arr) {
             if (@$arr["name"] == "") {
                 continue;
             }
             $fieldMapping = $dictionaryMapping->addChild("FieldMapping");
             //projdeme finalArr a přesypeme výsledky do FML
             $key1name = $legendArr[$key];
             $key2 = $arr['name'];
             $key2name = $legendArr[$key2];
             $key2nameArr = split("###", $key2name, 2);
             //overime, jestli uz byl dany klic uveden v daném dictionary (aby bylo na co odkazovat)
             if (!in_array($key, $writtenFieldsA)) {
                 XmlConnectorFDML::addPMMLField($dictionary1, $key, $key1name);
                 $writtenFieldsA[] = $key;
             }
             if (!in_array($key2name, $writtenFieldsB)) {
                 if (count($key2nameArr) > 1) {
                     XmlConnectorFDML::addBKEFField($dictionary2, $key2, $key2nameArr[0], $key2nameArr[1]);
                 } else {
                     XmlConnectorFDML::addPMMLField($dictionary2, $key2, $key2name);
                 }
                 $writtenFieldsB[] = $key2;
             }
             //
             $appliesTo = $fieldMapping->addChild('AppliesTo');
             $fieldRef1 = $appliesTo->addChild('FieldRef');
             $fieldRef1->addAttribute('dictID', 'a');
             $fieldRef1->addAttribute('id', $key);
             //TODO naplneni atributu
             $fieldRef2 = $appliesTo->addChild('FieldRef');
             $fieldRef2->addAttribute('dictID', 'b');
             $fieldRef2->addAttribute('id', $key2);
             /*vyplnime mapping info*/
             $mappingInfo = $fieldMapping->addChild('MappingInfo');
             //typ mapovani
             if (isset($userDataArr[$key])) {
                 $matchingType = "user";
             } else {
                 $matchingType = "autosuggestion";
             }
             $mappingInfo->addChild('Type', $matchingType);
             //hodnoty autosuggestion
             $autosuggestion = $mappingInfo->addChild("Autosuggestion");
             $autosuggestion->addChild("Names", @$arr["match"]["ratioArr"]["names"]);
             $autosuggestion->addChild("Values", @$arr["match"]["ratioArr"]["values"]);
             $autosuggestion->addChild("Experience", @$arr["match"]["ratioArr"]["expirience"]);
             /*--vyplnime mapping info*/
             /*mapovani hodnot*/
             if (isset($arr['mappedValues']) || isset($arr['autoMappedValues'])) {
                 // mapujeme výčet hodnot - připravíme si klíč, do kterého budeme tato mapování ukládat
                 $valueMappings = $fieldMapping->addChild("ValueMappings");
                 //uživatelsky namapované hodnoty
                 if (count(@$arr["mappedValues"]) > 0) {
                     foreach ($arr["mappedValues"] as $valueA => $valuesArr) {
                         if (count($valuesArr) > 0) {
                             foreach ($valuesArr as $valueB) {
                                 $valueMapping = $valueMappings->addChild("ValueMapping");
                                 $valueMapping->addAttribute('type', 'user');
                                 $field1 = $valueMapping->addChild("Field");
                                 $field1->addAttribute('id', $key);
                                 $field1->addAttribute('dictID', 'a');
                                 $catRef1 = $field1->addChild('CatRef', $valuesMapArr[$valueA]);
                                 $catRef1->addAttribute('id', 'v' . $key . '_' . $valueA);
                                 $field2 = $valueMapping->addChild("Field");
                                 $field2->addAttribute('id', $key2);
                                 $field2->addAttribute('dictID', 'b');
                                 $catRef2 = $field2->addChild('CatRef', $valuesMapArr[$valueB]);
                                 $catRef2->addAttribute('id', 'v' . $key2 . '_' . $valueB);
                             }
                         }
                     }
                 }
                 //automaticky namapované hodnoty
                 if (count(@$arr["autoMappedValues"]) > 0) {
                     foreach ($arr["autoMappedValues"] as $valueA => $valuesArr) {
                         if (count($valuesArr) > 0) {
                             foreach ($valuesArr as $valueB) {
                                 $valueMapping = $valueMappings->addChild("ValueMapping");
                                 $valueMapping->addAttribute('type', 'autosuggestion');
                                 $field1 = $valueMapping->addChild("Field");
                                 $field1->addAttribute('id', $key);
                                 $field1->addAttribute('dictID', 'a');
                                 $catRef1 = $field1->addChild('CatRef', $valuesMapArr[$valueA]);
                                 $catRef1->addAttribute('id', 'v' . $key . '_' . $valueA);
                                 $field2 = $valueMapping->addChild("Field");
                                 $field2->addAttribute('id', $key2);
                                 $field2->addAttribute('dictID', 'b');
                                 $catRef2 = $field2->addChild('CatRef', $valuesMapArr[$valueB]);
                                 $catRef2->addAttribute('id', 'v' . $key2 . '_' . $valueB);
                                 //pokud odkazujeme na referenci, ktera jeste nebyla vytvorena, tak ji doplnime...
                                 if (!in_array($valueA, $writtenValues)) {
                                     XmlConnectorFDML::addValueToDictionary($dictionary1, $key, $valueA, $valuesMapArr[$valueA]);
                                     $writtenValues[] = $valueA;
                                 }
                                 if (!in_array($valueB, $writtenValues)) {
                                     XmlConnectorFDML::addValueToDictionary($dictionary2, $key2, $valueB, $valuesMapArr[$valueB]);
                                     $writtenValues[] = $valueB;
                                 }
                             }
                         }
                     }
                 }
             }
             /*--mapovani hodnot*/
         }
     }
     /********************************************************************************************/
     //TODO tady byla ukoncovaci zavorka
     /////////////////////////////////-----------------------------------------------/////////////////////////////
     return $xml->asXML();
 }
示例#2
0
 public static function generateFML($finalArr, $legendArr, $valuesMapArr, $userDataArr, $art1, $art2)
 {
     require_once JPATH_COMPONENT . DS . 'library' . DS . 'XmlConnectorFDML.php';
     return XmlConnectorFDML::generateFDML($finalArr, $legendArr, $valuesMapArr, $userDataArr, $art1, $art2);
 }