Production

This commit is contained in:
saeid
2019-04-29 16:06:18 +04:30
parent 7bda94601c
commit 9c28dc5538
25 changed files with 117 additions and 75850 deletions
+80 -124
View File
@@ -13,8 +13,8 @@ class TestResultController extends Controller
{
public function index()
{
$TestResult = TestResult::with('testtype')->paginate(10);
return response()->json(['TestResult' => $TestResult, 'LastPage' => $TestResult->lastPage()]);
$TestResult = TestResult::with('test_type')->paginate(10);
return \MessageResponse::data($TestResult);
}
public function create()
@@ -22,53 +22,20 @@ class TestResultController extends Controller
//
}
public function CreateChildFormValue2($InputChild,$TestResultObj,$TestResultInfo)
{
// dd($TestResultInfo[$InputChild->name]);
// foreach ($Input->children as $InputChild) {
// public function CreateChildFormValue2($Input,$TestResultObj,$TestResultInfo)
// {
// if ($Input['type'] != 'Form') {
// $Value = $TestResultInfo[$Input->name];
// $InputValueObj = InputValue::create(['test_result_id' => $TestResultObj->id , 'input_id' => $Input->id , 'value' => $Value]);
// }
// else {
// foreach ($Input->children as $InputChild) {
// $this->CreateChildFormValue2($InputChild,$TestResultObj,$TestResultInfo[$Input->name]);
// }
// }
//
// }
$TestResultInfo = $TestResultInfo[$InputChild->name];
if ($InputChild->type == 'Form') {
foreach ($InputChild->children as $InputChild2) {
// dd($TestResultInfo[$InputChild2->name]);
$this->CreateChildFormValue($InputChild2,$TestResultObj,$TestResultInfo[$InputChild2->name]);
}
}
$Value = $TestResultInfo;
// dd($Value);
$InputValueObj = InputValue::create(['test_result_id' => $TestResultObj->id , 'input_id' => $InputChild['id'] , 'value' => $Value]);
// dd(['test_result_id' => $TestResultObj->id , 'input_id' => $InputChild['id'] , 'value' => $Value]);
// }
}
public function CreateChildFormValue($Input,$TestResultObj,$TestResultInfo)
{
// dd($Input->children[0]->children);
// if ($Input->type == 'Form') {
// code...
// $TestResultInfo = $TestResultInfo[$Input->name];
foreach ($Input->children as $InputChild) {
// $TestResultInfo = $TestResultInfo[$InputChild->name];
if ($InputChild->type == 'Form') {
// dd($TestResultInfo[$InputChild->name]);
$this->CreateChildFormValue($InputChild,$TestResultObj,$TestResultInfo[$InputChild->name]);
// dd($InputChild);
}
else {
$Value = $TestResultInfo[$InputChild->name];
// dd($Value);
$InputValueObj = InputValue::create(['test_result_id' => $TestResultObj->id , 'input_id' => $InputChild['id'] , 'value' => $Value ]);
}
}
return 'success';
}
public function store(StoreTestResultRequest $request)
{
try {
@@ -82,90 +49,56 @@ class TestResultController extends Controller
'verified' => 0,
];
$TestResultObj = TestResult::create($TestResult);
// $TestResultInfo = $request['info'];
$TestResultInfo = [];
$TestResultInfo = $request->all();
$Inputs = Input::with('options','children','children.children')->where('test_type_id',$request->test_type_id)->get();
// dd($Inputs->toArray()[2]);
// foreach ($Inputs as $Input) {
// if ($Input['type'] == 'Form') {
// $TestResultInfo = $request[$Input->name];
//
// // $this->CreateChildFormValue($Input,$TestResultObj,$TestResultInfo);
//
// ///--------------------------------------------------
// foreach ($Input->children as $InputChild) {
//
// $this->CreateChildFormValue($InputChild,$TestResultObj,$TestResultInfo);
// ///--------------------------------------------------
// // $Value = $TestResultInfo[$InputChild->name];
// //
// // if ($InputChild->type == 'Form') {
// // foreach ($InputChild->children as $InputChild2) {
// // $Value = $TestResultInfo[$InputChild->name][$InputChild2->name];
// // $InputValueObj = InputValue::create(['test_result_id' => $TestResultObj->id , 'input_id' => $InputChild2['id'] , 'value' => $Value]);
// // return 'success';
// // }
// //
// // }
// // $InputValueObj = InputValue::create(['test_result_id' => $TestResultObj->id , 'input_id' => $InputChild['id'] , 'value' => $Value]);
// }
// ///--------------------------------------------------
// }
// else {
// $TestResultInfo = $request->all();
// }
// $Value = $TestResultInfo[$Input->name];
// $InputValueObj = InputValue::create(['test_result_id' => $TestResultObj->id , 'input_id' => $Input->id , 'value' => $Value]);
// }
////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////--2
foreach ($Inputs as $Input) {
if ($Input['type'] != 'Form') {
$Value = $TestResultInfo[$Input->name];
$InputValueObj = InputValue::create(['test_result_id' => $TestResultObj->id , 'input_id' => $Input->id , 'value' => $Value]);
}
else {
foreach ($Input->children as $InputChild) {
$Value = $TestResultInfo[$Input->name][$InputChild->name];
$InputValueObj = InputValue::create(['test_result_id' => $TestResultObj->id , 'input_id' => $InputChild->id , 'value' => $Value]);
}
//-------------------------------------------------------
// $this->CreateChildFormValue2($Input,$TestResultObj,$TestResultInfo);
// foreach ($Input->children as $InputChild) {
//
// if ($InputChild['type'] != 'Form') {
// $Value = $TestResultInfo[$Input->name][$InputChild->name];
// $InputValueObj = InputValue::create(['test_result_id' => $TestResultObj->id , 'input_id' => $InputChild->id , 'value' => $Value]);
// }
// else {
//
// foreach ($InputChild->children as $InputChild2) {
//
// if ($InputChild2['type'] != 'Form') {
// $Value = $TestResultInfo[$Input->name][$InputChild->name][$InputChild2->name];
// $InputValueObj = InputValue::create(['test_result_id' => $TestResultObj->id , 'input_id' => $InputChild2->id , 'value' => $Value]);
// }
// else {
//
// }
//
// }
// }
//
// }
//---------------------------------------------------------
foreach ($Inputs as $Input) {
if ($Input['type'] == 'Form') {
$TestResultInfo = $request[$Input->name];//-----estesna
}
}
$this->CreateChildFormValue($Input,$TestResultObj,$TestResultInfo);
//******
///--------------------------------------------------
// foreach ($Input->children as $InputChild) {
//
// $TestResultInfo = $TestResultInfo[$InputChild->name];
// // dd($TestResultInfo);
// if ($InputChild->type == 'Form') {
// foreach ($InputChild->children as $InputChild2) {
//
// $Value = $TestResultInfo[$InputChild->name][$InputChild2->name];
//
// $InputValueObj = InputValue::create(['test_result_id' => $TestResultObj->id , 'input_id' => $InputChild2['id'] , 'value' => $Value]);
// return 'success';
// }
// }
// $InputValueObj = InputValue::create(['test_result_id' => $TestResultObj->id , 'input_id' => $InputChild['id'] , 'value' => $Value]);
// }
///--------------------------------------------------
}
else {
// $TestResultInfo = $request->all();
$Value = $request[$Input->name];
// dd($Value);
$InputValueObj = InputValue::create(['test_result_id' => $TestResultObj->id , 'input_id' => $Input->id , 'value' => $Value]);
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////
});
} catch (\Exception $e) {
return response()->json($e->getMessage(), 441);
}
return \MessageResponse::success();
// }
return \MessageResponse::success(null,trans('messages.create'));
}
@@ -181,8 +114,31 @@ class TestResultController extends Controller
public function update(StoreTestResultRequest $request, TestResult $TestResult)
{
$TestResult->update($request->all());
return response()->json(trans('messages.success'));
$TestResultData = [
'user_id' => auth('api')->user()->id,
'autoclave_id' => $request->autoclave_id,
'test_type_id' => $request->test_type_id,
'result' => $request->result,
'verified' => 0,
];
$TestResult->update($TestResultData);
$TestResultInfo = $request->all();
$Inputs = Input::with('options','children','children.children')->where('test_type_id',$request->test_type_id)->get();
foreach ($Inputs as $Input) {
if ($Input['type'] != 'Form') {
$Value = $TestResultInfo[$Input->name];
$InputValueObj = InputValue::where('test_result_id',$TestResult)->update(['test_result_id' => $TestResultObj->id , 'input_id' => $Input->id , 'value' => $Value]);
}
else {
foreach ($Input->children as $InputChild) {
$Value = $TestResultInfo[$Input->name][$InputChild->name];
$InputValueObj = InputValue::where('test_result_id',$TestResult)->update(['test_result_id' => $TestResultObj->id , 'input_id' => $InputChild->id , 'value' => $Value]);
}
}
}
return \MessageResponse::success(null,trans('messages.update'));
}
public function destroy($id)
+14 -35
View File
@@ -16,12 +16,6 @@ class TestTypeController extends Controller
return \MessageResponse::data($TestTypes);
}
public function listNames()
{
$TestTypes = TestType::pluck('name');
return \MessageResponse::data($TestTypes);
}
public function create()
{
//
@@ -137,33 +131,7 @@ class TestTypeController extends Controller
//------------------------------------------------------Option
return $InputInfo;
}
// public function CreateChildFormInfo($Input,$InputInfo)
// {
// foreach ($Input['children'] as $InputChild) {
//
// $ChildInfo = $this->CreateInputInfo($InputChild);
// $InputInfo['children'] = $ChildInfo;
//
// if ($InputChild['type'] == 'Form') {
// return $this->CreateChildFormInfo($InputChild,$ChildInfo);
// }
// }
//
// return $InputInfo;
// }
// public function CreateChildFormInfo($Input,$InputInfo)
// {
// foreach ($Input['children'] as $InputChild) {
//
// $InputInfo['children'] = $this->CreateInputInfo($InputChild);
// $ChildInfo = $InputInfo['children'];
// $Children[] = $ChildInfo;
// if ($InputChild['type'] == 'Form') {
// $ChildInfo['children'] = $this->CreateChildFormInfo($InputChild,$ChildInfo);
// }
// }
// return $Children;
// }
public function CreateChildFormInfo($Input,$InputInfo)
{
$Children = [];
@@ -362,13 +330,24 @@ class TestTypeController extends Controller
{
$TestType = TestType::where('name', $request->name)->orWhere('unique_code', $request->unique_code)->first();
if ($TestType) {
$Inputs = Input::select('id','name','type','size','parent_id')->with('options','children','children.options')->whereNull('parent_id')->where('test_type_id',$TestType->id)->get();
$Inputs = Input::select('id','name','type','size','parent_id')->with(
['options' => function ($query) {
$query->select('id', 'title','input_id');
}],
['children' => function ($query) {
$query->select('id','name','type','size','parent_id');
}],
['children.options' => function ($query) {
$query->select('id', 'title','input_id');
}]
)->whereNull('parent_id')->where('test_type_id',$TestType->id)->get();
return \MessageResponse::data($Inputs);
}
return \MessageResponse::error();
}
public function destroy($id)
{
//
}
}