171 lines
4.7 KiB
PHP
171 lines
4.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\AksesFile;
|
|
use App\Models\DataUser;
|
|
use App\Models\FileDirectory;
|
|
use App\Models\UnitKerja;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class AksesFileController extends Controller
|
|
{
|
|
/**
|
|
* Display a listing of the resource.
|
|
*/
|
|
public function index()
|
|
{
|
|
$data = [
|
|
'title' => 'Akses'
|
|
];
|
|
return view('akses.index', $data);
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*/
|
|
public function create()
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*/
|
|
public function store(Request $request)
|
|
{
|
|
DB::connection('dbDirectory')->beginTransaction();
|
|
try {
|
|
$datas = request('data');
|
|
foreach ($datas as $data) {
|
|
$payload = [
|
|
'pegawai_id' => $data['pegawai_id'],
|
|
'pegawai_id_entry' => auth()->user()?->dataUser?->id,
|
|
'pegawai_nama_entry' => auth()->user()?->dataUser?->namalengkap,
|
|
'entry_at' => Carbon::now()->format('Y-m-d H:i:s.u'),
|
|
];
|
|
if($data['akses'] === "all"){
|
|
$payload['all_akses'] = true;
|
|
}else{
|
|
$payload['all_akses'] = false;
|
|
$payload['unit_akses'] = $data['unit_akses'];
|
|
|
|
}
|
|
AksesFile::create($payload);
|
|
}
|
|
DB::connection('dbDirectory')->commit();
|
|
return response()->json([
|
|
'status' => true,
|
|
'message' => 'Data berhasil disimpan',
|
|
], 200);
|
|
} catch (\Throwable $th) {
|
|
DB::connection('dbDirectory')->rollBack();
|
|
return response()->json([
|
|
'status' => false,
|
|
'message' => $th->getMessage()
|
|
], 500);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Display the specified resource.
|
|
*/
|
|
public function show(string $id)
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Show the form for editing the specified resource.
|
|
*/
|
|
public function edit(string $id)
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*/
|
|
public function update(Request $request, string $id)
|
|
{
|
|
try {
|
|
$data = AksesFile::where('akses_file_id', $id)->first();
|
|
$payload = [
|
|
'pegawai_id' => request('pegawai_id'),
|
|
'pegawai_id_modified' => auth()->user()?->dataUser?->id,
|
|
'pegawai_nama_modified' => auth()->user()?->dataUser?->namalengkap,
|
|
'modified_at' => Carbon::now()->format('Y-m-d H:i:s.u'),
|
|
'all_akses' => request('akses') === "all" ? true : false,
|
|
'unit_akses' => request('unit_akses')
|
|
];
|
|
$data->update($payload);
|
|
|
|
return response()->json([
|
|
'status' => true,
|
|
'message' => 'Data berhasil diperbarui',
|
|
], 200);
|
|
} catch (\Throwable $th) {
|
|
DB::connection('dbDirectory')->rollBack();
|
|
return response()->json([
|
|
'status' => false,
|
|
'message' => $th->getMessage()
|
|
], 500);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*/
|
|
public function destroy(string $id)
|
|
{
|
|
$data = AksesFile::where('akses_file_id', $id)->first();
|
|
if(!$data){
|
|
return response()->json([
|
|
'status' => false,
|
|
'message' => 'Data tidak ditemukan'
|
|
], 404);
|
|
}
|
|
$payload =[
|
|
'statusenabled' => false
|
|
];
|
|
$data->update($payload);
|
|
return response()->json([
|
|
'status' => true,
|
|
'message' => 'Data berhasil dihapus'
|
|
], 200);
|
|
}
|
|
|
|
|
|
public function datatable(){
|
|
return AksesFile::where('statusenabled', true)->get();
|
|
}
|
|
|
|
public function optionPegawai(){
|
|
$q = request()->get('q');
|
|
$query = DataUser::where('statusenabled', true);
|
|
$data = $query->when($q, function($query, $q){
|
|
$query->where('nama', 'ILIKE', '%' . $q . '%');
|
|
})->select('id','nama')->get();
|
|
|
|
return response()->json([
|
|
'status' => true,
|
|
'data' => $data
|
|
], 200);
|
|
}
|
|
|
|
public function optionUnitKerja(){
|
|
$q = request()->get('q');
|
|
$query = UnitKerja::where('statusenabled', true);
|
|
$data = $query->when($q, function($query, $q){
|
|
$query->where('name', 'ILIKE', '%' . $q . '%');
|
|
})->select('id','name')->get();
|
|
|
|
return response()->json([
|
|
'status' => true,
|
|
'data' => $data
|
|
], 200);
|
|
}
|
|
}
|