77 lines
2.8 KiB
PHP
77 lines
2.8 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\EmployeeDirectory;
|
|
use App\Support\Legacy\MeetingWriter;
|
|
use App\Support\Legacy\PortalException;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Illuminate\Http\Request;
|
|
|
|
/**
|
|
* Jadwal mingguan kelas kuliah (t_jadwaltemu + t_jadwalruangkuliah) dari halaman detail Kelas Kuliah akun DB lama: tambah
|
|
* pertemuan, hapus. Path "operator/list_kelas/jadwal/..." memegang kode menu lama sendiri (MenuAccess::ACTIONS: Input
|
|
* Jadwal M030301 atau Entry Jadwal & Peminat M030203), disaring middleware EnsureLegacyMenuAccess.
|
|
*/
|
|
class KelasJadwalController extends Controller
|
|
{
|
|
use ServesLegacyList;
|
|
|
|
public function __construct(
|
|
private readonly AcademicOverview $overview,
|
|
private readonly EmployeeDirectory $employees,
|
|
private readonly MeetingWriter $writer,
|
|
) {}
|
|
|
|
public function store(Request $request, int $id): RedirectResponse
|
|
{
|
|
[$prodi, $units] = $this->scopeOrFail($request);
|
|
$input = $request->validate([
|
|
'hari' => ['required', 'integer', 'between:1,7'],
|
|
'mulai' => ['required', 'date_format:H:i'],
|
|
'selesai' => ['required', 'date_format:H:i'],
|
|
'ruang' => ['required', 'integer'],
|
|
], [], ['hari' => 'hari', 'mulai' => 'jam mulai', 'selesai' => 'jam selesai', 'ruang' => 'ruang']);
|
|
|
|
try {
|
|
$this->writer->add($prodi, $units, $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', 'Pertemuan ditambahkan.');
|
|
}
|
|
|
|
public function destroy(Request $request, int $id, int $temu): RedirectResponse
|
|
{
|
|
[$prodi] = $this->scopeOrFail($request);
|
|
|
|
try {
|
|
$this->writer->remove($prodi, $id, $temu);
|
|
} catch (PortalException $e) {
|
|
return $this->back($id)->with('error', $e->getMessage());
|
|
}
|
|
|
|
return $this->back($id)->with('status', 'Pertemuan dihapus.');
|
|
}
|
|
|
|
/** @return array{0: list<int>, 1: list<int>} prodi akun dan unit ruang (fakultas + prodi) */
|
|
private function scopeOrFail(Request $request): array
|
|
{
|
|
$this->legacyOnly($request);
|
|
$iduser = (int) $request->user()->getKey();
|
|
$prodi = $this->overview->programs($iduser)->keys()->all();
|
|
abort_if($prodi === [], 404);
|
|
|
|
return [$prodi, array_values(array_unique([...$this->employees->faculties($iduser), ...$prodi]))];
|
|
}
|
|
|
|
private function back(int $id): RedirectResponse
|
|
{
|
|
return redirect()->route('operator.kelas-kuliah.show', $id);
|
|
}
|
|
}
|