fix subtest depth

This commit is contained in:
mikael-zakaria 2025-02-02 23:05:59 +08:00
parent a3a6a2b80c
commit d1f37ae6dc

View File

@ -87,7 +87,8 @@ left join cmod.dbo.CM_TM_TESTS ct on ct.HISCODE=m.HISCODE and ct.REQID=cq.REQID
left join cmod.dbo.CM_DICT_TUBES tub on tub.TUBEID=m.TUBEID
where r.ACCESSNUMBER='$accessnumber' ORDER BY t.TESTORDER";
$query = $db->query($sql);
$test_results = $query->getResultArray();
$test_results = $query->getResultArray();
$d0=-1; $d1=-1; $d2=-1; $d3=-1;
foreach ($test_results as $result) {
$refftestid = trim($result['REFFTESTID']);
$testorder = $result['TESTORDER'];
@ -126,21 +127,22 @@ where r.ACCESSNUMBER='$accessnumber' ORDER BY t.TESTORDER";
"test_unit"=> "$testunit",
"test_reff" => "$testreff",
"test_summary"=> "$testsum",
//"subtest_results" => [],
];
//"debug" => "d0=$d0 d1=$d1 d2=$d2",
];
if ( $depth == 0 || $depth == '' ) { // depth 0
if(isset($d0)) { $d0++; } else { $d0 = 0; }
$d1=0;
$d0++;
$d1=-1;
$json['test_results'][] = $data;
} else if ($depth == 1) { // depth 1
if(isset($d1)) { $d1++; }
$d2=0;
$d1++;
$d2=-1;
$json['test_results'][$d0]['subtest_results'][] = $data;
} else if ($depth == 2) { // depth 2
if(isset($d2)) { $d2++; }
$d3=0;
} else if ($depth == 2) { // depth 2
$d2++;
$d3=-1;
$json['test_results'][$d0]['subtest_results'][$d1]['subtest_results'][] = $data;
}
}
return $json;
}