102 lines
3.2 KiB
PHP
102 lines
3.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Carbon\Carbon;
|
|
use App\Models\User;
|
|
use App\Models\Pengajuan;
|
|
use Illuminate\Http\Request;
|
|
use App\Models\SettingPengajuan;
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
class DaftarDosenController extends Controller
|
|
{
|
|
/**
|
|
* Display a listing of the resource.
|
|
*/
|
|
public function index()
|
|
{
|
|
$no = 1;
|
|
$nomor = 1;
|
|
$dosen = User::where('role', 'Dosen')->orderByRaw("FIELD(prodi, 'MIF', 'TIF', 'TKK', 'BSD')")->orderBy('name', 'ASC')->get();
|
|
$pengajuan = Pengajuan::all();
|
|
$status = Pengajuan::get()->where('id_mahasiswa', auth()->user()->id);
|
|
|
|
return view('daftar-dosen', compact('no', 'nomor', 'dosen', 'pengajuan', 'status'));
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*/
|
|
public function store(Request $request)
|
|
{
|
|
$user = Auth::user();
|
|
$countPengajuan = Pengajuan::where('id_mahasiswa', $user->id)->count();
|
|
$maxPembimbing = SettingPengajuan::select('maxPembimbing')->first()->maxPembimbing;
|
|
|
|
if ($countPengajuan >= $maxPembimbing) {
|
|
return redirect('daftar-dosen')->with('toast_error', 'Pengajuan Dosen Pembimbing Telah Mencapai Batas Maksimum.');
|
|
}
|
|
|
|
$setting = SettingPengajuan::first();
|
|
$tglMulai = $setting->tglMulai;
|
|
$tglSelesai = $setting->tglSelesai;
|
|
$currentDate = Carbon::now();
|
|
|
|
if ($currentDate->lt($tglMulai)) {
|
|
return redirect()->back()->with('toast_error', 'Pengajuan Dosen Pembimbing Belum Dibuka.');
|
|
} elseif ($currentDate->gt($tglSelesai)) {
|
|
return redirect()->back()->with('toast_error', 'Pengajuan Dosen Pembimbing Sudah Ditutup.');
|
|
}
|
|
|
|
$request->validate([
|
|
'judul',
|
|
'ipk',
|
|
'jumlah_bimbingan',
|
|
'id_mahasiswa',
|
|
'id_dosen_pembimbing',
|
|
]);
|
|
|
|
$existingSubmission = Pengajuan::where('id_dosen_pembimbing', $request->id_dosen_pembimbing)->where('id_mahasiswa', $request->id_mahasiswa)->exists();
|
|
|
|
if ($existingSubmission) {
|
|
return redirect('daftar-dosen')->with('toast_error', 'Dosen Pembimbing Sudah Diajukan.');
|
|
}
|
|
|
|
try {
|
|
Pengajuan::create(array_merge($request->all(), ['nama' => $user->name]));
|
|
$user = User::find($request->id_mahasiswa);
|
|
$user->judul = $request->judul;
|
|
$user->ipk = $request->ipk;
|
|
$user->save();
|
|
return redirect('daftar-dosen')->with('toast_success', 'Pengajuan Dosen Pembimbing Berhasil.');
|
|
} catch (\Exception $e) {
|
|
return redirect('daftar-dosen')->with('toast_error', 'Pengajuan Dosen Pembimbing Gagal.')->withErrors($e->getMessage())->withInput();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Display the specified resource.
|
|
*/
|
|
public function show(string $id)
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*/
|
|
public function update(Request $request, string $id)
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*/
|
|
public function destroy(string $id)
|
|
{
|
|
//
|
|
}
|
|
}
|