64 lines
2.6 KiB
PHP
64 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\ClassSchedule;
|
|
use App\Support\Prototype\Satu\Catalog;
|
|
use Illuminate\Contracts\View\View;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
|
|
/** Perkuliahan > Data Kelas > Tahun Ajaran (slug ms_tahunajaran) untuk akun DB lama: tahun ajaran dari t_periodekuliah. */
|
|
class TahunAjaranController extends Controller
|
|
{
|
|
use ServesLegacyList;
|
|
|
|
private const string SLUG = 'ms_tahunajaran';
|
|
|
|
public function __construct(private readonly ClassSchedule $schedule, private readonly AcademicOverview $overview) {}
|
|
|
|
public function __invoke(Request $request): View
|
|
{
|
|
$page = Catalog::page(self::SLUG);
|
|
[$active, $scope] = $this->active($request);
|
|
|
|
return view('operator.satu.remote-list', [
|
|
'page' => $page,
|
|
'crumbs' => $this->crumbs(self::SLUG, $page),
|
|
'note' => 'Tahun ajaran asli dari periode kuliah SIAKAD.'.($active === null ? '' : " Baris berarsir = tahun ajaran periode kuliah aktif {$scope} ({$active})."),
|
|
'empty' => ['icon' => 'calendar', 'title' => 'Belum ada tahun ajaran', 'description' => 'Tahun ajaran tampil setelah ada periode kuliah.'],
|
|
'url' => route('operator.tahun-ajaran.data'),
|
|
'filters' => [],
|
|
'columns' => [
|
|
['key' => 'tahun', 'label' => 'Tahun'],
|
|
['key' => 'nama', 'label' => 'Nama Tahun'],
|
|
],
|
|
'perPage' => ClassSchedule::PER_PAGE,
|
|
'data' => $this->payload($this->schedule->academicYears('', ClassSchedule::PER_PAGE[0], 1, $active)),
|
|
]);
|
|
}
|
|
|
|
public function data(Request $request): JsonResponse
|
|
{
|
|
$this->legacyOnly($request);
|
|
[$active] = $this->active($request);
|
|
|
|
return response()->json($this->payload($this->schedule->academicYears($this->query($request), $this->perPage($request, ClassSchedule::PER_PAGE), max(1, $request->integer('page', 1)), $active)));
|
|
}
|
|
|
|
/**
|
|
* Tahun ajaran periode kuliah aktif prodi yang dikelola akun (akun tanpa prodi: seluruh universitas) dan sebutan cakupannya.
|
|
*
|
|
* @return array{0: ?string, 1: string}
|
|
*/
|
|
private function active(Request $request): array
|
|
{
|
|
$prodi = $this->overview->programs((int) $request->user()->getKey())->keys()->all();
|
|
|
|
return [$this->schedule->activeYear($prodi === [] ? null : $prodi), $prodi === [] ? 'universitas' : 'program studi Anda'];
|
|
}
|
|
}
|