function doExport(&$dbHandler, $filename) { $tables = tlObjectWithDB::getDBTables(array('custom_fields', 'cfield_node_types')); $adodbXML = new ADODB_XML("1.0", "ISO-8859-1"); $sql = " SELECT name,label,type,possible_values,default_value,valid_regexp, " . " length_min,length_max,show_on_design,enable_on_design,show_on_execution," . " enable_on_execution,show_on_testplan_design,enable_on_testplan_design, " . " node_type_id,required " . " FROM {$tables['custom_fields']} CF,{$tables['cfield_node_types']} " . " WHERE CF.id=field_id "; $adodbXML->setRootTagName('custom_fields'); $adodbXML->setRowTagName('custom_field'); $content = $adodbXML->ConvertToXMLString($dbHandler->db, $sql); downloadContentsToFile($content, $filename); exit; }
function doExport(&$db, $filename, $testproject_id) { $debugMsg = 'Class:' . __CLASS__ . ' - Method: ' . __FUNCTION__; $tables = tlObjectWithDB::getDBTables(array('platforms')); $adodbXML = new ADODB_XML("1.0", "UTF-8"); $sql = "/* {$debugMsg} */ SELECT name,notes " . " FROM {$tables['platforms']} PLAT " . " WHERE PLAT.testproject_id=" . intval($testproject_id); $adodbXML->setRootTagName('platforms'); $adodbXML->setRowTagName('platform'); $content = $adodbXML->ConvertToXMLString($db->db, $sql); downloadContentsToFile($content, $filename); exit; }
function doExport(&$dbHandler, $filename) { $adodbXML = new ADODB_XML("1.0", "ISO-8859-1"); $adodbXML->setRootTagName('users'); $adodbXML->setRowTagName('user'); $tables = tlObjectWithDB::getDBTables(array('users')); $fieldSet = 'id,login,role_id,email,first,last,locale,default_testproject_id,active'; $sql = " SELECT {$fieldSet} FROM {$tables['users']} "; $content = $adodbXML->ConvertToXMLString($dbHandler->db, $sql); downloadContentsToFile($content, $filename); exit; }
function do_export(&$db, &$smarty, &$args) { $pfn = null; switch ($args->exportType) { case 'iSerializationToCSV': $pfn = "exportKeywordsToCSV"; break; case 'iSerializationToXML': $pfn = "exportKeywordsToXML"; break; } if ($pfn) { $tprojectMgr = new testproject($db); $content = $tprojectMgr->{$pfn}($args->tproject_id); downloadContentsToFile($content, $args->export_filename); exit; } }
case 'XML': $pfn = 'exportTestSuiteDataToXML'; if ($exporting_just_one_tc) { $pfn = 'exportTestCaseDataToXML'; } break; } if ($pfn) { if ($exporting_just_one_tc) { $optExport['ROOTELEM'] = "<testcases>{{XMLCODE}}</testcases>"; $content = $tcase_mgr->{$pfn}($args->tcase_id, $args->tcversion_id, $args->tproject_id, null, $optExport); } else { $content = TL_XMLEXPORT_HEADER; $content .= $tsuite_mgr->{$pfn}($args->container_id, $args->tproject_id, $optExport); } downloadContentsToFile($content, $gui->export_filename); exit; } } if ($args->useRecursion) { // we are working on a testsuite $obj_mgr = new testsuite($db); } else { $obj_mgr = new testcase($db); } $gui->object_name = $node['name']; $gui->exportTypes = $obj_mgr->get_export_file_types(); $gui->tproject_name = $args->tproject_name; $gui->tproject_id = $args->tproject_id; $gui->tcID = $args->tcase_id; $gui->useRecursion = $args->useRecursion ? 1 : 0;
/** * doExport * */ function doExport(&$argsObj, &$req_spec_mgr) { $pfn = null; switch ($argsObj->exportType) { case 'csv': $requirements_map = $req_spec_mgr->get_requirements($argsObj->req_spec_id); $pfn = "exportReqDataToCSV"; $fileName = 'reqs.csv'; $content = $pfn($requirements_map); break; case 'XML': $pfn = "exportReqSpecToXML"; $fileName = 'reqs.xml'; $content = TL_XMLEXPORT_HEADER; $optionsForExport['RECURSIVE'] = $argsObj->scope == 'items' ? false : true; $openTag = $argsObj->scope == 'items' ? "requirements>" : 'requirement-specification>'; switch ($argsObj->scope) { case 'tree': $reqSpecSet = $req_spec_mgr->getFirstLevelInTestProject($argsObj->tproject_id); $reqSpecSet = array_keys($reqSpecSet); break; case 'branch': case 'items': $reqSpecSet = array($argsObj->req_spec_id); break; } $content .= "<" . $openTag . "\n"; if (!is_null($reqSpecSet)) { foreach ($reqSpecSet as $reqSpecID) { $content .= $req_spec_mgr->{$pfn}($reqSpecID, $argsObj->tproject_id, $optionsForExport); } } $content .= "</" . $openTag . "\n"; break; } if ($pfn) { $fileName = is_null($argsObj->export_filename) ? $fileName : $argsObj->export_filename; downloadContentsToFile($content, $fileName); exit; } }
/** * * */ function createSpreadsheet($gui, $args) { $lbl = init_labels(array('title_test_suite_name' => null, 'platform' => null, 'priority' => null, 'build' => null, 'title_test_case_title' => null, 'test_exec_by' => null, 'notes' => null, 'date_time_run' => null, 'execution_duration' => null, 'testproject' => null, 'generated_by_TestLink_on' => null, 'testplan' => null, 'result_on_last_build' => null, 'last_execution' => null, 'assigned_to' => null, 'tcexec_result' => null, 'version' => null, 'execution_type' => null)); $buildIDSet = $args->builds->idSet; // contribution to have more than 26 columns $cellRange = range('A', 'Z'); $cellRangeLen = count($cellRange); for ($idx = 0; $idx < $cellRangeLen; $idx++) { for ($jdx = 0; $jdx < $cellRangeLen; $jdx++) { $cellRange[] = $cellRange[$idx] . $cellRange[$jdx]; } } $styleReportContext = array('font' => array('bold' => true)); $styleDataHeader = array('font' => array('bold' => true), 'borders' => array('outline' => array('style' => PHPExcel_Style_Border::BORDER_MEDIUM), 'vertical' => array('style' => PHPExcel_Style_Border::BORDER_THIN)), 'fill' => array('type' => PHPExcel_Style_Fill::FILL_SOLID, 'startcolor' => array('argb' => 'FF9999FF'))); $dummy = ''; $lines2write = array(array($lbl['testproject'], $gui->tproject_name), array($lbl['testplan'], $gui->tplan_name), array($lbl['generated_by_TestLink_on'], localize_dateOrTimeStamp(null, $dummy, 'timestamp_format', time()))); $objPHPExcel = new PHPExcel(); $cellArea = "A1:"; foreach ($lines2write as $zdx => $fields) { $cdx = $zdx + 1; $objPHPExcel->setActiveSheetIndex(0)->setCellValue("A{$cdx}", current($fields))->setCellValue("B{$cdx}", end($fields)); } $cellArea .= "A{$cdx}"; $objPHPExcel->getActiveSheet()->getStyle($cellArea)->applyFromArray($styleReportContext); // Step 2 // data is organized with following columns $dataHeader[] // Test suite // Test case // Test case version (for humans) // [Platform] => if any exists // // Priority ===> Just discovered that we have choosen to make this column // displayabled or not according test project configuration // IMHO has no sense work without priority // // Build // Assigned To // Exec result // Date // Tester // Notes // Duration // // ?? Exec result on ON LATEST CREATED Build // ?? Latest Execution result (Hmm need to explain better) // $dataHeader = array($lbl['title_test_suite_name'], $lbl['title_test_case_title'], $lbl['version']); if ($showPlatforms = !is_null($gui->platforms)) { $dataHeader[] = $lbl['platform']; } if ($gui->options->testPriorityEnabled) { $dataHeader[] = $lbl['priority']; } $gui->filterFeedback = null; $dataHeader[] = $lbl['build']; $dataHeader[] = $lbl['assigned_to']; $dataHeader[] = $lbl['tcexec_result']; $dataHeader[] = $lbl['date_time_run']; $dataHeader[] = $lbl['test_exec_by']; $dataHeader[] = $lbl['notes']; $dataHeader[] = $lbl['execution_duration']; $dataHeader[] = $lbl['execution_type']; $startingRow = count($lines2write) + 2; // MAGIC $cellArea = "A{$startingRow}:"; foreach ($dataHeader as $zdx => $field) { $cellID = $cellRange[$zdx] . $startingRow; $objPHPExcel->setActiveSheetIndex(0)->setCellValue($cellID, $field); $cellAreaEnd = $cellRange[$zdx]; } $cellArea .= "{$cellAreaEnd}{$startingRow}"; $objPHPExcel->getActiveSheet()->getStyle($cellArea)->applyFromArray($styleDataHeader); $startingRow++; $qta_loops = count($gui->matrix); for ($idx = 0; $idx < $qta_loops; $idx++) { foreach ($gui->matrix[$idx] as $ldx => $field) { $cellID = $cellRange[$ldx] . $startingRow; $objPHPExcel->setActiveSheetIndex(0)->setCellValue($cellID, $field); } $startingRow++; } // Final step $objPHPExcel->setActiveSheetIndex(0); $settings = array(); $settings['Excel2007'] = array('ext' => '.xlsx', 'Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); $settings['Excel5'] = array('ext' => '.xls', 'Content-Type' => 'application/vnd.ms-excel'); $xlsType = 'Excel5'; $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, $xlsType); $tmpfname = tempnam(config_get('temp_dir'), "resultsTCFlat.tmp"); $objWriter->save($tmpfname); $content = file_get_contents($tmpfname); unlink($tmpfname); $f2d = 'resultsTCFlat_' . $gui->tproject_name . '_' . $gui->tplan_name . $settings[$xlsType]['ext']; downloadContentsToFile($content, $f2d, array('Content-Type' => $settings[$xlsType]['Content-Type'])); exit; }
/** * */ function createSpreadsheet($gui, $args, $customFieldColumns = null) { $lbl = init_labels(array('title_test_suite_name' => null, 'platform' => null, 'build' => null, 'th_bugs_id_summary' => null, 'title_test_case_title' => null, 'version' => null, 'testproject' => null, 'generated_by_TestLink_on' => null, 'testplan' => null, 'title_execution_notes' => null, 'th_date' => null, 'th_run_by' => null, 'assigned_to' => null, 'summary' => null)); $cellRange = range('A', 'Z'); $styleReportContext = array('font' => array('bold' => true)); $styleDataHeader = array('font' => array('bold' => true), 'borders' => array('outline' => array('style' => PHPExcel_Style_Border::BORDER_MEDIUM), 'vertical' => array('style' => PHPExcel_Style_Border::BORDER_THIN)), 'fill' => array('type' => PHPExcel_Style_Fill::FILL_SOLID, 'startcolor' => array('argb' => 'FF9999FF'))); $dummy = ''; $lines2write = array(array($gui->title, ''), array($lbl['testproject'], $gui->tproject_name), array($lbl['testplan'], $gui->tplan_name), array($lbl['generated_by_TestLink_on'], localize_dateOrTimeStamp(null, $dummy, 'timestamp_format', time())), array($gui->report_context, '')); $objPHPExcel = new PHPExcel(); $cellArea = "A1:"; foreach ($lines2write as $zdx => $fields) { $cdx = $zdx + 1; $objPHPExcel->setActiveSheetIndex(0)->setCellValue("A{$cdx}", current($fields))->setCellValue("B{$cdx}", end($fields)); } $cellArea .= "A{$cdx}"; $objPHPExcel->getActiveSheet()->getStyle($cellArea)->applyFromArray($styleReportContext); // Step 2 // data is organized with following columns$dataHeader[] // Test suite // Test case // Version // [Platform] // Build // Tester // Date // Execution notes // [Custom Field ENABLED ON EXEC 1] // [Custom Field ENABLED ON EXEC 1] // [Custom Field ENABLED ON EXEC 1] // [bugString] only if bugtracking integration exists for this test project // This is HOW gui->dataSet is organized // THIS IS CRITIC ?? // // suiteName Issue Tracker Management // testTitle PTRJ-76:Create issue tracker - no conflict // testVersion 1 // [platformName] // buildName 1.0 // testerName admin // localizedTS 2013-03-28 20:15:06 // notes [empty string] // bugString [empty string] // $dataHeader = array($lbl['title_test_suite_name'], $lbl['title_test_case_title'], $lbl['version']); if ($showPlatforms = property_exists($gui, 'platformSet') && !is_null($gui->platformSet) && !isset($gui->platformSet[0])) { $dataHeader[] = $lbl['platform']; } $dataHeader[] = $lbl['build']; if ($gui->notRunReport) { $dataHeader[] = $lbl['assigned_to']; $dataHeader[] = $lbl['summary']; } else { $dataHeader[] = $lbl['th_run_by']; $dataHeader[] = $lbl['th_date']; $dataHeader[] = $lbl['title_execution_notes']; } if (!is_null($customFieldColumns)) { foreach ($customFieldColumns as $id => $def) { $dataHeader[] = $def['label']; } } // ATTENTION logic regarding NOT RUN IS MISSING // For not run this column and also columns regarding CF on exec are not displayed if ($gui->bugInterfaceOn && !$gui->notRunReport) { $dataHeader[] = $lbl['th_bugs_id_summary']; } $startingRow = count($lines2write) + 2; // MAGIC $cellArea = "A{$startingRow}:"; foreach ($dataHeader as $zdx => $field) { $cellID = $cellRange[$zdx] . $startingRow; $objPHPExcel->setActiveSheetIndex(0)->setCellValue($cellID, $field); $cellAreaEnd = $cellRange[$zdx]; } $cellArea .= "{$cellAreaEnd}{$startingRow}"; $objPHPExcel->getActiveSheet()->getStyle($cellArea)->applyFromArray($styleDataHeader); // new dBug($gui->dataSet); die(); // Now process data $startingRow++; $qta_loops = count($gui->dataSet); for ($idx = 0; $idx < $qta_loops; $idx++) { $line2write = $gui->dataSet[$idx]; $colCounter = 0; foreach ($gui->dataSet[$idx] as $ldx => $field) { if ($ldx != 'bugString' || $ldx == 'bugString' && $gui->bugInterfaceOn) { $cellID = $cellRange[$colCounter] . $startingRow; $objPHPExcel->setActiveSheetIndex(0)->setCellValue($cellID, html_entity_decode($field)); $colCounter++; } // May be same processing can be applied to execution otes if ($ldx == 'bugString' && $gui->bugInterfaceOn) { // To manage new line // http://stackoverflow.com/questions/5960242/how-to-make-new-lines-in-a-cell-using-phpexcel $objPHPExcel->setActiveSheetIndex(0)->getStyle($cellID)->getAlignment()->setWrapText(true); // $objPHPExcel->setActiveSheetIndex(0)->getRowDimension($startingRow)->setRowHeight(-1); // http://stackoverflow.com/questions/6054444/how-to-set-auto-height-in-phpexcel } } // $colQty = count($line2write); $cellEnd = $cellRange[$colCounter - 1] . $startingRow; $startingRow++; } // Final step $objPHPExcel->setActiveSheetIndex(0); $settings = array(); $settings['Excel2007'] = array('ext' => '.xlsx', 'Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); $settings['Excel5'] = array('ext' => '.xls', 'Content-Type' => 'application/vnd.ms-excel'); $xlsType = 'Excel5'; $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, $xlsType); $tmpfname = tempnam(config_get('temp_dir'), "resultsTC.tmp"); $objWriter->save($tmpfname); $content = file_get_contents($tmpfname); unlink($tmpfname); $f2d = 'resultsByStatus_' . $gui->tproject_name . '_' . $gui->tplan_name . $settings[$xlsType]['ext']; downloadContentsToFile($content, $f2d, array('Content-Type' => $settings[$xlsType]['Content-Type'])); exit; }
case 'CSV': fclose($fp); break; case 'XLSX': $styleData = array('borders' => array('outline' => array('style' => PHPExcel_Style_Border::BORDER_THIN), 'vertical' => array('style' => PHPExcel_Style_Border::BORDER_THIN))); $cellArea .= $cellEnd; $objPHPExcel->getActiveSheet()->getStyle($cellArea)->applyFromArray($styleData); $objPHPExcel->setActiveSheetIndex(0); $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); $objWriter->save($tmpfname); break; } $content = file_get_contents($tmpfname); unlink($tmpfname); $file2download .= '.' . strtolower($args->outputFormat); downloadContentsToFile($content, $file2download); exit; /** * * */ function init_args() { $iParams = array("format" => array(tlInputParameter::INT_N), "doReport" => array(tlInputParameter::INT_N), "build_id" => array(tlInputParameter::INT_N), "platform_id" => array(tlInputParameter::INT_N), "tproject_id" => array(tlInputParameter::INT_N), "tplan_id" => array(tlInputParameter::INT_N)); $args = new stdClass(); R_PARAMS($iParams, $args); $args->basehref = $_SESSION['basehref']; $args->userID = $_SESSION['userID']; $args->user = $_SESSION['currentUser']; $args->author = $args->user->firstName . ' ' . $args->user->lastName; $args->outputFormat = 'XLSX';