79 lines
2.6 KiB
PHP
79 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace App\Support\Legacy;
|
|
|
|
use App\Enums\Role;
|
|
|
|
/**
|
|
* Pemetaan akun SIAKAD lama ke role baru. Role bawaan = prioritas tertinggi (pemilih peran dapat beralih ke role lain milik akun), 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;
|
|
|
|
/**
|
|
* Role bawaan akun (yang pertama dari all()). 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
|
|
{
|
|
return self::all($jenis, $otoritas, $isDosen)[0] ?? null;
|
|
}
|
|
|
|
/**
|
|
* Semua role yang boleh dipakai akun (untuk pemilih peran), berurutan menurut prioritas: superuser, admin, staf (operator),
|
|
* dosen, lalu operator karena otoritas lain. Tiap role hanya muncul bila akun memang punya otoritasnya.
|
|
*
|
|
* @param list<int> $otoritas
|
|
* @return list<Role>
|
|
*/
|
|
public static function all(int $jenis, array $otoritas, bool $isDosen): array
|
|
{
|
|
if ($jenis === self::JENIS_MAHASISWA) {
|
|
return [Role::Mahasiswa];
|
|
}
|
|
|
|
if ($jenis !== self::JENIS_PEGAWAI) {
|
|
return [];
|
|
}
|
|
|
|
$known = [...self::SUPERUSER, ...self::ADMIN, ...self::OPERATOR, self::DOSEN];
|
|
|
|
$roles = array_filter([
|
|
self::hasAny($otoritas, self::SUPERUSER) ? Role::Superuser : null,
|
|
self::hasAny($otoritas, self::ADMIN) ? Role::Admin : null,
|
|
self::hasAny($otoritas, self::OPERATOR) ? Role::Operator : null,
|
|
$isDosen || in_array(self::DOSEN, $otoritas, true) ? Role::Dosen : null,
|
|
array_diff($otoritas, $known) !== [] ? Role::Operator : null,
|
|
]);
|
|
|
|
return array_values(array_unique($roles, SORT_REGULAR));
|
|
}
|
|
|
|
/**
|
|
* @param list<int> $otoritas
|
|
* @param list<int> $ids
|
|
*/
|
|
private static function hasAny(array $otoritas, array $ids): bool
|
|
{
|
|
return array_intersect($otoritas, $ids) !== [];
|
|
}
|
|
}
|