[Operator] Penambahan Tambah Jadwal Kelas dan Dosen Pengajar
This commit is contained in:
@@ -8,6 +8,10 @@ use App\Support\Legacy\AcademicOverview;
|
||||
use App\Support\Legacy\ClassSchedule;
|
||||
use App\Support\Legacy\ClassWriter;
|
||||
use App\Support\Legacy\Curriculum;
|
||||
use App\Support\Legacy\EmployeeDirectory;
|
||||
use App\Support\Legacy\LecturerWriter;
|
||||
use App\Support\Legacy\MeetingWriter;
|
||||
use App\Support\Legacy\MenuAccess;
|
||||
use App\Support\Legacy\PortalException;
|
||||
use App\Support\Prototype\Satu\Catalog;
|
||||
use Illuminate\Contracts\View\View;
|
||||
@@ -36,6 +40,7 @@ class KelasController extends Controller
|
||||
private readonly ClassSchedule $schedule,
|
||||
private readonly Curriculum $curriculum,
|
||||
private readonly ClassWriter $writer,
|
||||
private readonly LecturerWriter $lecturers,
|
||||
) {}
|
||||
|
||||
public function __invoke(Request $request): View
|
||||
@@ -183,17 +188,27 @@ class KelasController extends Controller
|
||||
return response()->json($this->payload($this->search($request, $prodi, $periods, $default)));
|
||||
}
|
||||
|
||||
public function show(Request $request, int $id): View
|
||||
/** MenuAccess disuntik per pemanggilan (bukan konstruktor): cache haknya per instance, sedangkan controller dipakai ulang antar permintaan (uji, Octane). */
|
||||
public function show(Request $request, MenuAccess $access, EmployeeDirectory $employees, MeetingWriter $meetings, int $id): View
|
||||
{
|
||||
$this->legacyOnly($request);
|
||||
$prodi = $this->overview->programs((int) $request->user()->getKey())->keys()->all();
|
||||
$iduser = (int) $request->user()->getKey();
|
||||
$prodi = $this->overview->programs($iduser)->keys()->all();
|
||||
$detail = $this->schedule->detail($prodi, $id) ?? abort(404);
|
||||
$page = Catalog::page(self::SLUG);
|
||||
// Penetapan pengajar dan jadwal mengikuti kode menu lama Input Jadwal / Entry Jadwal & Peminat (MenuAccess::ACTIONS), bukan hak Kelas Kuliah.
|
||||
$open = $detail['kelas']['kunci'] === 'Tidak Dikunci';
|
||||
$canAssign = $open && $access->allows($request->user(), 'list_kelas/pengajar');
|
||||
$canSchedule = $open && $access->allows($request->user(), 'list_kelas/jadwal');
|
||||
|
||||
return view('operator.satu.kelas-detail', [
|
||||
'page' => $page,
|
||||
'crumbs' => ['Beranda' => route(auth()->user()->role->dashboardRoute())] + array_fill_keys(Catalog::trail(self::SLUG), null) + [$page['title'] => route('operator.halaman', self::SLUG), 'Detail' => null],
|
||||
'back' => route('operator.halaman', self::SLUG),
|
||||
'canAssign' => $canAssign,
|
||||
'dosenOptions' => $canAssign ? $this->lecturers->options()->except(array_column($detail['pengajar'], 'id')) : collect(),
|
||||
'canSchedule' => $canSchedule,
|
||||
'roomOptions' => $canSchedule ? $meetings->roomOptions(array_values(array_unique([...$employees->faculties($iduser), ...$prodi]))) : collect(),
|
||||
] + $detail);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
<?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\LecturerWriter;
|
||||
use App\Support\Legacy\PortalException;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
/**
|
||||
* Pengajar kelas kuliah (t_jadwaldosen) dari halaman detail Kelas Kuliah akun DB lama: tambah dosen, jadikan pengajar
|
||||
* utama, hapus. Path "operator/list_kelas/pengajar/..." memegang kode menu lama sendiri (MenuAccess::ACTIONS: Input
|
||||
* Jadwal M030301 atau Entry Jadwal & Peminat M030203), disaring middleware EnsureLegacyMenuAccess.
|
||||
*/
|
||||
class KelasPengajarController extends Controller
|
||||
{
|
||||
use ServesLegacyList;
|
||||
|
||||
public function __construct(private readonly AcademicOverview $overview, private readonly LecturerWriter $writer) {}
|
||||
|
||||
public function store(Request $request, int $id): RedirectResponse
|
||||
{
|
||||
$prodi = $this->prodiOrFail($request);
|
||||
$dosen = $request->validate(['dosen' => ['required', 'integer']], [], ['dosen' => 'dosen'])['dosen'];
|
||||
|
||||
try {
|
||||
$this->writer->assign($prodi, $id, (int) $dosen, (string) $request->user()->username, $request->ip());
|
||||
} catch (PortalException $e) {
|
||||
return $this->back($id)->with('error', $e->getMessage());
|
||||
}
|
||||
|
||||
return $this->back($id)->with('status', 'Pengajar ditambahkan.');
|
||||
}
|
||||
|
||||
public function promote(Request $request, int $id, int $dosen): RedirectResponse
|
||||
{
|
||||
$prodi = $this->prodiOrFail($request);
|
||||
|
||||
try {
|
||||
$this->writer->promote($prodi, $id, $dosen);
|
||||
} catch (PortalException $e) {
|
||||
return $this->back($id)->with('error', $e->getMessage());
|
||||
}
|
||||
|
||||
return $this->back($id)->with('status', 'Pengajar utama diperbarui.');
|
||||
}
|
||||
|
||||
public function destroy(Request $request, int $id, int $dosen): RedirectResponse
|
||||
{
|
||||
$prodi = $this->prodiOrFail($request);
|
||||
|
||||
try {
|
||||
$this->writer->remove($prodi, $id, $dosen);
|
||||
} catch (PortalException $e) {
|
||||
return $this->back($id)->with('error', $e->getMessage());
|
||||
}
|
||||
|
||||
return $this->back($id)->with('status', 'Pengajar dihapus.');
|
||||
}
|
||||
|
||||
/** @return list<int> */
|
||||
private function prodiOrFail(Request $request): array
|
||||
{
|
||||
$this->legacyOnly($request);
|
||||
$prodi = $this->overview->programs((int) $request->user()->getKey())->keys()->all();
|
||||
abort_if($prodi === [], 404);
|
||||
|
||||
return $prodi;
|
||||
}
|
||||
|
||||
private function back(int $id): RedirectResponse
|
||||
{
|
||||
return redirect()->route('operator.kelas-kuliah.show', $id);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user