This commit is contained in:
saeid
2019-05-06 21:48:46 +04:30
parent 5d8500dafd
commit f6d7277ddc
14 changed files with 268 additions and 168 deletions
+62 -17
View File
@@ -38,7 +38,6 @@ class TestResultController extends Controller
public function store(StoreTestResultRequest $request)
{
// dd($request->all());
try {
$return_value = \DB::transaction(function () use ($request) {
@@ -52,24 +51,39 @@ class TestResultController extends Controller
$TestResultObj = TestResult::create($TestResult);
$TestResultInfo = $request->all();
$Inputs = Input::with('options','children','children.children')->where('test_type_id',$request->test_type_id)->get();
$Inputs = Input::with('options','children','children.children')->whereNull('parent_id')->where('test_type_id',$request->test_type_id)->get();
////////////////////////////////////////////////////////////////////////////////////--2
foreach ($Inputs as $Input) {
if ($Input['type'] != 'Form') {
$Value = $TestResultInfo[$Input->name];
if ($Input['type'] == 'Checkbox') {
$Value = json_encode($Value);
if ($Input['type'] == 'Checkbox' || $Input['type'] == 'Select' ) {
foreach ($Value as $Option) {
// dd($Option);
$InputValueObj = InputValue::create(['test_result_id' => $TestResultObj->id, 'input_id' => $Input->id, 'option_id' => $Option]);
}
}
$InputValueObj = InputValue::create(['test_result_id' => $TestResultObj->id , 'input_id' => $Input->id , 'value' => $Value]);
else {
$InputValueObj = InputValue::create(['test_result_id' => $TestResultObj->id, 'input_id' => $Input->id, 'value' => $Value]);
}
}
else {
foreach ($Input->children as $InputChild) {
$Value = $TestResultInfo[$InputChild->name];
if ($InputChild['type'] == 'Checkbox') {
$Value = json_encode($Value);
if ($InputChild['type'] == 'Checkbox' || $InputChild['type'] == 'Select') {
// dd($InputChild['type']);
foreach ($Value as $Option) {
$InputValueObj = InputValue::create(['test_result_id' => $TestResultObj->id, 'input_id' => $InputChild->id, 'option_id' => $Option]);
}
}
$InputValueObj = InputValue::create(['test_result_id' => $TestResultObj->id , 'input_id' => $InputChild->id , 'value' => $Value]);
else {
$InputValueObj = InputValue::create(['test_result_id' => $TestResultObj->id, 'input_id' => $InputChild->id, 'value' => $Value]);
}
}
//-------------------------------------------------------
// $this->CreateChildFormValue2($Input,$TestResultObj,$TestResultInfo);
@@ -99,6 +113,13 @@ class TestResultController extends Controller
}
}
// if ($request->hasFile('image')) {
// $image = $request->file('image');
// $input['imagename'] = time().$image->getClientOriginalExtension();
// $path = '/Uploads'.'/'.$TestResultObj->id;
// Storage::disk('public')->makeDirectory($TestResultObj->id);
// $image->move($path, $input['imagename']);
// }
});
@@ -109,9 +130,19 @@ class TestResultController extends Controller
}
public function show($id)
public function show(TestResult $TestResult)
{
//
foreach ($TestResult->input_values as $key => $value) {
$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;
}
else {
$TestResult[$input->name] = $value->value;
}
}
return \MessageResponse::data($TestResult);
}
//Todo:: pass Inputs
@@ -119,7 +150,13 @@ class TestResultController extends Controller
{
foreach ($TestResult->input_values as $key => $value) {
$input = $value->input;
$TestResult[$input->name] = $value->value;
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;
}
else {
$TestResult[$input->name] = $value->value;
}
}
return \MessageResponse::data($TestResult);
}
@@ -136,24 +173,32 @@ class TestResultController extends Controller
$TestResult->update($TestResultData);
$TestResultInfo = $request->all();
$Inputs = Input::with('options','children','children.children')->where('test_type_id',$request->test_type_id)->get();
$Inputs = Input::with('options','children','children.children')->whereNull('parent_id')->where('test_type_id',$request->test_type_id)->get();
foreach ($Inputs as $Input) {
if ($Input['type'] != 'Form') {
$Value = $TestResultInfo[$Input->name];
if ($Input['type'] == 'Checkbox') {
$Value = json_encode($Value);
if ($Input['type'] == 'Checkbox' || $Input['type'] == 'Select' ) {
foreach ($Value as $Option) {
// $InputValueObj = InputValue::create(['test_result_id' => $TestResultObj->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]);
}
$InputValueObj = InputValue::where('test_result_id',$TestResult->id)->where('input_id', $Input['id'])->update(['value' => $Value]);
}
else {
foreach ($Input->children as $InputChild) {
$Value = $TestResultInfo[$InputChild->name];
if ($InputChild['type'] == 'Checkbox') {
if ($InputChild['type'] == 'Checkbox' || $InputChild['type'] == 'Select') {
$Value = json_encode($Value);
}
$InputValueObj = InputValue::where('test_result_id',$TestResult->id)->where('input_id', $Input['id'])->update(['value' => $Value]);
else {
$InputValueObj = InputValue::where('test_result_id',$TestResult->id)->where('input_id', $InputChild['id'])->update(['value' => $Value]);
}
}
}
}