mirror of
https://git.meshkee.com/cssd/cssd-back.git
synced 2026-10-11 23:21:05 +03:30
Structor CSSD
This commit is contained in:
@@ -1,10 +0,0 @@
|
||||
<?php
|
||||
namespace App\Appended\Classes\Common\Response\Facades;
|
||||
|
||||
use Illuminate\Support\Facades\Facade;
|
||||
|
||||
class MessageResponse extends Facade {
|
||||
|
||||
protected static function getFacadeAccessor() { return 'messages'; }
|
||||
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Appended\Classes\Common\Response;
|
||||
|
||||
class MessageResponse
|
||||
{
|
||||
public function view($view = null, $data = null)
|
||||
{
|
||||
return response()->json(['data' => $data, 'view' => $view], 200);
|
||||
}
|
||||
|
||||
public function success($message = null, $title = null, $status = 'Success' , $data = null , $view = null )
|
||||
{
|
||||
$message = isset($message) ? $message : trans('messages.success_title');
|
||||
$title = isset($title) ? $title : trans('messages.success');
|
||||
return response()->json(['status' => $status, 'message' => $message, 'title' => $title, 'data' => $data, 'view' => $view], 200);
|
||||
}
|
||||
|
||||
public function error($message = null, $title = null, $status = 'Faild', $statusCode = 422 )
|
||||
{
|
||||
$message = isset($message) ? $message : trans('messages.faild_message');
|
||||
$title = isset($title) ? $title : trans('messages.faild');
|
||||
return response()->json(['status' => $status, 'errors' => ['message' => [$message, 'Title' => $title]]], $statusCode);
|
||||
}
|
||||
}
|
||||
@@ -1,121 +0,0 @@
|
||||
<?php
|
||||
namespace App\Appended\Traites\Auth;
|
||||
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Mail\RegistrationMailer;
|
||||
use App\Jobs\SendVerificationSMS;
|
||||
|
||||
|
||||
trait Verification
|
||||
{
|
||||
|
||||
private function setVerified($user_id, $verification)
|
||||
{
|
||||
$verify_number = $verification === 'email' ? 1 : 2;
|
||||
$user = is_numeric($user_id) ? \App\User::select('id', 'verified')->findOrFail($user_id) : $user_id;
|
||||
$user->verified = $user->verified | $verify_number;
|
||||
$user->save();
|
||||
return $user;
|
||||
}
|
||||
|
||||
/**
|
||||
*--------------------------------------------------------------------------
|
||||
* farid saravi
|
||||
* This function checks confirmation email and set user in the database as verified. lsb
|
||||
*--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
public function confirm($token)
|
||||
{
|
||||
$user_id = Cache::pull($token);
|
||||
if ($user_id) {
|
||||
$user = $this->setVerified($user_id, 'email');
|
||||
if (! \Auth::check()) {
|
||||
$this->guard()->login($user);
|
||||
}
|
||||
}
|
||||
return redirect('/');
|
||||
}
|
||||
|
||||
/**
|
||||
*--------------------------------------------------------------------------
|
||||
* farid saravi
|
||||
* This function checks confirmation sms and set user in the database as verified sms. msb
|
||||
*--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
public function confirm_phone(Request $request)
|
||||
{
|
||||
$user_id = Cache::pull('phone_number_' . $request->number);
|
||||
if ($user_id)
|
||||
{
|
||||
$user = $this->setVerified($user_id, 'phone_number');
|
||||
if (! \Auth::check())
|
||||
{
|
||||
$this->guard()->login($user);
|
||||
}
|
||||
return response()->json(['status' => 'success']);
|
||||
}
|
||||
return response()->json(['status' => 'fail'], 422);
|
||||
}
|
||||
|
||||
/**
|
||||
*--------------------------------------------------------------------------
|
||||
* farid saravi
|
||||
* This function sends confirmation email to a user.
|
||||
* @param \App\User
|
||||
* @return void
|
||||
*--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
public function mail_confirmation($user, $Type=null)
|
||||
{
|
||||
$Type = ($Type == null) ? 'VerifyUser' : $Type;
|
||||
$email_token = str_random(30);
|
||||
Cache::put($email_token, $user->id, Carbon::now()->addDays(2));
|
||||
Mail::to($user->email)->send(new RegistrationMailer($user, $email_token, $Type));
|
||||
}
|
||||
|
||||
/**
|
||||
*--------------------------------------------------------------------------
|
||||
* farid saravi
|
||||
* This function sends confirmation sms to a user.
|
||||
* @param \App\User
|
||||
* @return void
|
||||
*--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
public function phone_confirmation($user)
|
||||
{
|
||||
$rand_number = rand(100000, 999999);
|
||||
Cache::put('phone_number_' . $rand_number, $user->id, 60);
|
||||
if( $user->cell_number != '' && $user->cell_number != null ) {
|
||||
$MessageText = ' کد فعالسازی شما :'. $rand_number;
|
||||
$this->sendSMS($user->cell_number, $MessageText);
|
||||
}
|
||||
}
|
||||
|
||||
protected function sendSMS($phone_number, $message)
|
||||
{
|
||||
$options = array(
|
||||
'login' => 'hs-harmony-istore',
|
||||
'password' => 'WillaSMS47CD47'
|
||||
);
|
||||
$client = new \SoapClient('http://sms.sms-bartar.com/webservice/?WSDL', $options);
|
||||
|
||||
try {
|
||||
$messageId = $client->send($phone_number, $message);
|
||||
|
||||
} catch (SoapFault $sf) {
|
||||
|
||||
print $sf->faultcode . "\n";
|
||||
print $sf->faultstring . "\n";
|
||||
|
||||
return ['code' => $sf->faultcode, 'message' => $sf->faultstring];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,49 +1,49 @@
|
||||
<?php
|
||||
namespace App\Http\Controllers\Auth;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Transformers\Json;
|
||||
use App\User;
|
||||
use Illuminate\Foundation\Auth\SendsPasswordResetEmails;
|
||||
use Illuminate\Http\Request;
|
||||
class ForgotPasswordController extends Controller
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Password Reset Controller
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This controller is responsible for handling password reset emails and
|
||||
| includes a trait which assists in sending these notifications from
|
||||
| your application to your users. Feel free to explore this trait.
|
||||
|
|
||||
*/
|
||||
use SendsPasswordResetEmails;
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('guest');
|
||||
}
|
||||
/**
|
||||
* Send a reset link to the given user.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function getResetToken(Request $request)
|
||||
{
|
||||
dd($request->all());
|
||||
$this->validate($request, ['email' => 'required|email']);
|
||||
if ($request->wantsJson()) {
|
||||
$user = User::where('email', $request->input('email'))->first();
|
||||
if (!$user) {
|
||||
return response()->json(Json::response(null, trans('passwords.user')), 400);
|
||||
}
|
||||
$token = $this->broker()->createToken($user);
|
||||
return response()->json(Json::response(['token' => $token]));
|
||||
}
|
||||
}
|
||||
}
|
||||
<?php␍
|
||||
namespace App\Http\Controllers\Auth;␍
|
||||
use App\Http\Controllers\Controller;␍
|
||||
use App\Transformers\Json;␍
|
||||
use App\User;␍
|
||||
use Illuminate\Foundation\Auth\SendsPasswordResetEmails;␍
|
||||
use Illuminate\Http\Request;␍
|
||||
class ForgotPasswordController extends Controller␍
|
||||
{␍
|
||||
/*␍
|
||||
|--------------------------------------------------------------------------␍
|
||||
| Password Reset Controller␍
|
||||
|--------------------------------------------------------------------------␍
|
||||
|␍
|
||||
| This controller is responsible for handling password reset emails and␍
|
||||
| includes a trait which assists in sending these notifications from␍
|
||||
| your application to your users. Feel free to explore this trait.␍
|
||||
|␍
|
||||
*/␍
|
||||
use SendsPasswordResetEmails;␍
|
||||
/**␍
|
||||
* Create a new controller instance.␍
|
||||
*␍
|
||||
* @return void␍
|
||||
*/␍
|
||||
public function __construct()␍
|
||||
{␍
|
||||
$this->middleware('guest');␍
|
||||
}␍
|
||||
/**␍
|
||||
* Send a reset link to the given user.␍
|
||||
*␍
|
||||
* @param \Illuminate\Http\Request $request␍
|
||||
* @return \Illuminate\Http\Response␍
|
||||
*/␍
|
||||
public function getResetToken(Request $request)␍
|
||||
{␍
|
||||
dd($request->all());␍
|
||||
$this->validate($request, ['email' => 'required|email']);␍
|
||||
if ($request->wantsJson()) {␍
|
||||
$user = User::where('email', $request->input('email'))->first();␍
|
||||
if (!$user) {␍
|
||||
return response()->json(Json::response(null, trans('passwords.user')), 400);␍
|
||||
}␍
|
||||
$token = $this->broker()->createToken($user);␍
|
||||
return response()->json(Json::response(['token' => $token]));␍
|
||||
}␍
|
||||
}␍
|
||||
}␍
|
||||
|
||||
@@ -1,61 +1,61 @@
|
||||
<?php
|
||||
namespace App\Http\Controllers\Auth;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Transformers\Json;
|
||||
use Illuminate\Foundation\Auth\ResetsPasswords;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Password;
|
||||
class ResetPasswordController extends Controller
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Password Reset Controller
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This controller is responsible for handling password reset requests
|
||||
| and uses a simple trait to include this behavior. You're free to
|
||||
| explore this trait and override any methods you wish to tweak.
|
||||
|
|
||||
*/
|
||||
use ResetsPasswords;
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('guest');
|
||||
}
|
||||
/**
|
||||
* Reset the given user's password.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function reset(Request $request)
|
||||
{
|
||||
$this->validate($request, $this->rules(), $this->validationErrorMessages());
|
||||
// Here we will attempt to reset the user's password. If it is successful we
|
||||
// will update the password on an actual user model and persist it to the
|
||||
// database. Otherwise we will parse the error and return the response.
|
||||
$response = $this->broker()->reset(
|
||||
$this->credentials($request), function ($user, $password) {
|
||||
$this->resetPassword($user, $password);
|
||||
}
|
||||
);
|
||||
if ($request->wantsJson()) {
|
||||
if ($response == Password::PASSWORD_RESET) {
|
||||
return response()->json(Json::response(null, trans('passwords.reset')));
|
||||
} else {
|
||||
return response()->json(Json::response($request->input('email'), trans($response), 202));
|
||||
}
|
||||
}
|
||||
// If the password was successfully reset, we will redirect the user back to
|
||||
// the application's home authenticated view. If there is an error we can
|
||||
// redirect them back to where they came from with their error message.
|
||||
return $response == Password::PASSWORD_RESET
|
||||
? $this->sendResetResponse($response)
|
||||
: $this->sendResetFailedResponse($request, $response);
|
||||
}
|
||||
}
|
||||
<?php␍
|
||||
namespace App\Http\Controllers\Auth;␍
|
||||
use App\Http\Controllers\Controller;␍
|
||||
use App\Transformers\Json;␍
|
||||
use Illuminate\Foundation\Auth\ResetsPasswords;␍
|
||||
use Illuminate\Http\Request;␍
|
||||
use Illuminate\Support\Facades\Password;␍
|
||||
class ResetPasswordController extends Controller␍
|
||||
{␍
|
||||
/*␍
|
||||
|--------------------------------------------------------------------------␍
|
||||
| Password Reset Controller␍
|
||||
|--------------------------------------------------------------------------␍
|
||||
|␍
|
||||
| This controller is responsible for handling password reset requests␍
|
||||
| and uses a simple trait to include this behavior. You're free to␍
|
||||
| explore this trait and override any methods you wish to tweak.␍
|
||||
|␍
|
||||
*/␍
|
||||
use ResetsPasswords;␍
|
||||
/**␍
|
||||
* Create a new controller instance.␍
|
||||
*␍
|
||||
* @return void␍
|
||||
*/␍
|
||||
public function __construct()␍
|
||||
{␍
|
||||
$this->middleware('guest');␍
|
||||
}␍
|
||||
/**␍
|
||||
* Reset the given user's password.␍
|
||||
*␍
|
||||
* @param \Illuminate\Http\Request $request␍
|
||||
* @return \Illuminate\Http\Response␍
|
||||
*/␍
|
||||
public function reset(Request $request)␍
|
||||
{␍
|
||||
$this->validate($request, $this->rules(), $this->validationErrorMessages());␍
|
||||
// Here we will attempt to reset the user's password. If it is successful we␍
|
||||
// will update the password on an actual user model and persist it to the␍
|
||||
// database. Otherwise we will parse the error and return the response.␍
|
||||
$response = $this->broker()->reset(␍
|
||||
$this->credentials($request), function ($user, $password) {␍
|
||||
$this->resetPassword($user, $password);␍
|
||||
}␍
|
||||
);␍
|
||||
if ($request->wantsJson()) {␍
|
||||
if ($response == Password::PASSWORD_RESET) {␍
|
||||
return response()->json(Json::response(null, trans('passwords.reset')));␍
|
||||
} else {␍
|
||||
return response()->json(Json::response($request->input('email'), trans($response), 202));␍
|
||||
}␍
|
||||
}␍
|
||||
// If the password was successfully reset, we will redirect the user back to␍
|
||||
// the application's home authenticated view. If there is an error we can␍
|
||||
// redirect them back to where they came from with their error message.␍
|
||||
return $response == Password::PASSWORD_RESET␍
|
||||
? $this->sendResetResponse($response)␍
|
||||
: $this->sendResetFailedResponse($request, $response);␍
|
||||
}␍
|
||||
}␍
|
||||
|
||||
@@ -12,7 +12,7 @@ class MedicalCenterController extends Controller
|
||||
public function index()
|
||||
{
|
||||
$MedicalCenters = MedicalCenter::withCount('users')->paginate(10);
|
||||
return response()->json(['MedicalCenters' => $MedicalCenters]);
|
||||
return \MessageResponse::data($MedicalCenters);
|
||||
}
|
||||
|
||||
public function create()
|
||||
@@ -22,7 +22,7 @@ class MedicalCenterController extends Controller
|
||||
|
||||
public function store(StoreMedicalCenterRequest $request)
|
||||
{
|
||||
$MedicalCenter = MedicalCenter::create($request->all());
|
||||
MedicalCenter::create($request->all());
|
||||
return response()->json(trans('messages.success'));
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ class TestResultController extends Controller
|
||||
//
|
||||
}
|
||||
|
||||
public function CreateChildFormValue($InputChild,$TestResultObj,$TestResultInfo)
|
||||
public function CreateChildFormValue2($InputChild,$TestResultObj,$TestResultInfo)
|
||||
{
|
||||
// dd($TestResultInfo[$InputChild->name]);
|
||||
// foreach ($Input->children as $InputChild) {
|
||||
@@ -40,6 +40,34 @@ class TestResultController extends Controller
|
||||
$InputValueObj = InputValue::create(['test_result_id' => $TestResultObj->id , 'input_id' => $InputChild['id'] , 'value' => $Value]);
|
||||
// dd(['test_result_id' => $TestResultObj->id , 'input_id' => $InputChild['id'] , 'value' => $Value]);
|
||||
// }
|
||||
}
|
||||
public function CreateChildFormValue($Input,$TestResultObj,$TestResultInfo)
|
||||
{
|
||||
// dd($Input->children[0]->children);
|
||||
// if ($Input->type == 'Form') {
|
||||
// code...
|
||||
|
||||
// $TestResultInfo = $TestResultInfo[$Input->name];
|
||||
foreach ($Input->children as $InputChild) {
|
||||
|
||||
// $TestResultInfo = $TestResultInfo[$InputChild->name];
|
||||
|
||||
if ($InputChild->type == 'Form') {
|
||||
|
||||
// dd($TestResultInfo[$InputChild->name]);
|
||||
$this->CreateChildFormValue($InputChild,$TestResultObj,$TestResultInfo[$InputChild->name]);
|
||||
// dd($InputChild);
|
||||
}
|
||||
else {
|
||||
$Value = $TestResultInfo[$InputChild->name];
|
||||
// dd($Value);
|
||||
$InputValueObj = InputValue::create(['test_result_id' => $TestResultObj->id , 'input_id' => $InputChild['id'] , 'value' => $Value ]);
|
||||
}
|
||||
|
||||
}
|
||||
return 'success';
|
||||
|
||||
|
||||
}
|
||||
public function store(StoreTestResultRequest $request)
|
||||
{
|
||||
@@ -57,39 +85,77 @@ class TestResultController extends Controller
|
||||
// $TestResultInfo = $request['info'];
|
||||
$TestResultInfo = [];
|
||||
|
||||
$Inputs = Input::with('options','children')->where('test_type_id',$request->test_type_id)->get();
|
||||
$Inputs = Input::with('options','children','children.children')->where('test_type_id',$request->test_type_id)->get();
|
||||
// dd($Inputs->toArray()[2]);
|
||||
// foreach ($Inputs as $Input) {
|
||||
// if ($Input['type'] == 'Form') {
|
||||
// $TestResultInfo = $request[$Input->name];
|
||||
//
|
||||
// // $this->CreateChildFormValue($Input,$TestResultObj,$TestResultInfo);
|
||||
//
|
||||
// ///--------------------------------------------------
|
||||
// foreach ($Input->children as $InputChild) {
|
||||
//
|
||||
// $this->CreateChildFormValue($InputChild,$TestResultObj,$TestResultInfo);
|
||||
// ///--------------------------------------------------
|
||||
// // $Value = $TestResultInfo[$InputChild->name];
|
||||
// //
|
||||
// // if ($InputChild->type == 'Form') {
|
||||
// // foreach ($InputChild->children as $InputChild2) {
|
||||
// // $Value = $TestResultInfo[$InputChild->name][$InputChild2->name];
|
||||
// // $InputValueObj = InputValue::create(['test_result_id' => $TestResultObj->id , 'input_id' => $InputChild2['id'] , 'value' => $Value]);
|
||||
// // return 'success';
|
||||
// // }
|
||||
// //
|
||||
// // }
|
||||
// // $InputValueObj = InputValue::create(['test_result_id' => $TestResultObj->id , 'input_id' => $InputChild['id'] , 'value' => $Value]);
|
||||
// }
|
||||
// ///--------------------------------------------------
|
||||
// }
|
||||
// else {
|
||||
// $TestResultInfo = $request->all();
|
||||
// }
|
||||
// $Value = $TestResultInfo[$Input->name];
|
||||
// $InputValueObj = InputValue::create(['test_result_id' => $TestResultObj->id , 'input_id' => $Input->id , 'value' => $Value]);
|
||||
// }
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
foreach ($Inputs as $Input) {
|
||||
if ($Input['type'] == 'Form') {
|
||||
$TestResultInfo = $request[$Input->name];
|
||||
$TestResultInfo = $request[$Input->name];//-----estesna
|
||||
|
||||
// $this->CreateChildFormValue($Input,$TestResultObj,$TestResultInfo);
|
||||
|
||||
$this->CreateChildFormValue($Input,$TestResultObj,$TestResultInfo);
|
||||
|
||||
//******
|
||||
///--------------------------------------------------
|
||||
foreach ($Input->children as $InputChild) {
|
||||
|
||||
$this->CreateChildFormValue($InputChild,$TestResultObj,$TestResultInfo);
|
||||
///--------------------------------------------------
|
||||
// $Value = $TestResultInfo[$InputChild->name];
|
||||
//
|
||||
// if ($InputChild->type == 'Form') {
|
||||
// foreach ($InputChild->children as $InputChild2) {
|
||||
// $Value = $TestResultInfo[$InputChild->name][$InputChild2->name];
|
||||
// $InputValueObj = InputValue::create(['test_result_id' => $TestResultObj->id , 'input_id' => $InputChild2['id'] , 'value' => $Value]);
|
||||
// return 'success';
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// $InputValueObj = InputValue::create(['test_result_id' => $TestResultObj->id , 'input_id' => $InputChild['id'] , 'value' => $Value]);
|
||||
}
|
||||
// foreach ($Input->children as $InputChild) {
|
||||
//
|
||||
// $TestResultInfo = $TestResultInfo[$InputChild->name];
|
||||
// // dd($TestResultInfo);
|
||||
// if ($InputChild->type == 'Form') {
|
||||
// foreach ($InputChild->children as $InputChild2) {
|
||||
//
|
||||
// $Value = $TestResultInfo[$InputChild->name][$InputChild2->name];
|
||||
//
|
||||
// $InputValueObj = InputValue::create(['test_result_id' => $TestResultObj->id , 'input_id' => $InputChild2['id'] , 'value' => $Value]);
|
||||
// return 'success';
|
||||
// }
|
||||
// }
|
||||
// $InputValueObj = InputValue::create(['test_result_id' => $TestResultObj->id , 'input_id' => $InputChild['id'] , 'value' => $Value]);
|
||||
// }
|
||||
///--------------------------------------------------
|
||||
}
|
||||
else {
|
||||
$TestResultInfo = $request->all();
|
||||
// $TestResultInfo = $request->all();
|
||||
$Value = $request[$Input->name];
|
||||
// dd($Value);
|
||||
$InputValueObj = InputValue::create(['test_result_id' => $TestResultObj->id , 'input_id' => $Input->id , 'value' => $Value]);
|
||||
}
|
||||
$Value = $TestResultInfo[$Input->name];
|
||||
$InputValueObj = InputValue::create(['test_result_id' => $TestResultObj->id , 'input_id' => $Input->id , 'value' => $Value]);
|
||||
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
});
|
||||
} catch (\Exception $e) {
|
||||
|
||||
@@ -12,8 +12,8 @@ class TestTypeController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$TestTypes = TestType::paginate(10);
|
||||
return response()->json(['TestTypes' => $TestTypes, 'LastPage' => $TestTypes->lastPage()]);
|
||||
$TestTypes = TestType::with('user','user.medical_center')->paginate(10);
|
||||
return \MessageResponse::data($TestTypes);
|
||||
}
|
||||
|
||||
public function create()
|
||||
@@ -23,7 +23,7 @@ class TestTypeController extends Controller
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////// Add TestType /////////////////////////
|
||||
/////////////////////// Store TestType /////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -40,7 +40,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') {
|
||||
foreach ($Input['options'] as $Option) {
|
||||
$Option = Option::create(['title' => $Option['title'] , 'input_id' => $InputObj->id]);
|
||||
}
|
||||
@@ -86,7 +86,7 @@ class TestTypeController extends Controller
|
||||
} catch (\Exception $e) {
|
||||
return response()->json($e->getMessage(), 441);
|
||||
}
|
||||
return \MessageResponse::success();
|
||||
return \MessageResponse::success(null,trans('messages.create'));
|
||||
}
|
||||
|
||||
public function show($id)
|
||||
@@ -94,14 +94,105 @@ class TestTypeController extends Controller
|
||||
//
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$TestType = TestType::with('inputs','inputs.children','inputs.children.children','inputs.options')->findOrFail($id);//?????
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////// Edit TestType /////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// $TestType = TestType::where('id',$id)->with('inputs','inputs.children','inputs.children.children','inputs.options')->whereHas('inputs' , function($query){
|
||||
// $query->where('parent_id',null);
|
||||
// })->get();
|
||||
return response()->json(['TestType' => $TestType]);
|
||||
public function CreateInputInfo($Input)
|
||||
{
|
||||
//------------------------------------------------------Input
|
||||
$InputInfo = [
|
||||
'id' => $Input->id,
|
||||
'name' => $Input->name,
|
||||
'type' => $Input->type,
|
||||
'size' => $Input->size ,
|
||||
'parent_id' => $Input->parent_id,
|
||||
'options' => [],
|
||||
'children' => []
|
||||
];
|
||||
//------------------------------------------------------Input
|
||||
//------------------------------------------------------Option
|
||||
if ($Input['type'] == 'Checkbox' || $Input['type'] == 'Select') {
|
||||
|
||||
foreach ($Input['options'] as $Option) {
|
||||
$OptionInfo = [
|
||||
'id' => $Option->id ,
|
||||
'title' => $Option->title
|
||||
];
|
||||
$Options[] = $OptionInfo;
|
||||
}
|
||||
$InputInfo['options'] = $Options;
|
||||
}
|
||||
//------------------------------------------------------Option
|
||||
return $InputInfo;
|
||||
}
|
||||
// public function CreateChildFormInfo($Input,$InputInfo)
|
||||
// {
|
||||
// foreach ($Input['children'] as $InputChild) {
|
||||
//
|
||||
// $ChildInfo = $this->CreateInputInfo($InputChild);
|
||||
// $InputInfo['children'] = $ChildInfo;
|
||||
//
|
||||
// if ($InputChild['type'] == 'Form') {
|
||||
// return $this->CreateChildFormInfo($InputChild,$ChildInfo);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return $InputInfo;
|
||||
// }
|
||||
// public function CreateChildFormInfo($Input,$InputInfo)
|
||||
// {
|
||||
// foreach ($Input['children'] as $InputChild) {
|
||||
//
|
||||
// $InputInfo['children'] = $this->CreateInputInfo($InputChild);
|
||||
// $ChildInfo = $InputInfo['children'];
|
||||
// $Children[] = $ChildInfo;
|
||||
// if ($InputChild['type'] == 'Form') {
|
||||
// $ChildInfo['children'] = $this->CreateChildFormInfo($InputChild,$ChildInfo);
|
||||
// }
|
||||
// }
|
||||
// return $Children;
|
||||
// }
|
||||
public function CreateChildFormInfo($Input,$InputInfo)
|
||||
{
|
||||
foreach ($Input['children'] as $InputChild) {
|
||||
|
||||
$ChildInfo = $this->CreateInputInfo($InputChild);
|
||||
$Children[] = $ChildInfo;
|
||||
if ($InputChild['type'] == 'Form') {
|
||||
$this->CreateChildFormInfo($InputChild,$ChildInfo);
|
||||
}
|
||||
}
|
||||
return $Children;
|
||||
}
|
||||
|
||||
public function edit(TestType $TestType)
|
||||
{
|
||||
$Inputs = Input::with('children','options','children.options')->where('test_type_id',$TestType->id)->where('parent_id',null)->get();
|
||||
|
||||
$Info = [];
|
||||
$Options = [];
|
||||
$Children = [];
|
||||
|
||||
foreach ($Inputs as $Input) {
|
||||
|
||||
$InputInfo = $this->CreateInputInfo($Input);
|
||||
|
||||
if ($Input['type'] == 'Form') {
|
||||
$Children = $this->CreateChildFormInfo($Input,$InputInfo);
|
||||
$InputInfo['children'] = $Children;
|
||||
}
|
||||
$Info[] = $InputInfo;
|
||||
}
|
||||
$TestTypeInfo = [
|
||||
'id' => $TestType->id,
|
||||
'name' => $TestType->name,
|
||||
'unique_code' => $TestType->unique_code,
|
||||
'info' => $Info,
|
||||
];
|
||||
return \MessageResponse::data($TestTypeInfo);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -123,19 +214,19 @@ class TestTypeController extends Controller
|
||||
$InputObj = Input::where('id',$Input['id'])->update($InputData);
|
||||
//---------------------------------------------Input
|
||||
//---------------------------------------------Option
|
||||
if ($Input['type'] == 'CheckBox' || $Input['type'] == 'Select') {
|
||||
if ($Input['type'] == 'Checkbox' || $Input['type'] == 'Select') {
|
||||
foreach ($Input['options'] as $Option) {
|
||||
if ($Option['id'] == 0) {//--new
|
||||
$Option = Option::create(['title' => $Option['title'] , 'input_id' => $InputObj->id]);
|
||||
$Option = Option::create(['title' => $Option['title'] , 'input_id' => $Input['id'] ]);
|
||||
}
|
||||
else {
|
||||
$Option = Option::where('id', $Option['id'])->update(['title' => $Option['title'] ]);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//---------------------------------------------Option
|
||||
return $InputObj;
|
||||
// dd($Input);
|
||||
return $Input;
|
||||
|
||||
}
|
||||
public function UpdateChildForm($Input,$TestType,$InputObj)
|
||||
@@ -150,7 +241,8 @@ class TestTypeController extends Controller
|
||||
}
|
||||
}
|
||||
else {
|
||||
$InputChildObj = $this->UpdateInput($InputChild,$TestType,$InputObj->id);
|
||||
// dd($InputObj);
|
||||
$InputChildObj = $this->UpdateInput($InputChild,$TestType,$InputObj['id']);
|
||||
if (isset($InputChild['children'])) {
|
||||
$this->UpdateChildForm($InputChild,$TestType,$InputChildObj);
|
||||
}
|
||||
@@ -162,6 +254,7 @@ class TestTypeController extends Controller
|
||||
|
||||
public function update(StoreTestTypeRequest $request, TestType $TestType)
|
||||
{
|
||||
// dd($request->all());
|
||||
$TestTypeData = [
|
||||
'name' => $request['name'],
|
||||
'unique_code' => $request['unique_code'],
|
||||
@@ -175,11 +268,13 @@ class TestTypeController extends Controller
|
||||
}
|
||||
else {
|
||||
$InputObj = $this->UpdateInput($Input,$TestType);
|
||||
// dd($InputObj);
|
||||
}
|
||||
if ($Input->Type == 'Form') {
|
||||
if ($Input['type'] == 'Form') {
|
||||
$this->UpdateChildForm($Input,$TestType,$InputObj);
|
||||
}
|
||||
}
|
||||
return \MessageResponse::success(null,trans('messages.update'));
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
|
||||
@@ -1,66 +1,83 @@
|
||||
<?php
|
||||
|
||||
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
use App\Http\Requests\StoreUserRequest;
|
||||
use App\User;
|
||||
use App\MedicalCenter;
|
||||
use App\User;
|
||||
|
||||
|
||||
|
||||
class UserController extends Controller
|
||||
|
||||
{
|
||||
public function index(Request $request)
|
||||
|
||||
public function index()
|
||||
{
|
||||
$Users = User::where('medicalcenter', $request->medical_center_id)->paginate(10);
|
||||
return response()->json(['Users' => $Users, 'LastPage' => $Users->lastPage()]);
|
||||
$Users = User::with(['medical_center', 'roles'])->paginate(10);
|
||||
return \MessageResponse::data($Users);
|
||||
}
|
||||
|
||||
public function store(StoreUserRequest $request)
|
||||
{
|
||||
$UserData = [
|
||||
'name' => $request->name,
|
||||
'cell_number' => $request->cell_number,
|
||||
'medical_center_id' => $request->medical_center_id,
|
||||
'name' => $request->name ,
|
||||
'cell_number' => $request->cell_number ,
|
||||
'medical_center_id' => $request->medical_center_id ,
|
||||
'status' => 'PreRegister',
|
||||
'verified' => 1,
|
||||
'password' => bcrypt($request->password),
|
||||
];
|
||||
$User = User::create($UserData);
|
||||
|
||||
return response()->json(trans('messages.success'));
|
||||
return \MessageResponse::success(trans('messages.success'));
|
||||
}
|
||||
|
||||
public function edit(User $User)
|
||||
{
|
||||
return response()->json(['User' => $User]);
|
||||
return \MessageResponse::data($User);
|
||||
}
|
||||
|
||||
public function update(StoreUserRequest $request, User $User)
|
||||
{
|
||||
$UserData = [
|
||||
'name' => $request->name,
|
||||
'cell_number' => $request->cell_number,
|
||||
'medical_center_id' => $request->medical_center_id,
|
||||
'name' => $request->name ,
|
||||
'cell_number' => $request->cell_number ,
|
||||
'medical_center_id' => $request->medical_center_id ,
|
||||
'status' => 'PreRegister',
|
||||
'verified' => 1,
|
||||
'password' => bcrypt($request->password),
|
||||
];
|
||||
$User->update($UserData);
|
||||
return response()->json(trans('messages.success'));
|
||||
return \MessageResponse::success(trans('messages.success'));
|
||||
}
|
||||
|
||||
public function destroy(User $User)
|
||||
{
|
||||
if (auth('api')->user()->can('delete', $User)) {
|
||||
return response()->json(trans('messages.failed'));
|
||||
return \MessageResponse::error(trans('messages.failed'));
|
||||
}
|
||||
$User->delete(); //?????????????????
|
||||
$User->delete();
|
||||
return \MessageResponse::success(trans('messages.success'));
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function getByMedicalCenter(MedicalCenter $MedicalCenter)
|
||||
{
|
||||
$MedicalCenter = $MedicalCenter->load(['users' => function ($query) {
|
||||
return $query->select(['id', 'medical_center_id', 'name', 'cell_number', 'status']);
|
||||
}, 'users.roles']);
|
||||
return response()->json($MedicalCenter, 200);
|
||||
return \MessageResponse::data($MedicalCenter);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function changeStatus(User $User)
|
||||
{
|
||||
if ($User->status == 'Active') {
|
||||
@@ -69,18 +86,26 @@ class UserController extends Controller
|
||||
$User->status = 'Active';
|
||||
}
|
||||
$User->save();
|
||||
return response()->json($User, 200);
|
||||
return \MessageResponse::data($User);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function changeRole(User $User, Request $request)
|
||||
{
|
||||
$User->syncRoles($request->roles);
|
||||
return response()->json($User, 200);
|
||||
return \MessageResponse::data($User);
|
||||
}
|
||||
|
||||
public function updateInfo(Request $request)
|
||||
{
|
||||
auth('api')->user()->update($request->all());
|
||||
return response()->json(['user' => auth('api')->user()], 200);
|
||||
return \MessageResponse::success(trans('messages.success'));
|
||||
}
|
||||
|
||||
public function getInfo()
|
||||
{
|
||||
return \MessageResponse::data([ 'user' => auth('api')->user(), 'roles' => auth('api')->user()->getRoleNames() ]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,30 +1,30 @@
|
||||
<?php // /app/Http/Middleware/Cors.php
|
||||
namespace App\Http\Middleware;
|
||||
use Closure;
|
||||
class Cors {
|
||||
|
||||
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
/* @var $response Response */
|
||||
$response = $next($request)
|
||||
->header('Access-Control-Allow-Origin', '*')
|
||||
->header('Access-Control-Allow-credentials', true)
|
||||
->header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
|
||||
if (!$request->isMethod('OPTIONS')) {
|
||||
return $response;
|
||||
}
|
||||
$allow = $response->headers->get('Allow'); // true list of allowed methods
|
||||
if (!$allow) {
|
||||
return $response;
|
||||
}
|
||||
$headers = [
|
||||
'Access-Control-Allow-Methods' => $allow,
|
||||
'Access-Control-Max-Age' => 3600,
|
||||
'Access-Control-Allow-Headers' => 'X-Requested-With, Origin, X-Csrftoken, Content-Type, Accept',
|
||||
];
|
||||
return $response->withHeaders($headers);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
<?php // /app/Http/Middleware/Cors.php␍
|
||||
namespace App\Http\Middleware;␍
|
||||
use Closure;␍
|
||||
class Cors {␍
|
||||
␍
|
||||
␍
|
||||
public function handle($request, Closure $next)␍
|
||||
{␍
|
||||
/* @var $response Response */␍
|
||||
$response = $next($request)␍
|
||||
->header('Access-Control-Allow-Origin', '*')␍
|
||||
->header('Access-Control-Allow-credentials', true)␍
|
||||
->header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');␍
|
||||
if (!$request->isMethod('OPTIONS')) {␍
|
||||
return $response;␍
|
||||
}␍
|
||||
$allow = $response->headers->get('Allow'); // true list of allowed methods␍
|
||||
if (!$allow) {␍
|
||||
return $response;␍
|
||||
}␍
|
||||
$headers = [␍
|
||||
'Access-Control-Allow-Methods' => $allow,␍
|
||||
'Access-Control-Max-Age' => 3600,␍
|
||||
'Access-Control-Allow-Headers' => 'X-Requested-With, Origin, X-Csrftoken, Content-Type, Accept',␍
|
||||
];␍
|
||||
return $response->withHeaders($headers);␍
|
||||
}␍
|
||||
␍
|
||||
␍
|
||||
}␍
|
||||
|
||||
@@ -1,53 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use App\MedicalCenter;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Contracts\Validation\Validator;
|
||||
|
||||
|
||||
class StoreMedicalCenterRequest extends FormRequest
|
||||
{
|
||||
public function authorize()
|
||||
{
|
||||
if ($this->method() == 'POST') {
|
||||
return auth('api')->check() && auth('api')->user()->can('store', MedicalCenter::class);
|
||||
} else {
|
||||
$MedicalCenter = $this->route('MedicalCenter');
|
||||
return auth('api')->check() && $MedicalCenter && auth('api')->user()->can('update', $MedicalCenter);
|
||||
}
|
||||
}
|
||||
|
||||
public function rules()
|
||||
{
|
||||
switch ($this->method()) {
|
||||
case 'POST': {
|
||||
return [
|
||||
'name' => 'required|max:100|unique:medical_centers',
|
||||
// 'operatores.*.name'=>'required|string|max:255',
|
||||
// 'operatores.*.cell_number'=>'required|digits_between:10,11|unique:users',
|
||||
// 'operatores.*.password'=>'required|string|min:6',
|
||||
];
|
||||
break;
|
||||
}
|
||||
case 'PUT':
|
||||
case 'PATCH': {
|
||||
$MedicalCenter = $this->route('MedicalCenter');
|
||||
return [
|
||||
'name' => 'required|max:100|unique:medical_centers,id,'.$MedicalCenter->id,
|
||||
// 'operatores.*.name'=>'required|string|max:255',
|
||||
// 'operatores.*.cell_number'=>'required|digits_between:10,11|unique:users',
|
||||
// 'operatores.*.password'=>'required|string|min:6',
|
||||
];
|
||||
break;
|
||||
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
<?php␍
|
||||
␍
|
||||
namespace App\Http\Requests;␍
|
||||
␍
|
||||
use App\MedicalCenter;␍
|
||||
use Illuminate\Validation\Rule;␍
|
||||
use Illuminate\Foundation\Http\FormRequest;␍
|
||||
use Illuminate\Contracts\Validation\Validator;␍
|
||||
␍
|
||||
␍
|
||||
class StoreMedicalCenterRequest extends FormRequest␍
|
||||
{␍
|
||||
public function authorize()␍
|
||||
{␍
|
||||
if ($this->method() == 'POST') {␍
|
||||
return auth('api')->check() && auth('api')->user()->can('store', MedicalCenter::class);␍
|
||||
} else {␍
|
||||
$MedicalCenter = $this->route('MedicalCenter');␍
|
||||
return auth('api')->check() && $MedicalCenter && auth('api')->user()->can('update', $MedicalCenter);␍
|
||||
}␍
|
||||
}␍
|
||||
␍
|
||||
public function rules()␍
|
||||
{␍
|
||||
switch ($this->method()) {␍
|
||||
case 'POST': {␍
|
||||
return [␍
|
||||
'name' => 'required|max:100|unique:medical_centers',␍
|
||||
// 'operatores.*.name'=>'required|string|max:255',␍
|
||||
// 'operatores.*.cell_number'=>'required|digits_between:10,11|unique:users',␍
|
||||
// 'operatores.*.password'=>'required|string|min:6',␍
|
||||
];␍
|
||||
break;␍
|
||||
}␍
|
||||
case 'PUT':␍
|
||||
case 'PATCH': {␍
|
||||
$MedicalCenter = $this->route('MedicalCenter');␍
|
||||
return [␍
|
||||
'name' => 'required|max:100|unique:medical_centers,id,'.$MedicalCenter->id,␍
|
||||
// 'operatores.*.name'=>'required|string|max:255',␍
|
||||
// 'operatores.*.cell_number'=>'required|digits_between:10,11|unique:users',␍
|
||||
// 'operatores.*.password'=>'required|string|min:6',␍
|
||||
];␍
|
||||
break;␍
|
||||
␍
|
||||
}␍
|
||||
default:␍
|
||||
break;␍
|
||||
}␍
|
||||
␍
|
||||
}␍
|
||||
␍
|
||||
}␍
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php␍
|
||||
␍
|
||||
namespace App\Http\Requests;␍
|
||||
␍
|
||||
use App\TestResult;␍
|
||||
use Illuminate\Validation\Rule;␍
|
||||
use Illuminate\Foundation\Http\FormRequest;␍
|
||||
use Illuminate\Contracts\Validation\Validator;␍
|
||||
␍
|
||||
␍
|
||||
class StoreTestResultRequest extends FormRequest␍
|
||||
{␍
|
||||
public function authorize()␍
|
||||
{␍
|
||||
if ($this->method() == 'POST') {␍
|
||||
return auth('api')->check() && auth('api')->user()->can('store', TestResult::class);␍
|
||||
} else {␍
|
||||
$TestResult = $this->route('TestResult');␍
|
||||
return auth('api')->check() && $TestResult && auth('api')->user()->can('update', $TestResult);␍
|
||||
}␍
|
||||
}␍
|
||||
␍
|
||||
public function rules()␍
|
||||
{␍
|
||||
switch ($this->method()) {␍
|
||||
case 'POST': {␍
|
||||
return [␍
|
||||
// 'user_id' => 'required',␍
|
||||
'autoclave_id' => '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;␍
|
||||
}␍
|
||||
case 'PUT':␍
|
||||
case 'PATCH': {␍
|
||||
// $TestResult = $this->route('TestResult');␍
|
||||
return [␍
|
||||
// 'user_id' => 'required',␍
|
||||
'autoclave_id' => '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;␍
|
||||
␍
|
||||
}␍
|
||||
default:␍
|
||||
break;␍
|
||||
}␍
|
||||
␍
|
||||
}␍
|
||||
␍
|
||||
}␍
|
||||
@@ -1,57 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use App\TestType;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Contracts\Validation\Validator;
|
||||
|
||||
|
||||
class StoreTestTypeRequest extends FormRequest
|
||||
{
|
||||
public function authorize()
|
||||
{
|
||||
if ($this->method() == 'POST') {
|
||||
return auth('api')->check() && auth('api')->user()->can('store', TestType::class);
|
||||
} else {
|
||||
$TestType = $this->route('TestType');
|
||||
return auth('api')->check() && $TestType && auth('api')->user()->can('update', $TestType);
|
||||
}
|
||||
}
|
||||
|
||||
public function rules()
|
||||
{
|
||||
switch ($this->method()) {
|
||||
case 'POST': {
|
||||
return [
|
||||
'name' => 'required|max:100|unique:test_types',
|
||||
'unique_code' => 'required|max:100|unique:test_types',
|
||||
'info.*.name'=>'required',
|
||||
'info.*.type'=>'required',
|
||||
'info.*.size'=>'required',
|
||||
'info.*.parent_id'=>'nullable|numeric|exists:inputs,id',
|
||||
];
|
||||
break;
|
||||
}
|
||||
case 'PUT':
|
||||
case 'PATCH': {
|
||||
$TestType = $this->route('TestType');
|
||||
return [
|
||||
'name' => 'required|max:100|unique:test_types,id,'.$TestType->id,
|
||||
'unique_code' => 'required|max:100|unique:test_types,id,'.$TestType->id,
|
||||
'info.*.name'=>'required',
|
||||
'info.*.type'=>'required',
|
||||
'info.*.size'=>'required',
|
||||
'info.*.parent_id'=>'nullable|numeric|exists:inputs,id',
|
||||
];
|
||||
break;
|
||||
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
<?php␍
|
||||
␍
|
||||
namespace App\Http\Requests;␍
|
||||
␍
|
||||
use App\TestType;␍
|
||||
use Illuminate\Validation\Rule;␍
|
||||
use Illuminate\Foundation\Http\FormRequest;␍
|
||||
use Illuminate\Contracts\Validation\Validator;␍
|
||||
␍
|
||||
␍
|
||||
class StoreTestTypeRequest extends FormRequest␍
|
||||
{␍
|
||||
public function authorize()␍
|
||||
{␍
|
||||
if ($this->method() == 'POST') {␍
|
||||
return auth('api')->check() && auth('api')->user()->can('store', TestType::class);␍
|
||||
} else {␍
|
||||
$TestType = $this->route('TestType');␍
|
||||
return auth('api')->check() && $TestType && auth('api')->user()->can('update', $TestType);␍
|
||||
}␍
|
||||
}␍
|
||||
␍
|
||||
public function rules()␍
|
||||
{␍
|
||||
switch ($this->method()) {␍
|
||||
case 'POST': {␍
|
||||
return [␍
|
||||
'name' => 'required|max:100|unique:test_types',␍
|
||||
'unique_code' => 'required|max:100|unique:test_types',␍
|
||||
'info.*.name'=>'required',␍
|
||||
'info.*.type'=>'required',␍
|
||||
'info.*.size'=>'nullable',␍
|
||||
'info.*.parent_id'=>'nullable|numeric|exists:inputs,id',␍
|
||||
];␍
|
||||
break;␍
|
||||
}␍
|
||||
case 'PUT':␍
|
||||
case 'PATCH': {␍
|
||||
$TestType = $this->route('TestType');␍
|
||||
return [␍
|
||||
'name' => 'required|max:100|unique:test_types,id,'.$TestType->id,␍
|
||||
'unique_code' => 'required|max:100|unique:test_types,id,'.$TestType->id,␍
|
||||
'info.*.name'=>'required',␍
|
||||
'info.*.type'=>'required',␍
|
||||
'info.*.size'=>'nullable',␍
|
||||
'info.*.parent_id'=>'nullable|numeric|exists:inputs,id',␍
|
||||
];␍
|
||||
break;␍
|
||||
␍
|
||||
}␍
|
||||
default:␍
|
||||
break;␍
|
||||
}␍
|
||||
␍
|
||||
}␍
|
||||
␍
|
||||
}␍
|
||||
|
||||
@@ -1,53 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use App\User;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Contracts\Validation\Validator;
|
||||
|
||||
|
||||
class StoreUserRequest extends FormRequest
|
||||
{
|
||||
public function authorize()
|
||||
{
|
||||
if ($this->method() == 'POST') {
|
||||
return auth('api')->check() && auth('api')->user()->can('store', User::class);
|
||||
} else {
|
||||
$User = $this->route('User');
|
||||
return auth('api')->check() && $User && auth('api')->user()->can('update', $User);
|
||||
}
|
||||
}
|
||||
|
||||
public function rules()
|
||||
{
|
||||
switch ($this->method()) {
|
||||
case 'POST': {
|
||||
return [
|
||||
'name'=>'required|string|max:255',
|
||||
'cell_number'=>'required|digits_between:10,11|unique:users',
|
||||
'password'=>'required|string|min:6',
|
||||
'medical_center_id' => 'required|numeric|exists:medical_centers,id',
|
||||
];
|
||||
break;
|
||||
}
|
||||
case 'PUT':
|
||||
case 'PATCH': {
|
||||
$User = $this->route('User');
|
||||
return [
|
||||
'name'=>'required|string|max:255',
|
||||
'cell_number'=>'required|digits_between:10,11|unique:users,id,'.$User->id,
|
||||
'password'=>'required|string|min:6',
|
||||
'medical_center_id' => 'required|numeric|exists:medical_centers,id',
|
||||
];
|
||||
break;
|
||||
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
<?php␍
|
||||
␍
|
||||
namespace App\Http\Requests;␍
|
||||
␍
|
||||
use App\User;␍
|
||||
use Illuminate\Validation\Rule;␍
|
||||
use Illuminate\Foundation\Http\FormRequest;␍
|
||||
use Illuminate\Contracts\Validation\Validator;␍
|
||||
␍
|
||||
␍
|
||||
class StoreUserRequest extends FormRequest␍
|
||||
{␍
|
||||
public function authorize()␍
|
||||
{␍
|
||||
if ($this->method() == 'POST') {␍
|
||||
return auth('api')->check() && auth('api')->user()->can('store', User::class);␍
|
||||
} else {␍
|
||||
$User = $this->route('User');␍
|
||||
return auth('api')->check() && $User && auth('api')->user()->can('update', $User);␍
|
||||
}␍
|
||||
}␍
|
||||
␍
|
||||
public function rules()␍
|
||||
{␍
|
||||
switch ($this->method()) {␍
|
||||
case 'POST': {␍
|
||||
return [␍
|
||||
'name'=>'required|string|max:255',␍
|
||||
'cell_number'=>'required|digits_between:10,11|unique:users',␍
|
||||
'password'=>'required|string|min:6',␍
|
||||
'medical_center_id' => 'required|numeric|exists:medical_centers,id',␍
|
||||
];␍
|
||||
break;␍
|
||||
}␍
|
||||
case 'PUT':␍
|
||||
case 'PATCH': {␍
|
||||
$User = $this->route('User');␍
|
||||
return [␍
|
||||
'name'=>'required|string|max:255',␍
|
||||
'cell_number'=>'required|digits_between:10,11|unique:users,id,'.$User->id,␍
|
||||
'password'=>'required|string|min:6',␍
|
||||
'medical_center_id' => 'required|numeric|exists:medical_centers,id',␍
|
||||
];␍
|
||||
break;␍
|
||||
␍
|
||||
}␍
|
||||
default:␍
|
||||
break;␍
|
||||
}␍
|
||||
␍
|
||||
}␍
|
||||
␍
|
||||
}␍
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ use Illuminate\Database\Eloquent\Model;
|
||||
class Input extends Model
|
||||
{
|
||||
public $fillable = ['name','type','size','test_type_id','parent_id'];
|
||||
public function testtype()
|
||||
public function test_type()
|
||||
{
|
||||
return $this->belongsTo('App\TestType');
|
||||
}
|
||||
|
||||
+2
-1
@@ -6,11 +6,12 @@ use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class InputValue extends Model
|
||||
{
|
||||
public $fillable = ['value','test_result_id','input_id'];
|
||||
public function input()
|
||||
{
|
||||
return $this->belongsTo('App\Input');
|
||||
}
|
||||
public function testresult()
|
||||
public function test_result()
|
||||
{
|
||||
return $this->belongsTo('App\TestResult');
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
namespace App\Packages\Messaging\src\Facades;
|
||||
|
||||
use Illuminate\Support\Facades\Facade;
|
||||
use App\Packages\Messaging\src\Message;
|
||||
|
||||
class MessageResponse extends Facade {
|
||||
|
||||
protected static function getFacadeAccessor() { return Message::class; }
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Packages\Messaging\src;
|
||||
|
||||
class Message
|
||||
{
|
||||
public function success($data = null, $message = null, $title = null, $status = 'Success')
|
||||
{
|
||||
$message = isset($message) ? $message : trans('success_title');
|
||||
$title = isset($title) ? $title : trans('success');
|
||||
return response()->json(['status' => $status, 'message' => $message, 'title' => $title, 'data' => $data], 200);
|
||||
}
|
||||
|
||||
public function error($message = null, $title = null, $statusCode = 422, $status = 'Faild', $data = null)
|
||||
{
|
||||
$message = isset($message) ? $message : trans('messages.faild_message');
|
||||
$title = isset($title) ? $title : trans('messages.faild');
|
||||
return response()->json(['status' => $status, 'errors' => ['message' => [$message, 'Title' => $title]], 'data' => $data], $statusCode);
|
||||
}
|
||||
}
|
||||
@@ -1,29 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\User;
|
||||
use App\MedicalCenter;
|
||||
use Doctrine\Tests\Common\Inflector\InflectorTest;
|
||||
|
||||
class MedicalCenterPolicy
|
||||
{
|
||||
|
||||
public function delete(User $User, MedicalCenter $MedicalCenter)
|
||||
{
|
||||
// if($User->hasRole('Admin'))
|
||||
return true;
|
||||
}
|
||||
|
||||
public function update(User $User, MedicalCenter $MedicalCenter)
|
||||
{
|
||||
// if($User->hasRole('Admin'))
|
||||
return true;
|
||||
}
|
||||
|
||||
public function store(User $User)
|
||||
{
|
||||
// if($User->hasRole('Admin'))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
<?php␍
|
||||
␍
|
||||
namespace App\Policies;␍
|
||||
␍
|
||||
use App\User;␍
|
||||
use App\MedicalCenter;␍
|
||||
use Doctrine\Tests\Common\Inflector\InflectorTest;␍
|
||||
␍
|
||||
class MedicalCenterPolicy␍
|
||||
{␍
|
||||
␍
|
||||
public function delete(User $User, MedicalCenter $MedicalCenter)␍
|
||||
{␍
|
||||
// if($User->hasRole('Admin'))␍
|
||||
return true;␍
|
||||
}␍
|
||||
␍
|
||||
public function update(User $User, MedicalCenter $MedicalCenter)␍
|
||||
{␍
|
||||
// if($User->hasRole('Admin'))␍
|
||||
return true;␍
|
||||
}␍
|
||||
␍
|
||||
public function store(User $User)␍
|
||||
{␍
|
||||
// if($User->hasRole('Admin'))␍
|
||||
return true;␍
|
||||
}␍
|
||||
}␍
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php␍
|
||||
␍
|
||||
namespace App\Policies;␍
|
||||
␍
|
||||
use App\User;␍
|
||||
use App\TestResult;␍
|
||||
use Doctrine\Tests\Common\Inflector\InflectorTest;␍
|
||||
␍
|
||||
class TestResultPolicy␍
|
||||
{␍
|
||||
␍
|
||||
public function delete(User $User, TestResult $TestResult)␍
|
||||
{␍
|
||||
// if($User->hasRole('Admin'))␍
|
||||
return true;␍
|
||||
}␍
|
||||
␍
|
||||
public function update(User $User, TestResult $TestResult)␍
|
||||
{␍
|
||||
// if($User->hasRole('Admin'))␍
|
||||
return true;␍
|
||||
}␍
|
||||
␍
|
||||
public function store(User $User)␍
|
||||
{␍
|
||||
// if($User->hasRole('Admin'))␍
|
||||
return true;␍
|
||||
}␍
|
||||
}␍
|
||||
@@ -1,29 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\User;
|
||||
use App\TestType;
|
||||
use Doctrine\Tests\Common\Inflector\InflectorTest;
|
||||
|
||||
class TestTypePolicy
|
||||
{
|
||||
|
||||
public function delete(User $User, TestType $TestType)
|
||||
{
|
||||
// if($User->hasRole('Admin'))
|
||||
return true;
|
||||
}
|
||||
|
||||
public function update(User $User, TestType $TestType)
|
||||
{
|
||||
// if($User->hasRole('Admin'))
|
||||
return true;
|
||||
}
|
||||
|
||||
public function store(User $User)
|
||||
{
|
||||
// if($User->hasRole('Admin'))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
<?php␍
|
||||
␍
|
||||
namespace App\Policies;␍
|
||||
␍
|
||||
use App\User;␍
|
||||
use App\TestType;␍
|
||||
use Doctrine\Tests\Common\Inflector\InflectorTest;␍
|
||||
␍
|
||||
class TestTypePolicy␍
|
||||
{␍
|
||||
␍
|
||||
public function delete(User $User, TestType $TestType)␍
|
||||
{␍
|
||||
// if($User->hasRole('Admin'))␍
|
||||
return true;␍
|
||||
}␍
|
||||
␍
|
||||
public function update(User $User, TestType $TestType)␍
|
||||
{␍
|
||||
// if($User->hasRole('Admin'))␍
|
||||
return true;␍
|
||||
}␍
|
||||
␍
|
||||
public function store(User $User)␍
|
||||
{␍
|
||||
// if($User->hasRole('Admin'))␍
|
||||
return true;␍
|
||||
}␍
|
||||
}␍
|
||||
|
||||
+28
-28
@@ -1,28 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\User;
|
||||
use Doctrine\Tests\Common\Inflector\InflectorTest;
|
||||
|
||||
class UserPolicy
|
||||
{
|
||||
|
||||
public function delete(User $User, User $Operator)
|
||||
{
|
||||
// if($User->hasRole('Admin') || $User->hasRole('Supervisor'))
|
||||
return true;
|
||||
}
|
||||
|
||||
public function update(User $User, User $Operator)
|
||||
{
|
||||
// if($User->hasRole('Admin') || $User->id == $Operator->id)
|
||||
return true;
|
||||
}
|
||||
|
||||
public function store(User $User)
|
||||
{
|
||||
// if($User->hasRole('Admin'))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
<?php␍
|
||||
␍
|
||||
namespace App\Policies;␍
|
||||
␍
|
||||
use App\User;␍
|
||||
use Doctrine\Tests\Common\Inflector\InflectorTest;␍
|
||||
␍
|
||||
class UserPolicy␍
|
||||
{␍
|
||||
␍
|
||||
public function delete(User $User, User $Operator)␍
|
||||
{␍
|
||||
// if($User->hasRole('Admin') || $User->hasRole('Supervisor'))␍
|
||||
return true;␍
|
||||
}␍
|
||||
␍
|
||||
public function update(User $User, User $Operator)␍
|
||||
{␍
|
||||
// if($User->hasRole('Admin') || $User->id == $Operator->id)␍
|
||||
return true;␍
|
||||
}␍
|
||||
␍
|
||||
public function store(User $User)␍
|
||||
{␍
|
||||
// if($User->hasRole('Admin'))␍
|
||||
return true;␍
|
||||
}␍
|
||||
}␍
|
||||
|
||||
@@ -13,7 +13,7 @@ class AppServiceProvider extends ServiceProvider
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
//
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+3
-2
@@ -6,7 +6,8 @@ use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class TestResult extends Model
|
||||
{
|
||||
public function testtype()
|
||||
public $fillable = ['result','verified','autoclave_id','test_type_id','user_id'];
|
||||
public function test_type()
|
||||
{
|
||||
return $this->belongsTo('App\TestType');
|
||||
}
|
||||
@@ -14,7 +15,7 @@ class TestResult extends Model
|
||||
{
|
||||
return $this->belongsTo('App\User');
|
||||
}
|
||||
public function inputvalues()
|
||||
public function input_values()
|
||||
{
|
||||
return $this->hasMany('App\InputValue');
|
||||
}
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@ class TestType extends Model
|
||||
{
|
||||
return $this->belongsTo('App\User');
|
||||
}
|
||||
public function testresults()
|
||||
public function test_results()
|
||||
{
|
||||
return $this->hasMany('App\TestResult');
|
||||
}
|
||||
|
||||
+12
-12
@@ -1,12 +1,12 @@
|
||||
<?php
|
||||
namespace App\Transformers;
|
||||
class Json
|
||||
{
|
||||
public static function response($data = null, $message = null)
|
||||
{
|
||||
return [
|
||||
'data' => $data,
|
||||
'message' => $message,
|
||||
];
|
||||
}
|
||||
}
|
||||
<?php␍
|
||||
namespace App\Transformers;␍
|
||||
class Json␍
|
||||
{␍
|
||||
public static function response($data = null, $message = null)␍
|
||||
{␍
|
||||
return [␍
|
||||
'data' => $data,␍
|
||||
'message' => $message,␍
|
||||
];␍
|
||||
}␍
|
||||
}␍
|
||||
|
||||
+7
-7
@@ -11,15 +11,15 @@ use Spatie\Permission\Traits\HasRoles;
|
||||
class User extends Authenticatable
|
||||
{
|
||||
use Notifiable, HasApiTokens, HasRoles;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'name', 'email', 'password','status','medical_center_id','address', 'gender'
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
'name', 'email', 'password','status','medical_center_id','address', 'gender'
|
||||
];
|
||||
/**
|
||||
* The attributes that should be hidden for arrays.
|
||||
*
|
||||
@@ -38,15 +38,15 @@ class User extends Authenticatable
|
||||
'email_verified_at' => 'datetime',
|
||||
];
|
||||
|
||||
public function medicalcenter()
|
||||
public function medical_center()
|
||||
{
|
||||
return $this->belongsTo('App\MedicalCenter');
|
||||
}
|
||||
public function testresults()
|
||||
public function test_results()
|
||||
{
|
||||
return $this->hasMany('App\TestResult');
|
||||
}
|
||||
public function testtypes()
|
||||
public function test_types()
|
||||
{
|
||||
return $this->hasMany('App\TestType');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user