create safety and privacy controller
This commit is contained in:
149
app/Http/Controllers/V3/Dashboard/SafetyAndPrivacyController.php
Normal file
149
app/Http/Controllers/V3/Dashboard/SafetyAndPrivacyController.php
Normal file
@@ -0,0 +1,149 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V3\Dashboard;
|
||||
|
||||
use App\Facades\File\FileFacade;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\V3\SafetyAndPrivacy\FirstStepStoreRequest;
|
||||
use App\Http\Requests\V3\SafetyAndPrivacy\SecondStepStoreRequest;
|
||||
use App\Http\Requests\V3\SafetyAndPrivacy\ThirdStepStoreRequest;
|
||||
use App\Http\Traits\ApiResponse;
|
||||
use App\Models\InfoItem;
|
||||
use App\Models\SafetyAndPrivacy;
|
||||
use App\Services\Cartables\SafetyAndPrivacyTableService;
|
||||
use App\Services\NominatimService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
||||
class SafetyAndPrivacyController extends Controller
|
||||
{
|
||||
use ApiResponse;
|
||||
|
||||
public function index(Request $request, SafetyAndPrivacyTableService $safetyAndPrivacyTableService): JsonResponse
|
||||
{
|
||||
return response()->json($safetyAndPrivacyTableService->datatable($request));
|
||||
}
|
||||
|
||||
public function firstStepStore(FirstStepStoreRequest $request, NominatimService $nominatimService): JsonResponse
|
||||
{
|
||||
$user = auth()->user();
|
||||
|
||||
if (auth()->user()->edarate_ostani_id || is_null(auth()->user()->city_id)) {
|
||||
return $this->errorResponse('امکان ثبت این مورد برای ادارات استانی و ستادی وجود ندارد!');
|
||||
}
|
||||
|
||||
if (is_null(auth()->user()->edarate_shahri_id)) {
|
||||
return $this->errorResponse('اداره شهری برای شما در سامانه ثبت نشده است!');
|
||||
}
|
||||
|
||||
$coordinates = explode(',', $request->point);
|
||||
$item = InfoItem::query()
|
||||
->where('id', $request->info_id)
|
||||
->where('item', 17)
|
||||
->firstOrFail();
|
||||
|
||||
DB::transaction(function () use ($request, $coordinates, $item, $nominatimService)
|
||||
{
|
||||
$safety_and_privacy = SafetyAndPrivacy::query()->create([
|
||||
'lat' => $coordinates[0],
|
||||
'lon' => $coordinates[1],
|
||||
'operator_id' => auth()->user()->id,
|
||||
'operator_name' => auth()->user()->name,
|
||||
'province_id' => auth()->user()->province_id,
|
||||
'province_fa' => auth()->user()->province_fa,
|
||||
'info_id' => $item->id,
|
||||
'info_fa' => $item->sub_item_str,
|
||||
'city_id' => auth()->user()->city_id,
|
||||
'city_fa' => auth()->user()->city_fa,
|
||||
'activity_date_time' => $request->activity_date." ".$request->activity_time,
|
||||
'edare_shahri_id' => auth()->user()->edarate_shahri_id,
|
||||
'edare_shahri_name' => auth()->user()->edarate_shahri_name,
|
||||
'way_id' => $nominatimService->get_way_id_from_nominatim($coordinates[0], $coordinates[1]),
|
||||
'recognize_picture' => $request->has('recognize_picture') ? FileFacade::save($request->recognize_picture, 'safety_and_privacy') : null,
|
||||
'step' => 1,
|
||||
'step_fa' => 'گام اول (شناسایی)'
|
||||
]);
|
||||
|
||||
auth()->user()->addActivityComplete(1134);
|
||||
});
|
||||
|
||||
return $this->successResponse();
|
||||
}
|
||||
|
||||
public function secondStepStore(SecondStepStoreRequest $safety_and_privacy, Request $request): JsonResponse
|
||||
{
|
||||
$user = auth()->user();
|
||||
|
||||
if (auth()->user()->edarate_ostani_id || is_null(auth()->user()->city_id)) {
|
||||
return $this->errorResponse('امکان ثبت این مورد برای ادارات استانی و ستادی وجود ندارد!');
|
||||
}
|
||||
|
||||
if (is_null(auth()->user()->edarate_shahri_id)) {
|
||||
return $this->errorResponse('اداره شهری برای شما در سامانه ثبت نشده است!');
|
||||
}
|
||||
|
||||
DB::transaction(function () use ($request, $safety_and_privacy)
|
||||
{
|
||||
$judiciary_document = [];
|
||||
foreach ($request->judiciary_document as $index => $item) {
|
||||
$judiciary_document[] = $item->store('safety_and_privacy/'.$safety_and_privacy->id.'/judiciary_document', 'public');
|
||||
}
|
||||
$safety_and_privacy->judiciary_document = serialize($judiciary_document);
|
||||
$safety_and_privacy->judiciary_document_upload_date = now();
|
||||
|
||||
$safety_and_privacy->goToSecondStep();
|
||||
$safety_and_privacy->save();
|
||||
|
||||
auth()->user()->addActivityComplete(1135);
|
||||
});
|
||||
|
||||
return $this->successResponse();
|
||||
}
|
||||
|
||||
public function thirdStepStore(ThirdStepStoreRequest $safety_and_privacy, Request $request): JsonResponse
|
||||
{
|
||||
$user = auth()->user();
|
||||
|
||||
if (auth()->user()->edarate_ostani_id || is_null(auth()->user()->city_id)) {
|
||||
return $this->errorResponse('امکان ثبت این مورد برای ادارات استانی و ستادی وجود ندارد!');
|
||||
}
|
||||
|
||||
if (is_null(auth()->user()->edarate_shahri_id)) {
|
||||
return $this->errorResponse('اداره شهری برای شما در سامانه ثبت نشده است!');
|
||||
}
|
||||
|
||||
DB::transaction(function () use ($request, $safety_and_privacy) {
|
||||
$action_picture = $request->file('action_picture')->store('safety_and_privacy/'.$safety_and_privacy->id.'/action_picture', 'public');
|
||||
$safety_and_privacy->action_picture = Storage::disk('public')->url($action_picture);
|
||||
$safety_and_privacy->action_picture_document_upload_date = now();
|
||||
|
||||
$safety_and_privacy->goToThirdStep();
|
||||
$safety_and_privacy->save();
|
||||
auth()->user()->addActivityComplete(1136);
|
||||
});
|
||||
|
||||
return $this->successResponse();
|
||||
}
|
||||
|
||||
public function show(SafetyAndPrivacy $safetyAndPrivacy): JsonResponse
|
||||
{
|
||||
return $this->successResponse($safetyAndPrivacy);
|
||||
}
|
||||
|
||||
public function destroy(SafetyAndPrivacy $safetyAndPrivacy): JsonResponse
|
||||
{
|
||||
Storage::deleteDirectory('public/' . 'safety_and_privacy/' . $safetyAndPrivacy->id);
|
||||
|
||||
DB::transaction(function () use ($safetyAndPrivacy)
|
||||
{
|
||||
auth()->user()->addActivityComplete(1155);
|
||||
$safetyAndPrivacy->delete();
|
||||
});
|
||||
|
||||
return $this->successResponse();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\V3\SafetyAndPrivacy;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class FirstStepStoreRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'point' => 'required',
|
||||
'info_id' => 'required',
|
||||
'activity_date' => 'required|date_format:Y-m-d',
|
||||
'activity_time' => 'required|date_format:H:i',
|
||||
'recognize_picture' => 'required|image',
|
||||
];
|
||||
}
|
||||
|
||||
public function attributes(): array
|
||||
{
|
||||
return [
|
||||
'activity_date' => 'تاریخ فعالیت',
|
||||
'activity_time' => 'ساعت فعالیت',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\V3\SafetyAndPrivacy;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class SecondStepStoreRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'judiciary_document' => 'required|array',
|
||||
'judiciary_document.*' => 'file',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\V3\SafetyAndPrivacy;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class ThirdStepStoreRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'action_picture' => 'required|image',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,7 @@ class RoadObservationTableService
|
||||
$user = auth()->user();
|
||||
|
||||
$fields = [
|
||||
'fk_RegisteredEventMessage', 'road_observeds.id', 'Title', 'road_observeds.created_at',
|
||||
'fk_RegisteredEventMessage', 'road_observeds.id', 'Title', 'road_observeds.created_at', 'StartTime_DateTime',
|
||||
'lat', 'lng', 'FeatureTypeTitle', 'Description', 'MobileForSendEventSms', 'rms_start_latlng',
|
||||
'rms_description', 'rms_status', 'rms_last_activity_fa', 'rms_last_activity', 'edarate_shahri_id',
|
||||
'road_observeds.province_id', 'province_fa', 'city_id', 'city_fa', 'edarate_shahri.name_fa',
|
||||
@@ -53,7 +53,7 @@ class RoadObservationTableService
|
||||
$user = auth()->user();
|
||||
|
||||
$fields = [
|
||||
'fk_RegisteredEventMessage', 'road_observeds.id', 'Title', 'road_observeds.created_at',
|
||||
'fk_RegisteredEventMessage', 'road_observeds.id', 'Title', 'road_observeds.created_at', 'StartTime_DateTime',
|
||||
'lat', 'lng', 'FeatureTypeTitle', 'Description', 'MobileForSendEventSms', 'edarate_shahri_id',
|
||||
'rms_description', 'rms_status', 'rms_start_latlng', 'rms_last_activity_fa', 'image_after', 'image_before',
|
||||
'rms_last_activity', 'road_observeds.province_id', 'province_fa', 'city_id', 'city_fa',
|
||||
@@ -79,14 +79,15 @@ class RoadObservationTableService
|
||||
{
|
||||
$user = auth()->user();
|
||||
|
||||
$fields = 'fk_RegisteredEventMessage, road_observeds.id, Title, FeatureTypeTitle, MobileForSendEventSms, StartTime_DateTime,
|
||||
road_observeds.created_at, rms_last_activity, rms_last_activity_fa, status, edarate_shahri_id,
|
||||
status_fa, supervisor_description, rms_description, province_fa, city_id, city_fa, Description, edarate_shahri.name_fa as edarate_shahri_name_fa, lat, lng';
|
||||
|
||||
if ($user->hasPermissionTo('show-fast-react')) {
|
||||
$query = RoadObserved::query()->leftjoin('edarate_shahri', 'road_observeds.edarate_shahri_id', 'edarate_shahri.id')
|
||||
->where('rms_status', '=', 0)
|
||||
->whereNotNull('edarate_shahri_id')
|
||||
->selectRaw('fk_RegisteredEventMessage, road_observeds.id, Title, FeatureTypeTitle, MobileForSendEventSms,
|
||||
road_observeds.created_at, rms_last_activity, rms_last_activity_fa, status, edarate_shahri_id,
|
||||
status_fa, supervisor_description, rms_description, province_fa, city_id, city_fa, Description, edarate_shahri.name_fa as edarate_shahri_name_fa, lat, lng'
|
||||
);
|
||||
->selectRaw($fields);
|
||||
}
|
||||
elseif ($user->hasPermissionTo('show-fast-react-province')) {
|
||||
|
||||
@@ -98,10 +99,7 @@ class RoadObservationTableService
|
||||
->where('rms_status', '=', 0)
|
||||
->whereNotNull('road_observeds.province_id')
|
||||
->where('road_observeds.province_id', '=', $user->province_id)
|
||||
->selectRaw('fk_RegisteredEventMessage, road_observeds.id, Title, FeatureTypeTitle, MobileForSendEventSms,
|
||||
road_observeds.created_at, rms_last_activity, rms_last_activity_fa, status, edarate_shahri_id,
|
||||
status_fa, supervisor_description, rms_description, province_fa, city_id, city_fa, Description, edarate_shahri.name_fa as edarate_shahri_name_fa, lat, lng'
|
||||
);
|
||||
->selectRaw($fields);
|
||||
|
||||
}
|
||||
elseif ($user->hasPermissionTo('show-fast-react-edarate-shahri')) {
|
||||
@@ -114,10 +112,7 @@ class RoadObservationTableService
|
||||
->where('rms_status', '=', 0)
|
||||
->whereNotNull('edarate_shahri_id')
|
||||
->where('edarate_shahri_id', '=', $user->edarate_shahri_id)
|
||||
->selectRaw('fk_RegisteredEventMessage, road_observeds.id, Title, FeatureTypeTitle, MobileForSendEventSms,
|
||||
road_observeds.created_at, rms_last_activity, rms_last_activity_fa, status, edarate_shahri_id,
|
||||
status_fa, supervisor_description, rms_description, province_fa, city_id, city_fa, Description, edarate_shahri.name_fa as edarate_shahri_name_fa, lat, lng'
|
||||
);
|
||||
->selectRaw($fields);
|
||||
|
||||
}
|
||||
|
||||
|
||||
49
app/Services/Cartables/SafetyAndPrivacyTableService.php
Normal file
49
app/Services/Cartables/SafetyAndPrivacyTableService.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Cartables;
|
||||
|
||||
use App\Facades\DataTable\DataTableFacade;
|
||||
use App\Http\Traits\ApiResponse;
|
||||
use App\Models\SafetyAndPrivacy;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class SafetyAndPrivacyTableService
|
||||
{
|
||||
use ApiResponse;
|
||||
|
||||
public function dataTable(Request $request, $loadRelations = false)
|
||||
{
|
||||
$user = auth()->user();
|
||||
|
||||
$fields = ['id','lat','lon','province_id','province_fa','city_id','city_fa','edare_shahri_id','edare_shahri_name',
|
||||
'recognize_picture','action_picture','operator_id','operator_name','way_id','created_at','updated_at','step','judiciary_document',
|
||||
'judiciary_document_upload_date','info_id','info_fa','activity_date_time','judiciary_document_upload_date','action_picture_document_upload_date',
|
||||
'step_fa'
|
||||
];
|
||||
|
||||
if ($user->hasPermissionTo('show-safety-and-privacy-operator-cartable')) {
|
||||
$query = SafetyAndPrivacy::query()->select($fields);
|
||||
}
|
||||
elseif ($user->hasPermissionTo('show-safety-and-privacy-operator-cartable-province')) {
|
||||
if (is_null($user->province_id)) {
|
||||
return $this->errorResponse('استانی برای شما در سامانه ثبت نشده است!');
|
||||
}
|
||||
|
||||
$query = SafetyAndPrivacy::query()->where('province_id', '=', $user->province_id)->select($fields);
|
||||
}
|
||||
elseif ($user->hasPermissionTo('show-safety-and-privacy-operator-cartable-edarate-shahri')) {
|
||||
if (is_null($user->edarate_shahri_id)) {
|
||||
return $this->errorResponse('اداره ای برای شما در سامانه ثبت نشده است!');
|
||||
}
|
||||
|
||||
$query = SafetyAndPrivacy::query()->where('edare_shahri_id', '=', $user->edarate_shahri_id);
|
||||
}
|
||||
|
||||
return DataTableFacade::run(
|
||||
$query,
|
||||
$request,
|
||||
allowedFilters: ['*'],
|
||||
allowedSortings: ['*']
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user