change TestType & TestResult

This commit is contained in:
Fayyazi
2019-07-15 13:41:05 +04:30
parent d3735c6d30
commit 969f8b8b45
7 changed files with 91 additions and 35 deletions
+43 -19
View File
@@ -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) {
+3 -3
View File
@@ -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') {
//**************************
+8 -12
View File
@@ -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;
+29
View File
@@ -0,0 +1,29 @@
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Item extends Model
{
public $fillable = [];
public function packages()
{
return $this->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');
//
// });
+4
View File
@@ -11,5 +11,9 @@ class Package extends Model
{
return $this->belongsTo('App\User');
}
public function items()
{
return $this->belongsToMany('App\Item', 'item_package');
}
}
+1 -1
View File
@@ -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');
@@ -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');