80 lines
3.3 KiB
PHP
80 lines
3.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Operator;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Controllers\Operator\Concerns\ServesLegacyList;
|
|
use App\Support\Legacy\AcademicOverview;
|
|
use App\Support\Legacy\ClassSchedule;
|
|
use App\Support\Legacy\EmployeeDirectory;
|
|
use App\Support\Legacy\ExamWriter;
|
|
use App\Support\Legacy\MeetingWriter;
|
|
use App\Support\Legacy\PortalException;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Validation\Rule;
|
|
|
|
/**
|
|
* Jadwal ujian kelas kuliah (t_jadwalujian + t_jadwalruangujian) dari halaman detail Kelas Kuliah akun DB lama: tambah ujian,
|
|
* hapus. Path "operator/list_kelas/ujian/..." memegang kode menu lama sendiri (MenuAccess::ACTIONS: Input Jadwal M030301
|
|
* atau Entry Jadwal & Peminat M030203), disaring middleware EnsureLegacyMenuAccess.
|
|
*/
|
|
class KelasUjianController extends Controller
|
|
{
|
|
use ServesLegacyList;
|
|
|
|
public function __construct(
|
|
private readonly AcademicOverview $overview,
|
|
private readonly EmployeeDirectory $employees,
|
|
private readonly MeetingWriter $meetings,
|
|
private readonly ExamWriter $writer,
|
|
) {}
|
|
|
|
public function store(Request $request, int $id): RedirectResponse
|
|
{
|
|
$this->legacyOnly($request);
|
|
$iduser = (int) $request->user()->getKey();
|
|
$prodi = $this->overview->programs($iduser)->keys()->all();
|
|
abort_if($prodi === [], 404);
|
|
|
|
$input = $request->validate([
|
|
'jenis' => ['required', Rule::in(array_keys(ClassSchedule::EXAMS))],
|
|
'tanggal' => ['required', 'date_format:Y-m-d'],
|
|
'ujian_mulai' => ['required', 'date_format:H:i'],
|
|
'ujian_selesai' => ['required', 'date_format:H:i'],
|
|
'ujian_ruang' => ['required', 'integer'],
|
|
], [], ['jenis' => 'jenis ujian', 'tanggal' => 'tanggal ujian', 'ujian_mulai' => 'jam mulai', 'ujian_selesai' => 'jam selesai', 'ujian_ruang' => 'ruang']);
|
|
// Nama isian berawalan ujian_ agar tidak bertabrakan dengan formulir pertemuan di halaman yang sama
|
|
$input = ['jenis' => $input['jenis'], 'tanggal' => $input['tanggal'], 'mulai' => $input['ujian_mulai'], 'selesai' => $input['ujian_selesai'], 'ruang' => $input['ujian_ruang']];
|
|
|
|
try {
|
|
$rooms = $this->meetings->roomOptions(array_values(array_unique([...$this->employees->faculties($iduser), ...$prodi])))->all();
|
|
$this->writer->add($prodi, $rooms, $id, $input, (string) $request->user()->username, $request->ip());
|
|
} catch (PortalException $e) {
|
|
return $this->back($id)->with('error', $e->getMessage());
|
|
}
|
|
|
|
return $this->back($id)->with('status', 'Jadwal ujian ditambahkan.');
|
|
}
|
|
|
|
public function destroy(Request $request, int $id, int $ujian): RedirectResponse
|
|
{
|
|
$this->legacyOnly($request);
|
|
$prodi = $this->overview->programs((int) $request->user()->getKey())->keys()->all();
|
|
abort_if($prodi === [], 404);
|
|
|
|
try {
|
|
$this->writer->remove($prodi, $id, $ujian);
|
|
} catch (PortalException $e) {
|
|
return $this->back($id)->with('error', $e->getMessage());
|
|
}
|
|
|
|
return $this->back($id)->with('status', 'Jadwal ujian dihapus.');
|
|
}
|
|
|
|
private function back(int $id): RedirectResponse
|
|
{
|
|
return redirect()->route('operator.kelas-kuliah.show', $id);
|
|
}
|
|
}
|