function exportTestCaseDataToXML($tcase_id, $tcversion_id, $tproject_id = null, $bNoXMLHeader = false, $optExport = array())
 {
     static $reqMgr;
     static $keywordMgr;
     static $cfieldMgr;
     if (is_null($reqMgr)) {
         $reqMgr = new requirement_mgr($this->db);
         $keywordMgr = new tlKeyword();
         $cfieldMgr = new cfield_mgr($this->db);
     }
     // Useful when you need to get info but do not have tcase id
     $tcase_id = intval((int) $tcase_id);
     $tcversion_id = intval((int) $tcversion_id);
     if ($tcase_id <= 0 && $tcversion_id > 0) {
         $info = $this->tree_manager->get_node_hierarchy_info($tcversion_id);
         $tcase_id = $info['parent_id'];
     }
     $tc_data = $this->get_by_id($tcase_id, $tcversion_id);
     $testCaseVersionID = $tc_data[0]['id'];
     if (!$tproject_id) {
         $tproject_id = $this->getTestProjectFromTestCase($tcase_id);
     }
     if (isset($optExport['CFIELDS']) && $optExport['CFIELDS']) {
         $cfMap = $this->get_linked_cfields_at_design($tcase_id, $testCaseVersionID, null, null, $tproject_id);
         // ||yyy||-> tags,  {{xxx}} -> attribute
         // tags and attributes receive different treatment on exportDataToXML()
         //
         // each UPPER CASE word in this map KEY, MUST HAVE AN OCCURENCE on $elemTpl
         // value is a key inside $tc_data[0]
         //
         if (!is_null($cfMap) && count($cfMap) > 0) {
             // $cfRootElem = "<custom_fields>{{XMLCODE}}</custom_fields>";
             // $cfElemTemplate = "\t" . "<custom_field>\n" .
             //                   "\t<name><![CDATA[||NAME||]]></name>\n" .
             //                   "\t<value><![CDATA[||VALUE||]]></value>\n</custom_field>\n";
             // $cfDecode = array ("||NAME||" => "name","||VALUE||" => "value");
             // $tc_data[0]['xmlcustomfields'] = $cfieldMgr->exportDataToXML($cfMap,$cfRootElem,$cfElemTemplate,$cfDecode,true);
             $tc_data[0]['xmlcustomfields'] = $cfieldMgr->exportValueAsXML($cfMap);
         }
     }
     if (isset($optExport['KEYWORDS']) && $optExport['KEYWORDS']) {
         $keywords = $this->getKeywords($tcase_id);
         if (!is_null($keywords)) {
             $xmlKW = "<keywords>" . $keywordMgr->toXMLString($keywords, true) . "</keywords>";
             $tc_data[0]['xmlkeywords'] = $xmlKW;
         }
     }
     if (isset($optExport['REQS']) && $optExport['REQS']) {
         $requirements = $reqMgr->get_all_for_tcase($tcase_id);
         if (!is_null($requirements) && count($requirements) > 0) {
             $reqRootElem = "\t<requirements>\n{{XMLCODE}}\t</requirements>\n";
             $reqElemTemplate = "\t\t<requirement>\n" . "\t\t\t<req_spec_title><![CDATA[||REQ_SPEC_TITLE||]]></req_spec_title>\n" . "\t\t\t<doc_id><![CDATA[||REQ_DOC_ID||]]></doc_id>\n" . "\t\t\t<title><![CDATA[||REQ_TITLE||]]></title>\n" . "\t\t</requirement>\n";
             $reqDecode = array("||REQ_SPEC_TITLE||" => "req_spec_title", "||REQ_DOC_ID||" => "req_doc_id", "||REQ_TITLE||" => "title");
             $tc_data[0]['xmlrequirements'] = exportDataToXML($requirements, $reqRootElem, $reqElemTemplate, $reqDecode, true);
         }
     }
     // ------------------------------------------------------------------------------------
     $stepRootElem = "<steps>{{XMLCODE}}</steps>";
     $stepTemplate = "\n" . '<step>' . "\n" . "\t<step_number><![CDATA[||STEP_NUMBER||]]></step_number>\n" . "\t<actions><![CDATA[||ACTIONS||]]></actions>\n" . "\t<expectedresults><![CDATA[||EXPECTEDRESULTS||]]></expectedresults>\n" . "\t<execution_type><![CDATA[||EXECUTIONTYPE||]]></execution_type>\n" . "</step>\n";
     $stepInfo = array("||STEP_NUMBER||" => "step_number", "||ACTIONS||" => "actions", "||EXPECTEDRESULTS||" => "expected_results", "||EXECUTIONTYPE||" => "execution_type");
     $stepSet = $tc_data[0]['steps'];
     $xmlsteps = exportDataToXML($stepSet, $stepRootElem, $stepTemplate, $stepInfo, true);
     $tc_data[0]['xmlsteps'] = $xmlsteps;
     // ------------------------------------------------------------------------------------
     $rootElem = "{{XMLCODE}}";
     if (isset($optExport['ROOTELEM'])) {
         $rootElem = $optExport['ROOTELEM'];
     }
     $elemTpl = "\n" . '<testcase internalid="{{TESTCASE_ID}}" name="{{NAME}}">' . "\n" . "\t<node_order><![CDATA[||NODE_ORDER||]]></node_order>\n";
     if (!isset($optExport['EXTERNALID']) || $optExport['EXTERNALID']) {
         $elemTpl .= "\t<externalid><![CDATA[||EXTERNALID||]]></externalid>\n";
     }
     $elemTpl .= "\t<version><![CDATA[||VERSION||]]></version>\n" . "\t<summary><![CDATA[||SUMMARY||]]></summary>\n" . "\t<preconditions><![CDATA[||PRECONDITIONS||]]></preconditions>\n" . "\t<execution_type><![CDATA[||EXECUTIONTYPE||]]></execution_type>\n" . "\t<importance><![CDATA[||IMPORTANCE||]]></importance>\n" . "\t<estimated_exec_duration>||ESTIMATED_EXEC_DURATION||</estimated_exec_duration>\n" . "\t<status>||STATUS||</status>\n" . "||STEPS||\n" . "||KEYWORDS||||CUSTOMFIELDS||||REQUIREMENTS||</testcase>\n";
     // ||yyy||-> tags,  {{xxx}} -> attribute
     // tags and attributes receive different treatment on exportDataToXML()
     //
     // each UPPER CASE word in this map KEY, MUST HAVE AN OCCURENCE on $elemTpl
     // value is a key inside $tc_data[0]
     //
     $info = array("{{TESTCASE_ID}}" => "testcase_id", "{{NAME}}" => "name", "||NODE_ORDER||" => "node_order", "||EXTERNALID||" => "tc_external_id", "||VERSION||" => "version", "||SUMMARY||" => "summary", "||PRECONDITIONS||" => "preconditions", "||EXECUTIONTYPE||" => "execution_type", "||IMPORTANCE||" => "importance", "||ESTIMATED_EXEC_DURATION||" => "estimated_exec_duration", "||STATUS||" => "status", "||STEPS||" => "xmlsteps", "||KEYWORDS||" => "xmlkeywords", "||CUSTOMFIELDS||" => "xmlcustomfields", "||REQUIREMENTS||" => "xmlrequirements");
     $xmlTC = exportDataToXML($tc_data, $rootElem, $elemTpl, $info, $bNoXMLHeader);
     return $xmlTC;
 }
 function exportTestSuiteDataToXML($container_id, $tproject_id, $optExport = array())
 {
     static $keywordMgr;
     if (is_null($keywordMgr)) {
         $keywordMgr = new tlKeyword();
     }
     // echo __FUNCTION__ . '<br>';
     $xmlTC = null;
     $doRecursion = isset($optExport['RECURSIVE']) ? $optExport['RECURSIVE'] : 0;
     if ($doRecursion) {
         $cfXML = null;
         $kwXML = null;
         $tsuiteData = $this->get_by_id($container_id);
         if (@$optExport['KEYWORDS']) {
             $kwMap = $this->getKeywords($container_id);
             if ($kwMap) {
                 $kwXML = "<keywords>" . $keywordMgr->toXMLString($kwMap, true) . "</keywords>";
             }
         }
         if ($optExport['CFIELDS']) {
             // 20090106 - franciscom - custom fields
             $cfMap = $this->get_linked_cfields_at_design($container_id, null, null, $tproject_id);
             if (!is_null($cfMap) && count($cfMap) > 0) {
                 $cfRootElem = "<custom_fields>{{XMLCODE}}</custom_fields>";
                 $cfElemTemplate = "\t" . '<custom_field><name><![CDATA[' . "\n||NAME||\n]]>" . "</name>" . '<value><![CDATA[' . "\n||VALUE||\n]]>" . '</value></custom_field>' . "\n";
                 $cfDecode = array("||NAME||" => "name", "||VALUE||" => "value");
                 $cfXML = exportDataToXML($cfMap, $cfRootElem, $cfElemTemplate, $cfDecode, true);
             }
         }
         $xmlTC = "<testsuite name=\"" . htmlspecialchars($tsuiteData['name']) . '" >' . "\n<node_order><![CDATA[{$tsuiteData['node_order']}]]></node_order>\n" . "<details><![CDATA[{$tsuiteData['details']}]]> \n{$kwXML}{$cfXML}</details>";
     } else {
         $xmlTC = "<testcases>";
     }
     $test_spec = $this->get_subtree($container_id, self::USE_RECURSIVE_MODE);
     $childNodes = isset($test_spec['childNodes']) ? $test_spec['childNodes'] : null;
     $tcase_mgr = null;
     if (!is_null($childNodes)) {
         $loop_qty = sizeof($childNodes);
         for ($idx = 0; $idx < $loop_qty; $idx++) {
             $cNode = $childNodes[$idx];
             $nTable = $cNode['node_table'];
             if ($doRecursion && $nTable == 'testsuites') {
                 $xmlTC .= $this->exportTestSuiteDataToXML($cNode['id'], $tproject_id, $optExport);
             } else {
                 if ($nTable == 'testcases') {
                     if (is_null($tcase_mgr)) {
                         $tcase_mgr = new testcase($this->db);
                     }
                     $xmlTC .= $tcase_mgr->exportTestCaseDataToXML($cNode['id'], testcase::LATEST_VERSION, $tproject_id, true, $optExport);
                 }
             }
         }
     }
     $xmlTC .= $doRecursion ? "</testsuite>" : "</testcases>";
     return $xmlTC;
 }
 function exportTestSuiteDataToXML($container_id, $tproject_id, $optExport = array())
 {
     static $keywordMgr;
     static $getLastVersionOpt = array('output' => 'minimun');
     static $tcase_mgr;
     if (is_null($keywordMgr)) {
         $keywordMgr = new tlKeyword();
     }
     $xmlTC = null;
     $doRecursion = isset($optExport['RECURSIVE']) ? $optExport['RECURSIVE'] : 0;
     if ($doRecursion) {
         $cfXML = null;
         $kwXML = null;
         $tsuiteData = $this->get_by_id($container_id);
         if (isset($optExport['KEYWORDS']) && $optExport['KEYWORDS']) {
             $kwMap = $this->getKeywords($container_id);
             if ($kwMap) {
                 $kwXML = "<keywords>" . $keywordMgr->toXMLString($kwMap, true) . "</keywords>";
             }
         }
         if (isset($optExport['CFIELDS']) && $optExport['CFIELDS']) {
             $cfMap = (array) $this->get_linked_cfields_at_design($container_id, null, null, $tproject_id);
             if (count($cfMap) > 0) {
                 $cfXML = $this->cfield_mgr->exportValueAsXML($cfMap);
             }
         }
         $xmlTC = "<testsuite name=\"" . htmlspecialchars($tsuiteData['name']) . '" >' . "\n<node_order><![CDATA[{$tsuiteData['node_order']}]]></node_order>\n" . "<details><![CDATA[{$tsuiteData['details']}]]> \n{$kwXML}{$cfXML}</details>";
     } else {
         $xmlTC = "<testcases>";
     }
     $test_spec = $this->get_subtree($container_id, self::USE_RECURSIVE_MODE);
     $childNodes = isset($test_spec['childNodes']) ? $test_spec['childNodes'] : null;
     $tcase_mgr = null;
     if (!is_null($childNodes)) {
         $loop_qty = sizeof($childNodes);
         for ($idx = 0; $idx < $loop_qty; $idx++) {
             $cNode = $childNodes[$idx];
             $nTable = $cNode['node_table'];
             if ($doRecursion && $nTable == 'testsuites') {
                 $xmlTC .= $this->exportTestSuiteDataToXML($cNode['id'], $tproject_id, $optExport);
             } else {
                 if ($nTable == 'testcases') {
                     if (is_null($tcase_mgr)) {
                         $tcase_mgr = new testcase($this->db);
                     }
                     $xmlTC .= $tcase_mgr->exportTestCaseDataToXML($cNode['id'], testcase::LATEST_VERSION, $tproject_id, true, $optExport);
                 }
             }
         }
     }
     $xmlTC .= $doRecursion ? "</testsuite>" : "</testcases>";
     return $xmlTC;
 }
 /**
  * 
  *
  */
 private function exportTestSuiteDataToXML($container, $tproject_id, $tplan_id, $platform_id)
 {
     static $keywordMgr;
     static $getLastVersionOpt = array('output' => 'minimun');
     static $tcaseMgr;
     static $tsuiteMgr;
     static $tcaseExportOptions;
     static $linkedItems;
     if (is_null($keywordMgr)) {
         $tcaseExportOptions = array('CFIELDS' => true, 'KEYWORDS' => true, 'EXEC_ORDER' => 0);
         $keywordMgr = new tlKeyword();
         $tsuiteMgr = new testsuite($this->db);
         $linkedItems = $this->getLinkedItems($tplan_id);
     }
     $xmlTC = null;
     $cfXML = null;
     $kwXML = null;
     if (isset($container['id'])) {
         $kwMap = $tsuiteMgr->getKeywords($container['id']);
         if ($kwMap) {
             $kwXML = "<keywords>" . $keywordMgr->toXMLString($kwMap, true) . "</keywords>";
         }
         $cfMap = (array) $tsuiteMgr->get_linked_cfields_at_design($container['id'], null, null, $tproject_id);
         if (count($cfMap) > 0) {
             $cfXML = $this->cfield_mgr->exportValueAsXML($cfMap);
         }
         $tsuiteData = $tsuiteMgr->get_by_id($container['id']);
         $xmlTC = "\n\t<testsuite name=\"" . htmlspecialchars($tsuiteData['name']) . '" >' . "\n\t\t<node_order><![CDATA[{$tsuiteData['node_order']}]]></node_order>" . "\n\t\t<details><![CDATA[{$tsuiteData['details']}]]>" . "\n\t\t{$kwXML}{$cfXML}</details>";
     }
     $childNodes = isset($container['childNodes']) ? $container['childNodes'] : null;
     if (!is_null($childNodes)) {
         $loop_qty = sizeof($childNodes);
         for ($idx = 0; $idx < $loop_qty; $idx++) {
             $cNode = $childNodes[$idx];
             switch ($cNode['node_table']) {
                 case 'testsuites':
                     $xmlTC .= $this->exportTestSuiteDataToXML($cNode, $tproject_id, $tplan_id, $platform_id);
                     break;
                 case 'testcases':
                     if (is_null($tcaseMgr)) {
                         $tcaseMgr = new testcase($this->db);
                     }
                     // testcase::LATEST_VERSION,
                     $tcaseExportOptions['EXEC_ORDER'] = $linkedItems[$cNode['id']][$platform_id]['node_order'];
                     $xmlTC .= $tcaseMgr->exportTestCaseDataToXML($cNode['id'], $cNode['tcversion_id'], $tproject_id, testcase::NOXMLHEADER, $tcaseExportOptions);
                     break;
             }
         }
     }
     if (isset($container['id'])) {
         $xmlTC .= "</testsuite>";
     }
     return $xmlTC;
 }
 function exportTestSuiteDataToXML($container_id, $tproject_id, $optExport = array())
 {
     static $keywordMgr;
     static $getLastVersionOpt = array('output' => 'minimun');
     static $tcase_mgr;
     if (is_null($keywordMgr)) {
         $keywordMgr = new tlKeyword();
     }
     $xmlTC = null;
     $relCache = array();
     $doRecursion = isset($optExport['RECURSIVE']) ? $optExport['RECURSIVE'] : 0;
     if ($doRecursion) {
         $cfXML = null;
         $kwXML = null;
         $tsuiteData = $this->get_by_id($container_id);
         if (isset($optExport['KEYWORDS']) && $optExport['KEYWORDS']) {
             $kwMap = $this->getKeywords($container_id);
             if ($kwMap) {
                 $kwXML = "<keywords>" . $keywordMgr->toXMLString($kwMap, true) . "</keywords>";
             }
         }
         if (isset($optExport['CFIELDS']) && $optExport['CFIELDS']) {
             $cfMap = (array) $this->get_linked_cfields_at_design($container_id, null, null, $tproject_id);
             if (count($cfMap) > 0) {
                 $cfXML = $this->cfield_mgr->exportValueAsXML($cfMap);
             }
         }
         $xmlTC = '<testsuite id="' . $tsuiteData['id'] . '" ' . 'name="' . htmlspecialchars($tsuiteData['name']) . '" >' . "\n<node_order><![CDATA[{$tsuiteData['node_order']}]]></node_order>\n" . "<details><![CDATA[{$tsuiteData['details']}]]></details> \n{$kwXML}{$cfXML}";
     } else {
         $xmlTC = "<testcases>";
     }
     $test_spec = $this->get_subtree($container_id, self::USE_RECURSIVE_MODE);
     $childNodes = isset($test_spec['childNodes']) ? $test_spec['childNodes'] : null;
     $tcase_mgr = null;
     $relXmlData = '';
     if (!is_null($childNodes)) {
         $loop_qty = sizeof($childNodes);
         for ($idx = 0; $idx < $loop_qty; $idx++) {
             $cNode = $childNodes[$idx];
             $nTable = $cNode['node_table'];
             if ($doRecursion && $nTable == 'testsuites') {
                 $xmlTC .= $this->exportTestSuiteDataToXML($cNode['id'], $tproject_id, $optExport);
             } else {
                 if ($nTable == 'testcases') {
                     if (is_null($tcase_mgr)) {
                         $tcase_mgr = new testcase($this->db);
                     }
                     $xmlTC .= $tcase_mgr->exportTestCaseDataToXML($cNode['id'], testcase::LATEST_VERSION, $tproject_id, true, $optExport);
                     // 20140816
                     // Collect and do cache of all test case relations that exists inside this test suite.
                     $relSet = $tcase_mgr->getRelations($cNode['id']);
                     if ($relSet['num_relations'] > 0) {
                         foreach ($relSet['relations'] as $key => $rel) {
                             // If we have already found this relation, skip it.
                             if (!in_array($rel['id'], $relCache)) {
                                 $relXmlData .= $tcase_mgr->exportRelationToXML($rel, $relSet['item']);
                                 $relCache[] = $rel['id'];
                             }
                         }
                     }
                 }
             }
         }
     }
     // after we scanned all relations and exported all relations to xml, let's output it to the XML buffer
     $xmlTC .= $relXmlData;
     $xmlTC .= $doRecursion ? "</testsuite>" : "</testcases>";
     return $xmlTC;
 }