From 969f8b8b4531f925b0da5b457947a51af50ed195 Mon Sep 17 00:00:00 2001 From: Fayyazi Date: Mon, 15 Jul 2019 13:41:05 +0430 Subject: [PATCH] change TestType & TestResult --- app/Http/Controllers/TestResultController.php | 62 +++++++++++++------ app/Http/Controllers/TestTypeController.php | 6 +- app/Http/Requests/StoreTestResultRequest.php | 20 +++--- app/Item.php | 29 +++++++++ app/Package.php | 4 ++ app/TestResult.php | 2 +- ...04_11_105013_create_test_results_table.php | 3 + 7 files changed, 91 insertions(+), 35 deletions(-) create mode 100644 app/Item.php diff --git a/app/Http/Controllers/TestResultController.php b/app/Http/Controllers/TestResultController.php index 2b54abbf..20b82f4d 100644 --- a/app/Http/Controllers/TestResultController.php +++ b/app/Http/Controllers/TestResultController.php @@ -85,7 +85,10 @@ class TestResultController extends Controller $TestResult = [ 'user_id' => auth('api')->user()->id, - 'autoclave_id' => $request->autoclave_id, + // 'autoclave_id' => $request->autoclave_id, + 'cycle_number' => $request->cycle_number, + 'device_id' => $request->device_id, + 'device_label' => $request->device_label, 'test_type_id' => $request->test_type_id, 'result' => $request->result, 'verified' => 'NotVerified', @@ -99,7 +102,7 @@ class TestResultController extends Controller foreach ($Inputs as $Input) { if ($Input['type'] != 'Form') { $Value = $TestResultInfo[$Input->name.'_'.$Input->id]; - if ($Input['type'] == 'Checkbox' || $Input['type'] == 'Select' ) { + if ($Input['type'] == 'Checkbox' || $Input['type'] == 'Select' || $Input['type'] == 'Radiobutton' || $Input['type'] == 'Range') { // foreach ($Value as $Option) { // $InputValueObj = InputValue::create(['test_result_id' => $TestResultObj->id, 'input_id' => $Input->id, 'option_id' => $Option]); @@ -117,7 +120,7 @@ class TestResultController extends Controller foreach ($Input->children as $InputChild) { $Value = $TestResultInfo[$InputChild->name.'_'.$InputChild->id]; - if ($InputChild['type'] == 'Checkbox' || $InputChild['type'] == 'Select') { + if ($InputChild['type'] == 'Checkbox' || $InputChild['type'] == 'Select' || $Input['type'] == 'Radiobutton' || $Input['type'] == 'Range') { // foreach ($Value as $Option) { // $InputValueObj = InputValue::create(['test_result_id' => $TestResultObj->id, 'input_id' => $InputChild->id, 'option_id' => $Option]); // } @@ -138,20 +141,38 @@ class TestResultController extends Controller ///////////////////////////////////////////////////////////////////////////Inputs ///////////////////////////////////////////////////////////////////////////Image - if ($request->img != null) { + // if ($request->img != null) { + // + // $Image = $request->img; + // $InterventionImage = Image::make($Image); + // $Mime = explode('/', $InterventionImage->mime()); + // + // $ImageName = time().'.'.$Mime[1]; + // $Path = 'uploads'.'/TestResults'.'/'.$TestResultObj->id .'/'.$ImageName; + // + // Storage::disk('public')->makeDirectory('TestResults'.'/'.$TestResultObj->id); + // $InterventionImage->save(public_path($Path)); + // + // $GalleryObj = Gallery::create(['user_id' => auth('api')->user()->id, 'path' => $Path]); + // $Uploadable = Uploadable::create(['uploadable_id' => $TestResultObj->id, 'uploadable_type' => 'App\TestResult', 'gallery_id' => $GalleryObj->id, 'image_role' => 'TitleImage']); + // } + //-------------------------------------------------imgs + if ($request->imgs != null) { - $Image = $request->img; - $InterventionImage = Image::make($Image); - $Mime = explode('/', $InterventionImage->mime()); + foreach ($request->imgs as $img) { + $Image = $img; + $InterventionImage = Image::make($Image); + $Mime = explode('/', $InterventionImage->mime()); - $ImageName = time().'.'.$Mime[1]; - $Path = 'uploads'.'/TestResults'.'/'.$TestResultObj->id .'/'.$ImageName; + $ImageName = time().'.'.$Mime[1]; + $Path = 'uploads'.'/TestResults'.'/'.$TestResultObj->id .'/'.$ImageName; - Storage::disk('public')->makeDirectory('TestResults'.'/'.$TestResultObj->id); - $InterventionImage->save(public_path($Path)); + Storage::disk('public')->makeDirectory('TestResults'.'/'.$TestResultObj->id); + $InterventionImage->save(public_path($Path)); - $GalleryObj = Gallery::create(['user_id' => auth('api')->user()->id, 'path' => $Path]); - $Uploadable = Uploadable::create(['uploadable_id' => $TestResultObj->id, 'uploadable_type' => 'App\TestResult', 'gallery_id' => $GalleryObj->id, 'image_role' => 'TitleImage']); + $GalleryObj = Gallery::create(['user_id' => auth('api')->user()->id, 'path' => $Path]); + $Uploadable = Uploadable::create(['uploadable_id' => $TestResultObj->id, 'uploadable_type' => 'App\TestResult', 'gallery_id' => $GalleryObj->id, 'image_role' => 'TitleImage']); + } } ///////////////////////////////////////////////////////////////////////////Image @@ -172,7 +193,7 @@ class TestResultController extends Controller if ($input->parent_id != null && $input->parent['type'] == 'Form') { //----------------------------------------------------------------------FormType - if ($input->type == 'Checkbox' || $input->type == 'Select') { + if ($input->type == 'Checkbox' || $input->type == 'Select' || $Input['type'] == 'Radiobutton' || $Input['type'] == 'Range') { $input_options = InputValue::with('option')->where('test_result_id', $TestResult->id)->where('input_id', $input->id)->get(); $options = []; foreach ($input_options as $input_option) { @@ -192,7 +213,7 @@ class TestResultController extends Controller } else { //-----------------------------------------------------------------------Anothertype - if ($input->type == 'Checkbox' || $input->type == 'Select') { + if ($input->type == 'Checkbox' || $input->type == 'Select' || $Input['type'] == 'Radiobutton' || $Input['type'] == 'Range') { $input_options = InputValue::with('option')->where('test_result_id', $TestResult->id)->where('input_id', $input->id)->get(); $options = []; foreach ($input_options as $input_option) { @@ -220,7 +241,7 @@ class TestResultController extends Controller { foreach ($TestResult->input_values as $key => $value) { $input = $value->input; - if ($input->type == 'Checkbox' || $input->type == 'Select') { + if ($input->type == 'Checkbox' || $input->type == 'Select' || $Input['type'] == 'Radiobutton' || $Input['type'] == 'Range') { $input_options = InputValue::where('test_result_id', $TestResult->id)->where('input_id', $input->id)->get()->pluck('option_id')->toArray(); $TestResult[$input->name.'_'.$input->id] = $input_options; } @@ -245,7 +266,10 @@ class TestResultController extends Controller public function update(StoreTestResultRequest $request, TestResult $TestResult) { $TestResultData = [ - 'autoclave_id' => $request->autoclave_id, + // 'autoclave_id' => $request->autoclave_id, + 'cycle_number' => $request->cycle_number, + 'device_id' => $request->device_id, + 'device_label' => $request->device_label, 'test_type_id' => $request->test_type_id, 'result' => $request->result, 'verified' => 'NotVerified', @@ -259,7 +283,7 @@ class TestResultController extends Controller if ($Input['type'] != 'Form') { $Value = $TestResultInfo[$Input->name.'_'.$Input->id]; - if ($Input['type'] == 'Checkbox' || $Input['type'] == 'Select' ) { + if ($Input['type'] == 'Checkbox' || $Input['type'] == 'Select' || $Input['type'] == 'Radiobutton' || $Input['type'] == 'Range') { $InputOptions = InputValue::where('test_result_id', $TestResult->id)->where('input_id', $Input->id)->get()->each->delete(); @@ -282,7 +306,7 @@ class TestResultController extends Controller $Value = $TestResultInfo[$InputChild->name.'_'.$InputChild->id]; - if ($InputChild['type'] == 'Checkbox' || $InputChild['type'] == 'Select') { + if ($InputChild['type'] == 'Checkbox' || $InputChild['type'] == 'Select' || $Input['type'] == 'Radiobutton' || $Input['type'] == 'Range') { $InputOptions = InputValue::where('test_result_id', $TestResult->id)->where('input_id', $InputChild->id)->get()->each->delete(); // foreach ($Value as $Option) { diff --git a/app/Http/Controllers/TestTypeController.php b/app/Http/Controllers/TestTypeController.php index 1b3114b9..84fc693c 100644 --- a/app/Http/Controllers/TestTypeController.php +++ b/app/Http/Controllers/TestTypeController.php @@ -75,7 +75,7 @@ class TestTypeController extends Controller $InputObj = Input::create($InputData); //---------------------------------------------Input //---------------------------------------------Option - if ($Input['type'] == 'Checkbox' || $Input['type'] == 'Select') { + if ($Input['type'] == 'Checkbox' || $Input['type'] == 'Select' || $Input['type'] == 'Radiobutton' || $Input['type'] == 'Range') { foreach ($Input['options'] as $Option) { $Option = Option::create(['title' => $Option['title'] , 'input_id' => $InputObj->id]); } @@ -151,7 +151,7 @@ class TestTypeController extends Controller ]; //------------------------------------------------------Input //------------------------------------------------------Option - if ($Input['type'] == 'Checkbox' || $Input['type'] == 'Select') { + if ($Input['type'] == 'Checkbox' || $Input['type'] == 'Select' || $Input['type'] == 'Radiobutton' || $Input['type'] == 'Range') { foreach ($Input['options'] as $Option) { $OptionInfo = [ @@ -230,7 +230,7 @@ class TestTypeController extends Controller $InputObj = Input::findOrFail($Input['id']); //---------------------------------------------Input //---------------------------------------------Option - if ($Input['type'] == 'Checkbox' || $Input['type'] == 'Select') { + if ($Input['type'] == 'Checkbox' || $Input['type'] == 'Select' || $Input['type'] == 'Radiobutton' || $Input['type'] == 'Range') { //************************** diff --git a/app/Http/Requests/StoreTestResultRequest.php b/app/Http/Requests/StoreTestResultRequest.php index 255d60e4..fd51871f 100644 --- a/app/Http/Requests/StoreTestResultRequest.php +++ b/app/Http/Requests/StoreTestResultRequest.php @@ -26,14 +26,12 @@ class StoreTestResultRequest extends FormRequest case 'POST': { return [ // 'user_id' => 'required', - 'autoclave_id' => 'required', + // 'autoclave_id' => 'required', + 'device_id' => 'required', + 'device_label' => 'required', + 'cycle_number' => 'required', 'test_type_id' => 'required|numeric|exists:test_types,id', 'result' => 'required', - // 'verified' => 'required', - // 'info.*.name'=>'required', - // 'info.*.type'=>'required', - // 'info.*.size'=>'nullable', - // 'info.*.parent_id'=>'nullable|numeric|exists:inputs,id', ]; break; } @@ -42,14 +40,12 @@ class StoreTestResultRequest extends FormRequest // $TestResult = $this->route('TestResult'); return [ // 'user_id' => 'required', - 'autoclave_id' => 'required', + // 'autoclave_id' => 'required', + 'device_id' => 'required', + 'device_label' => 'required', + 'cycle_number' => 'required', 'test_type_id' => 'required|numeric|exists:test_types,id', 'result' => 'required', - // 'verified' => 'required', - // 'info.*.name'=>'required', - // 'info.*.type'=>'required', - // 'info.*.size'=>'nullable', - // 'info.*.parent_id'=>'nullable|numeric|exists:inputs,id', ]; break; diff --git a/app/Item.php b/app/Item.php new file mode 100644 index 00000000..9a100a5c --- /dev/null +++ b/app/Item.php @@ -0,0 +1,29 @@ +belongsToMany('App\Package', 'item_package'); + } +} +// Schema::create('role_user', function (Blueprint $table) { +// +// $table->integer('user_id')->unsigned(); +// +// $table->integer('role_id')->unsigned(); +// +// $table->foreign('user_id')->references('id')->on('users') +// +// ->onDelete('cascade'); +// +// $table->foreign('role_id')->references('id')->on('roles') +// +// ->onDelete('cascade'); +// +// }); diff --git a/app/Package.php b/app/Package.php index 6c94c823..c1c178f3 100644 --- a/app/Package.php +++ b/app/Package.php @@ -11,5 +11,9 @@ class Package extends Model { return $this->belongsTo('App\User'); } + public function items() + { + return $this->belongsToMany('App\Item', 'item_package'); + } } diff --git a/app/TestResult.php b/app/TestResult.php index 59e98932..95ffd385 100644 --- a/app/TestResult.php +++ b/app/TestResult.php @@ -6,7 +6,7 @@ use Illuminate\Database\Eloquent\Model; class TestResult extends Model { - public $fillable = ['result','verified','autoclave_id','test_type_id','user_id']; + public $fillable = ['result','verified','autoclave_id','test_type_id','user_id','device_id', 'device_label', 'cycle_number']; public function test_type() { return $this->belongsTo('App\TestType'); diff --git a/database/migrations/2019_04_11_105013_create_test_results_table.php b/database/migrations/2019_04_11_105013_create_test_results_table.php index e8ff5734..afc05338 100644 --- a/database/migrations/2019_04_11_105013_create_test_results_table.php +++ b/database/migrations/2019_04_11_105013_create_test_results_table.php @@ -16,9 +16,12 @@ class CreateTestResultsTable extends Migration Schema::create('test_results', function (Blueprint $table) { $table->bigIncrements('id'); $table->string('info'); + $table->string('cycle_number'); $table->string('result'); $table->text('description'); $table->smallInteger('verified'); + $table->string('device_id'); + $table->string('device_label'); $table->integer('autoclave_id'); $table->unsignedBigInteger('user_id'); $table->foreign('user_id')->references('id')->on('users');