mirror of
https://git.meshkee.com/cssd/cssd-back.git
synced 2026-10-11 15:31:06 +03:30
saeid
This commit is contained in:
@@ -8,6 +8,10 @@ use App\Http\Requests\StoreTestResultRequest;
|
||||
use App\TestResult;
|
||||
use App\InputValue;
|
||||
use App\Input;
|
||||
use App\Gallery;
|
||||
use App\Uploadable;
|
||||
use Intervention\Image\ImageManagerStatic as Image;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class TestResultController extends Controller
|
||||
{
|
||||
@@ -53,7 +57,7 @@ class TestResultController extends Controller
|
||||
|
||||
$Inputs = Input::with('options','children','children.children')->whereNull('parent_id')->where('test_type_id',$request->test_type_id)->get();
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////--2
|
||||
///////////////////////////////////////////////////////////////////////////Inputs
|
||||
foreach ($Inputs as $Input) {
|
||||
if ($Input['type'] != 'Form') {
|
||||
$Value = $TestResultInfo[$Input->name];
|
||||
@@ -61,21 +65,18 @@ class TestResultController extends Controller
|
||||
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]);
|
||||
}
|
||||
}
|
||||
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' || $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]);
|
||||
}
|
||||
@@ -85,42 +86,27 @@ class TestResultController extends Controller
|
||||
}
|
||||
|
||||
}
|
||||
//-------------------------------------------------------
|
||||
// $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 {
|
||||
//
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//---------------------------------------------------------
|
||||
|
||||
}
|
||||
}
|
||||
// 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']);
|
||||
// }
|
||||
///////////////////////////////////////////////////////////////////////////Inputs
|
||||
///////////////////////////////////////////////////////////////////////////Image
|
||||
if ($request->hasFile('img')) {
|
||||
|
||||
$Image = $request->file('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']);
|
||||
}
|
||||
///////////////////////////////////////////////////////////////////////////Image
|
||||
|
||||
});
|
||||
} catch (\Exception $e) {
|
||||
@@ -130,22 +116,59 @@ class TestResultController extends Controller
|
||||
|
||||
}
|
||||
|
||||
public function show(TestResult $TestResult)
|
||||
public function show($id)
|
||||
{
|
||||
$TestResult = TestResult::with('input_values', 'user')->select('result', 'verified', 'autoclave_id','user_id','id')->findOrFail($id);
|
||||
$options = [];
|
||||
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;
|
||||
|
||||
if ($input->parent_id != null && $input->parent['type'] == 'Form') {
|
||||
//----------------------------------------------------------------------FormType
|
||||
if ($input->type == 'Checkbox' || $input->type == 'Select') {
|
||||
$input_options = InputValue::with('option')->where('test_result_id', $TestResult->id)->where('input_id', $input->id)->get();
|
||||
$options = [];
|
||||
foreach ($input_options as $input_option) {
|
||||
$options[] = $input_option->option->title;
|
||||
$input_values[$input->name] = $options;
|
||||
}
|
||||
|
||||
$children[$input->parent->name] = $input_values;
|
||||
$TestResult['children'] = $children;
|
||||
}
|
||||
else {
|
||||
$input_values = [$input->name => $value->value];
|
||||
$children[$input->parent->name] = $input_values;
|
||||
$TestResult['children'] = $children;
|
||||
}
|
||||
//-----------------------------------------------------------------------FormType
|
||||
}
|
||||
else {
|
||||
$TestResult[$input->name] = $value->value;
|
||||
//-----------------------------------------------------------------------Anothertype
|
||||
if ($input->type == 'Checkbox' || $input->type == 'Select') {
|
||||
$input_options = InputValue::with('option')->where('test_result_id', $TestResult->id)->where('input_id', $input->id)->get();
|
||||
$options = [];
|
||||
foreach ($input_options as $input_option) {
|
||||
$options[] = $input_option->option->title;
|
||||
}
|
||||
|
||||
$values[$input->name] = $options;
|
||||
$TestResult['options'] = $values;
|
||||
}
|
||||
else {
|
||||
$inputs[$input->name] = $value->value;
|
||||
$TestResult['inputs'] = $inputs;
|
||||
}
|
||||
//-----------------------------------------------------------------------Anothertype
|
||||
}
|
||||
}
|
||||
|
||||
if (count($TestResult->TitleImage)) {
|
||||
$TestResult['imagePath'] = $TestResult->TitleImage[0]->path;
|
||||
}
|
||||
return \MessageResponse::data($TestResult);
|
||||
}
|
||||
|
||||
//Todo:: pass Inputs
|
||||
public function edit(TestResult $TestResult)
|
||||
{
|
||||
foreach ($TestResult->input_values as $key => $value) {
|
||||
@@ -161,6 +184,14 @@ class TestResultController extends Controller
|
||||
return \MessageResponse::data($TestResult);
|
||||
}
|
||||
|
||||
public static function storage_path($path)
|
||||
{
|
||||
if (starts_with($path, 'uploads/')) {
|
||||
$path = substr($path, 8);
|
||||
}
|
||||
return $path;
|
||||
}
|
||||
|
||||
public function update(StoreTestResultRequest $request, TestResult $TestResult)
|
||||
{
|
||||
$TestResultData = [
|
||||
@@ -173,51 +204,94 @@ class TestResultController extends Controller
|
||||
$TestResult->update($TestResultData);
|
||||
$TestResultInfo = $request->all();
|
||||
|
||||
$Inputs = Input::with('options','children','children.children')->whereNull('parent_id')->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' || $Input['type'] == 'Select' ) {
|
||||
|
||||
$InputOptions = InputValue::where('test_result_id', $TestResult->id)->where('input_id', $Input->id)->get()->each->delete();
|
||||
|
||||
foreach ($Value as $Option) {
|
||||
// $InputValueObj = InputValue::create(['test_result_id' => $TestResultObj->id, 'input_id' => $Input->id, 'option_id' => $Option]);
|
||||
$InputValueObj = InputValue::create(['test_result_id' => $TestResult->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' || $InputChild['type'] == 'Select') {
|
||||
$Value = json_encode($Value);
|
||||
$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]);
|
||||
}
|
||||
}
|
||||
else {
|
||||
$InputValueObj = InputValue::where('test_result_id',$TestResult->id)->where('input_id', $InputChild['id'])->update(['value' => $Value]);
|
||||
$InputValueObj = InputValue::where('test_result_id', $TestResult->id)->where('input_id', $InputChild['id'])->update(['value' => $Value]);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
return \MessageResponse::success(null,trans('messages.update'));
|
||||
//////////////////////////////////////////////////////////////////Image
|
||||
$image = '';
|
||||
if (count($TestResult->TitleImage))
|
||||
$image = $TestResult->TitleImage[0];
|
||||
|
||||
if ($request->hasFile('img')) {
|
||||
|
||||
$Image = $request->file('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 !== ''){
|
||||
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']);
|
||||
//--------------------------------------------------------
|
||||
}
|
||||
}
|
||||
//////////////////////////////////////////////////////////////////Image
|
||||
|
||||
return \MessageResponse::success(null,trans('messages.update'));
|
||||
}
|
||||
|
||||
public function destroy(TestResult $TestResult)
|
||||
{
|
||||
if (auth('api')->user()->can('delete', $TestResult)) {
|
||||
return \MessageResponse::error(trans('messages.failed'));
|
||||
if (!auth('api')->user()->can('delete', $TestResult)) {
|
||||
return \MessageResponse::error(trans('messages.access_denied'));
|
||||
}
|
||||
$TestResult->delete();
|
||||
return \MessageResponse::success(null, trans('messages.failed'));
|
||||
return \MessageResponse::success(null, trans('messages.success'));
|
||||
}
|
||||
|
||||
public function verifyTestResult(TestResult $TestResult)
|
||||
{
|
||||
if (auth('api')->user()->can('verifyTestResult', $TestResult)) {
|
||||
return \MessageResponse::error(trans('messages.failed'));
|
||||
if (!auth('api')->user()->can('verifyTestResult', $TestResult)) {
|
||||
return \MessageResponse::error(trans('messages.access_denied'));
|
||||
}
|
||||
if ($TestResult->verified == 'Verified') {
|
||||
$TestResult->verified = 'NotVerified';
|
||||
@@ -225,7 +299,7 @@ class TestResultController extends Controller
|
||||
$TestResult->verified = 'Verified';
|
||||
}
|
||||
$TestResult->save();
|
||||
return \MessageResponse::data($TestResult);
|
||||
return \MessageResponse::success(trans('messages.success'));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user