79 lines
2.6 KiB
PHP
79 lines
2.6 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\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);
|
|
}
|
|
}
|