Integrasi Login dan menu Dasar SIAKAD Operator dan Mahasiswa
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace App\Support\Legacy;
|
||||
|
||||
use App\Enums\Role;
|
||||
|
||||
/**
|
||||
* Pemetaan akun SIAKAD lama ke role baru. Satu akun = satu role, urutan prioritas:
|
||||
* superuser, admin, staf (operator), dosen, otoritas lain (operator).
|
||||
*/
|
||||
final class LegacyRole
|
||||
{
|
||||
/** Nilai t_account.jenis. */
|
||||
public const int JENIS_PEGAWAI = 0;
|
||||
|
||||
public const int JENIS_MAHASISWA = 1;
|
||||
|
||||
/** Administrator Pusat. */
|
||||
private const array SUPERUSER = [1];
|
||||
|
||||
/** KA. PUSKOM, Sisfo Puskom. */
|
||||
private const array ADMIN = [22, 40];
|
||||
|
||||
/** Staf: Puskom, Fakultas, Jurusan, Prodi, Nilai, Keuangan, BAAK, Kasubbag, Cetak, Alumni, Daftar Ulang, BAPSI, Transfer. */
|
||||
private const array OPERATOR = [4, 7, 8, 9, 20, 23, 25, 33, 39, 44, 45, 46, 47, 48];
|
||||
|
||||
private const int DOSEN = 2;
|
||||
|
||||
/**
|
||||
* Pegawai tanpa otoritas dan bukan dosen tidak punya role (login ditolak).
|
||||
*
|
||||
* @param list<int> $otoritas idotoritas dari t_otoritasuser
|
||||
* @param bool $isDosen pegawai tercatat di t_dosen
|
||||
*/
|
||||
public static function resolve(int $jenis, array $otoritas, bool $isDosen): ?Role
|
||||
{
|
||||
if ($jenis === self::JENIS_MAHASISWA) {
|
||||
return Role::Mahasiswa;
|
||||
}
|
||||
|
||||
if ($jenis !== self::JENIS_PEGAWAI) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return match (true) {
|
||||
self::hasAny($otoritas, self::SUPERUSER) => Role::Superuser,
|
||||
self::hasAny($otoritas, self::ADMIN) => Role::Admin,
|
||||
self::hasAny($otoritas, self::OPERATOR) => Role::Operator,
|
||||
$isDosen || in_array(self::DOSEN, $otoritas, true) => Role::Dosen,
|
||||
$otoritas !== [] => Role::Operator,
|
||||
default => null,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<int> $otoritas
|
||||
* @param list<int> $ids
|
||||
*/
|
||||
private static function hasAny(array $otoritas, array $ids): bool
|
||||
{
|
||||
return array_intersect($otoritas, $ids) !== [];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user