[Superuser] Perbaikan Halaman Akses Superuser
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace App\Support\Legacy;
|
||||
|
||||
use Illuminate\Database\ConnectionInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
/**
|
||||
* Cakupan unit akun DB lama pada halaman katalog. Biasanya fakultas/prodi dari t_unituser; akun berotoritas pusat
|
||||
* (MenuAccess::CENTRAL, mis. Administrator Pusat) yang tidak punya baris t_unituser mencakup seluruh universitas, seperti
|
||||
* menu tanpa bybagian di aplikasi lama. Dipakai AcademicOverview::programs(), EmployeeDirectory::faculties(), CalendarEvents::units().
|
||||
*/
|
||||
final class UnitScope
|
||||
{
|
||||
/** t_jenisbagian: 1 fakultas, 3 program studi. */
|
||||
public const int JENIS_FAKULTAS = 1;
|
||||
|
||||
public const int JENIS_PRODI = 3;
|
||||
|
||||
/** @var array<int, bool> */
|
||||
private array $unlimited = [];
|
||||
|
||||
private function db(): ConnectionInterface
|
||||
{
|
||||
return DB::connection('untan');
|
||||
}
|
||||
|
||||
/** Akun tanpa unit yang memegang otoritas pusat: cakupannya seluruh universitas. */
|
||||
public function isUnlimited(int $iduser): bool
|
||||
{
|
||||
if (isset($this->unlimited[$iduser])) {
|
||||
return $this->unlimited[$iduser];
|
||||
}
|
||||
|
||||
$hasUnit = $this->db()->table('t_unituser')->where('iduser', $iduser)->exists();
|
||||
$central = ! $hasUnit && $this->db()->table('t_otoritasuser')->where('iduser', $iduser)->whereIn('idotoritas', MenuAccess::CENTRAL)->exists();
|
||||
|
||||
return $this->unlimited[$iduser] = $central;
|
||||
}
|
||||
|
||||
/** @return Collection<int, string> semua program studi, idbagian => nama, urut nama */
|
||||
public function allPrograms(): Collection
|
||||
{
|
||||
return $this->db()->table('t_bagian')->where('idjenisbagian', self::JENIS_PRODI)
|
||||
->orderBy('namabagian')->pluck('namabagian', 'idbagian')
|
||||
->mapWithKeys(fn (string $nama, int|string $id): array => [(int) $id => trim($nama)]);
|
||||
}
|
||||
|
||||
/** @return list<int> semua fakultas */
|
||||
public function allFaculties(): array
|
||||
{
|
||||
return $this->db()->table('t_bagian')->where('idjenisbagian', self::JENIS_FAKULTAS)
|
||||
->orderBy('namabagian')->pluck('idbagian')->map(fn (int|string $id): int => (int) $id)->values()->all();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user