mirror of
https://git.meshkee.com/cssd/cssd-back.git
synced 2026-10-11 11:11:07 +03:30
save changed
This commit is contained in:
@@ -79,7 +79,7 @@ class TestResultController extends Controller
|
||||
|
||||
public function store(StoreTestResultRequest $request)
|
||||
{
|
||||
|
||||
// dd($request->result);
|
||||
try {
|
||||
$return_value = \DB::transaction(function () use ($request) {
|
||||
|
||||
@@ -88,7 +88,7 @@ class TestResultController extends Controller
|
||||
// 'autoclave_id' => $request->autoclave_id,
|
||||
'cycle_number' => $request->cycle_number,
|
||||
'device_id' => $request->device_id,
|
||||
'device_label' => $request->device_label,
|
||||
// 'device_label' => $request->device_label,
|
||||
'test_type_id' => $request->test_type_id,
|
||||
'result' => $request->result,
|
||||
'verified' => 'NotVerified',
|
||||
@@ -102,15 +102,15 @@ 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' || $Input['type'] == 'Radiobutton' || $Input['type'] == 'Range') {
|
||||
if ($Input['type'] == 'Checkbox' || $Input['type'] == 'Select' || $Input['type'] == 'Radiobutton') {
|
||||
|
||||
// foreach ($Value as $Option) {
|
||||
// $InputValueObj = InputValue::create(['test_result_id' => $TestResultObj->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' => $TestResultObj->id, 'input_id' => $Input->id, 'option_id' => $Option->id]);
|
||||
}
|
||||
if(is_array($Value) && in_array($Option->id,$Value)){
|
||||
$InputValueObj = InputValue::create(['test_result_id' => $TestResultObj->id, 'input_id' => $Input->id, 'option_id' => $Option->id]);
|
||||
}
|
||||
if ($Input['type'] == 'Radiobutton' && $Option->id == $Value) {
|
||||
$InputValueObj = InputValue::create(['test_result_id' => $TestResultObj->id, 'input_id' => $Input->id, 'option_id' => $Option->id]);
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
@@ -120,14 +120,15 @@ class TestResultController extends Controller
|
||||
foreach ($Input->children as $InputChild) {
|
||||
$Value = $TestResultInfo[$InputChild->name.'_'.$InputChild->id];
|
||||
|
||||
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]);
|
||||
// }
|
||||
if ($InputChild['type'] == 'Checkbox' || $InputChild['type'] == 'Select' || $InputChild['type'] == 'Radiobutton') {
|
||||
|
||||
foreach ($InputChild->options as $Option) {//--2
|
||||
if(in_array($Option->id,$Value)){
|
||||
if(is_array($Value) && in_array($Option->id,$Value)){
|
||||
$InputValueObj = InputValue::create(['test_result_id' => $TestResultObj->id, 'input_id' => $InputChild->id, 'option_id' => $Option->id]);
|
||||
}
|
||||
if ($Input['type'] == 'Radiobutton' && $Option->id == $Value) {
|
||||
$InputValueObj = InputValue::create(['test_result_id' => $TestResultObj->id, 'input_id' => $InputChild->id, 'option_id' => $Option->id]);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -139,32 +140,16 @@ class TestResultController extends Controller
|
||||
}
|
||||
}
|
||||
///////////////////////////////////////////////////////////////////////////Inputs
|
||||
///////////////////////////////////////////////////////////////////////////Image
|
||||
|
||||
// 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
|
||||
///////////////////////////////////////////////////////////////////////////Images
|
||||
if ($request->imgs != null) {
|
||||
|
||||
foreach ($request->imgs as $img) {
|
||||
foreach ($request->imgs as $key => $img) {
|
||||
// $UniqueID = substr(base_convert(sha1(uniqid(mt_rand())), 16, 36), 0, 10);
|
||||
$Image = $img;
|
||||
$InterventionImage = Image::make($Image);
|
||||
$Mime = explode('/', $InterventionImage->mime());
|
||||
|
||||
$ImageName = time().'.'.$Mime[1];
|
||||
$ImageName = time().$key.'.'.$Mime[1];
|
||||
$Path = 'uploads'.'/TestResults'.'/'.$TestResultObj->id .'/'.$ImageName;
|
||||
|
||||
Storage::disk('public')->makeDirectory('TestResults'.'/'.$TestResultObj->id);
|
||||
@@ -174,7 +159,7 @@ class TestResultController extends Controller
|
||||
$Uploadable = Uploadable::create(['uploadable_id' => $TestResultObj->id, 'uploadable_type' => 'App\TestResult', 'gallery_id' => $GalleryObj->id, 'image_role' => 'TitleImage']);
|
||||
}
|
||||
}
|
||||
///////////////////////////////////////////////////////////////////////////Image
|
||||
///////////////////////////////////////////////////////////////////////////Images
|
||||
|
||||
});
|
||||
} catch (\Exception $e) {
|
||||
@@ -193,7 +178,7 @@ class TestResultController extends Controller
|
||||
|
||||
if ($input->parent_id != null && $input->parent['type'] == 'Form') {
|
||||
//----------------------------------------------------------------------FormType
|
||||
if ($input->type == 'Checkbox' || $input->type == 'Select' || $Input['type'] == 'Radiobutton' || $Input['type'] == 'Range') {
|
||||
if ($input->type == 'Checkbox' || $input->type == 'Select' || $input['type'] == 'Radiobutton') {
|
||||
$input_options = InputValue::with('option')->where('test_result_id', $TestResult->id)->where('input_id', $input->id)->get();
|
||||
$options = [];
|
||||
foreach ($input_options as $input_option) {
|
||||
@@ -213,7 +198,7 @@ class TestResultController extends Controller
|
||||
}
|
||||
else {
|
||||
//-----------------------------------------------------------------------Anothertype
|
||||
if ($input->type == 'Checkbox' || $input->type == 'Select' || $Input['type'] == 'Radiobutton' || $Input['type'] == 'Range') {
|
||||
if ($input->type == 'Checkbox' || $input->type == 'Select' || $input['type'] == 'Radiobutton') {
|
||||
$input_options = InputValue::with('option')->where('test_result_id', $TestResult->id)->where('input_id', $input->id)->get();
|
||||
$options = [];
|
||||
foreach ($input_options as $input_option) {
|
||||
@@ -231,8 +216,12 @@ class TestResultController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
$ImagesPath = [];
|
||||
if (count($TestResult->TitleImage)) {
|
||||
$TestResult['imagePath'] = $TestResult->TitleImage[0]->path;
|
||||
foreach ($TestResult->TitleImage as $Key => $TitleImage) {
|
||||
$ImagesPath[] = $TitleImage->path;
|
||||
}
|
||||
$TestResult['imagesPath'] = $ImagesPath;
|
||||
}
|
||||
return \MessageResponse::data($TestResult);
|
||||
}
|
||||
@@ -241,16 +230,25 @@ class TestResultController extends Controller
|
||||
{
|
||||
foreach ($TestResult->input_values as $key => $value) {
|
||||
$input = $value->input;
|
||||
if ($input->type == 'Checkbox' || $input->type == 'Select' || $Input['type'] == 'Radiobutton' || $Input['type'] == 'Range') {
|
||||
if ($input->type == 'Checkbox' || $input->type == 'Select' || $input['type'] == 'Radiobutton') {
|
||||
$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;
|
||||
if ($input['type'] == 'Radiobutton') {
|
||||
$TestResult[$input->name.'_'.$input->id] = $input_options[0];
|
||||
}
|
||||
else {
|
||||
$TestResult[$input->name.'_'.$input->id] = $input_options;
|
||||
}
|
||||
}
|
||||
else {
|
||||
$TestResult[$input->name.'_'.$input->id] = $value->value;
|
||||
}
|
||||
}
|
||||
$ImagesPath = [];
|
||||
if (count($TestResult->TitleImage)) {
|
||||
$TestResult['imagePath'] = $TestResult->TitleImage[0]->path;
|
||||
foreach ($TestResult->TitleImage as $Key => $TitleImage) {
|
||||
$ImagesPath[] = $TitleImage->path;
|
||||
}
|
||||
$TestResult['imagesPath'] = $ImagesPath;
|
||||
}
|
||||
return \MessageResponse::data($TestResult);
|
||||
}
|
||||
@@ -269,7 +267,7 @@ class TestResultController extends Controller
|
||||
// 'autoclave_id' => $request->autoclave_id,
|
||||
'cycle_number' => $request->cycle_number,
|
||||
'device_id' => $request->device_id,
|
||||
'device_label' => $request->device_label,
|
||||
// 'device_label' => $request->device_label,
|
||||
'test_type_id' => $request->test_type_id,
|
||||
'result' => $request->result,
|
||||
'verified' => 'NotVerified',
|
||||
@@ -282,19 +280,17 @@ 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' || $Input['type'] == 'Radiobutton' || $Input['type'] == 'Range') {
|
||||
if ($Input['type'] == 'Checkbox' || $Input['type'] == 'Select' || $Input['type'] == 'Radiobutton') {
|
||||
|
||||
$InputOptions = InputValue::where('test_result_id', $TestResult->id)->where('input_id', $Input->id)->get()->each->delete();
|
||||
|
||||
// $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)){
|
||||
if(is_array($Value) && in_array($Option->id,$Value)){
|
||||
$InputValueObj = InputValue::create(['test_result_id' => $TestResult->id, 'input_id' => $Input->id, 'option_id' => $Option->id]);
|
||||
}
|
||||
if ($Input['type'] == 'Radiobutton' && $Option->id == $Value) {
|
||||
$InputValueObj = InputValue::create(['test_result_id' => $TestResult->id, 'input_id' => $Input->id, 'option_id' => $Option->id]);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -306,16 +302,16 @@ class TestResultController extends Controller
|
||||
|
||||
$Value = $TestResultInfo[$InputChild->name.'_'.$InputChild->id];
|
||||
|
||||
if ($InputChild['type'] == 'Checkbox' || $InputChild['type'] == 'Select' || $Input['type'] == 'Radiobutton' || $Input['type'] == 'Range') {
|
||||
if ($InputChild['type'] == 'Checkbox' || $InputChild['type'] == 'Select' || $InputChild['type'] == 'Radiobutton') {
|
||||
$InputOptions = InputValue::where('test_result_id', $TestResult->id)->where('input_id', $InputChild->id)->get()->each->delete();
|
||||
|
||||
// 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)){
|
||||
if(is_array($Value) && in_array($Option->id,$Value)){
|
||||
$InputValueObj = InputValue::create(['test_result_id' => $TestResult->id, 'input_id' => $InputChild->id, 'option_id' => $Option->id]);
|
||||
}
|
||||
if ($Input['type'] == 'Radiobutton' && $Option->id == $Value) {
|
||||
$InputValueObj = InputValue::create(['test_result_id' => $TestResult->id, 'input_id' => $InputChild->id, 'option_id' => $Option->id]);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -324,42 +320,38 @@ class TestResultController extends Controller
|
||||
}
|
||||
}
|
||||
}
|
||||
/////////////////////////////////////////////////////////////////////Image
|
||||
$image = '';
|
||||
if (count($TestResult->TitleImage))
|
||||
$image = $TestResult->TitleImage[0];
|
||||
|
||||
if ($request->img != null) {
|
||||
|
||||
$Image = $request->img;
|
||||
$InterventionImage = Image::make($Image);
|
||||
$Mime = explode('/', $InterventionImage->mime());
|
||||
|
||||
$ImageName = time().'.'.$Mime[1];
|
||||
$Path = 'uploads'.'/TestResults'.'/'.$TestResult->id .'/'.$ImageName;
|
||||
|
||||
Storage::disk('public')->makeDirectory('TestResults'.'/'.$TestResult->id);
|
||||
$InterventionImage->save(public_path($Path));
|
||||
|
||||
|
||||
if ($image !== ''){
|
||||
/////////////////////////////////////////////////////////////////////Images
|
||||
$images = '';
|
||||
if (count($TestResult->TitleImage))
|
||||
{
|
||||
$images = $TestResult->TitleImage;
|
||||
foreach ($images as $key => $image) {
|
||||
Storage::disk('public')->delete(static::storage_path($image->path));
|
||||
Uploadable::where('gallery_id', $image->id)->where('uploadable_id', $TestResult->id)->where('uploadable_type', get_class($TestResult))->delete();
|
||||
|
||||
//--------------------------------------------------------
|
||||
$GalleryObj = Gallery::where('id', $image->id)->update(['path' => $Path]);
|
||||
$Uploadable = Uploadable::create(['uploadable_id' => $TestResult->id, 'uploadable_type' => get_class($TestResult), 'gallery_id' => $image->id, 'image_role' => 'TitleImage']);
|
||||
//--------------------------------------------------------
|
||||
|
||||
}
|
||||
else {
|
||||
//--------------------------------------------------------
|
||||
$GalleryObj = Gallery::create(['user_id' => auth('api')->user()->id, 'path' => $Path]);
|
||||
$Uploadable = Uploadable::create(['uploadable_id' => $TestResult->id, 'uploadable_type' => 'App\TestResult', 'gallery_id' => $GalleryObj->id, 'image_role' => 'TitleImage']);
|
||||
//--------------------------------------------------------
|
||||
Gallery::where('id', $image->id)->delete();
|
||||
}
|
||||
}
|
||||
//////////////////////////////////////////////////////////////////Image
|
||||
|
||||
if ($request->imgs != null) {
|
||||
foreach ($request->imgs as $key => $img) {//
|
||||
|
||||
$Image = $img;
|
||||
$InterventionImage = Image::make($Image);
|
||||
$Mime = explode('/', $InterventionImage->mime());
|
||||
|
||||
$ImageName = time().$key.'.'.$Mime[1];
|
||||
$Path = 'uploads'.'/TestResults'.'/'.$TestResult->id .'/'.$ImageName;
|
||||
|
||||
Storage::disk('public')->makeDirectory('TestResults'.'/'.$TestResult->id);
|
||||
$InterventionImage->save(public_path($Path));
|
||||
|
||||
//--------------------------------------------------------
|
||||
$GalleryObj = Gallery::create(['user_id' => auth('api')->user()->id, 'path' => $Path]);
|
||||
$Uploadable = Uploadable::create(['uploadable_id' => $TestResult->id, 'uploadable_type' => 'App\TestResult', 'gallery_id' => $GalleryObj->id, 'image_role' => 'TitleImage']);
|
||||
//--------------------------------------------------------
|
||||
|
||||
}//
|
||||
}
|
||||
|
||||
return \MessageResponse::success(null,trans('messages.update'));
|
||||
}
|
||||
@@ -369,6 +361,16 @@ class TestResultController extends Controller
|
||||
if (!auth('api')->user()->can('delete', $TestResult)) {
|
||||
return \MessageResponse::error(trans('messages.access_denied'));
|
||||
}
|
||||
if (count($TestResult->input_values)) {
|
||||
InputValue::where('test_result_id', $TestResult->id)->get()->each->delete();
|
||||
}
|
||||
if (count($TestResult->TitleImage)){
|
||||
foreach ($TestResult->TitleImage as $image) {
|
||||
Storage::disk('public')->delete(static::storage_path($image->path));
|
||||
Uploadable::where('gallery_id', $image->id)->where('uploadable_id', $TestResult->id)->where('uploadable_type', get_class($TestResult))->delete();
|
||||
Gallery::where('id', $image->id)->delete();
|
||||
}
|
||||
}
|
||||
$TestResult->delete();
|
||||
return \MessageResponse::success(null, trans('messages.success'));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user