100 lines
4.7 KiB
PHP
100 lines
4.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Operator;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\Legacy\Account;
|
|
use App\Support\Legacy\AcademicCalendar;
|
|
use App\Support\Legacy\AcademicOverview;
|
|
use App\Support\Prototype\Satu\Catalog;
|
|
use Illuminate\Contracts\View\View;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Pagination\LengthAwarePaginator;
|
|
use Illuminate\Support\Collection;
|
|
|
|
/**
|
|
* Portal > Kegiatan > Kalender Akademik (slug ms_kalender) untuk akun DB lama: kegiatan asli t_kalender_kegiatan
|
|
* per periode, hanya baca seperti Admin Fakultas di SATU. Filter dan halaman lewat data() (JSON).
|
|
*/
|
|
class KalenderController extends Controller
|
|
{
|
|
private const string SLUG = 'ms_kalender';
|
|
|
|
public function __construct(
|
|
private readonly AcademicOverview $overview,
|
|
private readonly AcademicCalendar $calendar,
|
|
) {}
|
|
|
|
public function __invoke(Request $request): View
|
|
{
|
|
$page = Catalog::page(self::SLUG);
|
|
$periods = $this->calendar->periods();
|
|
$prodi = $this->overview->programs((int) $request->user()->getKey())->keys()->all();
|
|
$default = $this->calendar->defaultPeriod($prodi, $periods);
|
|
[$labelPeriode, $labelJenis, $labelLiburAkademik, $labelLiburNasional] = $page['filters'];
|
|
|
|
return view('operator.satu.remote-list', [
|
|
'page' => $page,
|
|
'crumbs' => ['Beranda' => route('operator.dashboard')] + array_fill_keys(Catalog::trail(self::SLUG), null) + [$page['title'] => null],
|
|
'note' => 'Kalender akademik asli dari SIAKAD. Halaman ini hanya menampilkan data; pengisian kalender dilakukan oleh unit pusat.',
|
|
'empty' => ['icon' => 'calendar-days', 'title' => 'Belum ada periode akademik', 'description' => 'Daftar kegiatan tampil setelah periode akademik tersedia.'],
|
|
'url' => route('operator.kalender.data'),
|
|
'filters' => [
|
|
['name' => 'periode', 'label' => $labelPeriode, 'options' => $periods->all(), 'value' => $default],
|
|
['name' => 'jenis', 'label' => $labelJenis, 'options' => $this->calendar->types()->pluck('nama', 'id')->all()],
|
|
['name' => 'libur_akademik', 'label' => $labelLiburAkademik, 'type' => 'check'],
|
|
['name' => 'libur_nasional', 'label' => $labelLiburNasional, 'type' => 'check'],
|
|
],
|
|
'columns' => [
|
|
['key' => 'mulai', 'label' => 'Tgl Mulai'],
|
|
['key' => 'selesai', 'label' => 'Tgl Selesai'],
|
|
['key' => 'jenis', 'label' => 'Jenis Kegiatan'],
|
|
['key' => 'keterangan', 'label' => 'Keterangan'],
|
|
['key' => 'libur', 'label' => 'Libur', 'badge' => true],
|
|
],
|
|
'perPage' => AcademicCalendar::PER_PAGE,
|
|
'data' => $default === null ? null : $this->payload($this->search($request, $periods, $default)),
|
|
]);
|
|
}
|
|
|
|
public function data(Request $request): JsonResponse
|
|
{
|
|
abort_unless($request->user() instanceof Account, 404);
|
|
|
|
$periods = $this->calendar->periods();
|
|
abort_if($periods->isEmpty(), 404);
|
|
$prodi = $this->overview->programs((int) $request->user()->getKey())->keys()->all();
|
|
|
|
return response()->json($this->payload($this->search($request, $periods, $this->calendar->defaultPeriod($prodi, $periods))));
|
|
}
|
|
|
|
/** @param Collection<int, string> $periods */
|
|
private function search(Request $request, Collection $periods, int $default): LengthAwarePaginator
|
|
{
|
|
$periode = $request->filled('periode') && $periods->has($request->integer('periode')) ? $request->integer('periode') : $default;
|
|
$jenis = $request->filled('jenis') && $this->calendar->types()->contains('id', $request->integer('jenis')) ? $request->integer('jenis') : null;
|
|
$perPage = in_array($request->integer('per'), AcademicCalendar::PER_PAGE, true) ? $request->integer('per') : AcademicCalendar::PER_PAGE[0];
|
|
|
|
return $this->calendar->events([
|
|
'periode' => $periode,
|
|
'jenis' => $jenis,
|
|
'libur_akademik' => $request->boolean('libur_akademik'),
|
|
'libur_nasional' => $request->boolean('libur_nasional'),
|
|
'q' => mb_substr(trim((string) $request->string('q')), 0, 100),
|
|
], $perPage);
|
|
}
|
|
|
|
/** @return array{rows: list<array<string, mixed>>, page: int, last_page: int, total: int, per_page: int} */
|
|
private function payload(LengthAwarePaginator $rows): array
|
|
{
|
|
return [
|
|
'rows' => array_values($rows->items()),
|
|
'page' => $rows->currentPage(),
|
|
'last_page' => $rows->lastPage(),
|
|
'total' => $rows->total(),
|
|
'per_page' => $rows->perPage(),
|
|
];
|
|
}
|
|
}
|