mirror of
https://git.meshkee.com/cssd/cssd-back.git
synced 2026-10-10 19:41:07 +03:30
ss
This commit is contained in:
@@ -46,6 +46,7 @@ class TestResultController extends Controller
|
||||
|
||||
public function store(StoreTestResultRequest $request)
|
||||
{
|
||||
|
||||
try {
|
||||
$return_value = \DB::transaction(function () use ($request) {
|
||||
|
||||
@@ -140,13 +141,13 @@ class TestResultController extends Controller
|
||||
$options[] = $input_option->option->title;
|
||||
$input_values[$input->name] = $options;
|
||||
}
|
||||
|
||||
// dd($input_values);
|
||||
$children[$input->parent->name] = $input_values;
|
||||
$TestResult['children'] = $children;
|
||||
}
|
||||
else {
|
||||
$input_values = [$input->name => $value->value];
|
||||
$children[$input->parent->name] = $input_values;
|
||||
|
||||
$children[$input->parent->name][$input->name] = $value->value;
|
||||
$TestResult['children'] = $children;
|
||||
}
|
||||
//-----------------------------------------------------------------------FormType
|
||||
@@ -174,6 +175,7 @@ class TestResultController extends Controller
|
||||
if (count($TestResult->TitleImage)) {
|
||||
$TestResult['imagePath'] = $TestResult->TitleImage[0]->path;
|
||||
}
|
||||
// dd($TestResult);
|
||||
return \MessageResponse::data($TestResult);
|
||||
}
|
||||
|
||||
@@ -183,16 +185,15 @@ class TestResultController extends Controller
|
||||
$input = $value->input;
|
||||
if ($input->type == 'Checkbox' || $input->type == 'Select') {
|
||||
$input_options = InputValue::where('test_result_id', $TestResult->id)->where('input_id', $input->id)->get()->pluck('option_id')->toArray();
|
||||
$TestResult[$input->name] = $input_options;
|
||||
$TestResult[$input->id] = $input_options;
|
||||
}
|
||||
else {
|
||||
$TestResult[$input->name] = $value->value;
|
||||
$TestResult[$input->id] = $value->value;
|
||||
}
|
||||
}
|
||||
if (count($TestResult->TitleImage)) {
|
||||
$TestResult['imagePath'] = $TestResult->TitleImage[0]->path;
|
||||
}
|
||||
|
||||
return \MessageResponse::data($TestResult);
|
||||
}
|
||||
|
||||
@@ -206,7 +207,7 @@ class TestResultController extends Controller
|
||||
|
||||
public function update(StoreTestResultRequest $request, TestResult $TestResult)
|
||||
{
|
||||
|
||||
// dd($request->all());
|
||||
$TestResultData = [
|
||||
'user_id' => auth('api')->user()->id,
|
||||
'autoclave_id' => $request->autoclave_id,
|
||||
@@ -217,7 +218,7 @@ class TestResultController extends Controller
|
||||
$TestResult->update($TestResultData);
|
||||
$TestResultInfo = $request->all();
|
||||
|
||||
$Inputs = Input::with('options', 'children', 'children.children')->whereNull('parent_id')->where('test_type_id',$request->test_type_id)->get();
|
||||
$Inputs = Input::with('options', 'children', 'children.options')->whereNull('parent_id')->where('test_type_id',$request->test_type_id)->get();
|
||||
|
||||
foreach ($Inputs as $Input) {
|
||||
if ($Input['type'] != 'Form') {
|
||||
@@ -227,9 +228,15 @@ class TestResultController extends Controller
|
||||
|
||||
$InputOptions = InputValue::where('test_result_id', $TestResult->id)->where('input_id', $Input->id)->get()->each->delete();
|
||||
|
||||
foreach ($Value as $Option) {
|
||||
// $option_array = $Input->options->pluck('id')->toArray();
|
||||
foreach ($Value as $Option) {//--1
|
||||
$InputValueObj = InputValue::create(['test_result_id' => $TestResult->id, 'input_id' => $Input->id, 'option_id' => $Option]);
|
||||
}
|
||||
// foreach ($Input->options as $Option) {//--2
|
||||
// if(in_array($Option->id,$Value)){
|
||||
// $InputValueObj = InputValue::create(['test_result_id' => $TestResult->id, 'input_id' => $Input->id, 'option_id' => $Option]);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
else {
|
||||
$InputValueObj = InputValue::where('test_result_id', $TestResult->id)->where('input_id', $Input['id'])->update(['value' => $Value]);
|
||||
@@ -237,6 +244,7 @@ class TestResultController extends Controller
|
||||
}
|
||||
else {
|
||||
foreach ($Input->children as $InputChild) {
|
||||
|
||||
$Value = $TestResultInfo[$InputChild->name];
|
||||
|
||||
if ($InputChild['type'] == 'Checkbox' || $InputChild['type'] == 'Select') {
|
||||
@@ -245,6 +253,11 @@ class TestResultController extends Controller
|
||||
foreach ($Value as $Option) {
|
||||
$InputValueObj = InputValue::create(['test_result_id' => $TestResult->id, 'input_id' => $InputChild->id, 'option_id' => $Option]);
|
||||
}
|
||||
// foreach ($InputChild->options as $Option) {//--2
|
||||
// if(in_array($Option->id,$Value)){
|
||||
// $InputValueObj = InputValue::create(['test_result_id' => $TestResult->id, 'input_id' => $InputChild->id, 'option_id' => $Option->id]);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
else {
|
||||
$InputValueObj = InputValue::where('test_result_id', $TestResult->id)->where('input_id', $InputChild['id'])->update(['value' => $Value]);
|
||||
|
||||
Reference in New Issue
Block a user