Initial commit BIJ CI4

This commit is contained in:
BIJ Dev
2026-04-21 05:49:17 +07:00
commit fa38ac6b24
13170 changed files with 866701 additions and 0 deletions

0
app/Helpers/.gitkeep Normal file
View File

View File

@@ -0,0 +1,93 @@
<?php
declare(strict_types=1);
if (! function_exists('cuti_tanggal_label')) {
/**
* Label tanggal cuti untuk tampilan admin (d/m/Y). Nilai tidak valid → tanda em dash.
* Menerima string (Y-m-d, ISO datetime, d/m/Y), DateTimeInterface, angka 8 digit yyyymmdd, atau array hasil JSON aneh.
*/
function cuti_tanggal_label(mixed $raw): string
{
if ($raw === null || $raw === '') {
return '—';
}
if (is_array($raw)) {
$raw = $raw['date'] ?? $raw['value'] ?? null;
if ($raw === null || $raw === '') {
return '—';
}
}
if ($raw instanceof \DateTimeInterface) {
return $raw->format('d/m/Y');
}
if (is_object($raw) && ! $raw instanceof \Stringable) {
return '—';
}
if ($raw instanceof \Stringable) {
$raw = (string) $raw;
}
if (is_int($raw)) {
$s = (string) $raw;
if (strlen($s) === 8 && preg_match('/^\d{8}$/', $s)) {
$y = substr($s, 0, 4);
$m = substr($s, 4, 2);
$d = substr($s, 6, 2);
$ts = strtotime($y . '-' . $m . '-' . $d);
return $ts !== false ? date('d/m/Y', $ts) : '—';
}
return '—';
}
if (is_float($raw)) {
return '—';
}
if (! is_string($raw)) {
return '—';
}
$s = trim($raw);
if ($s === '' || str_starts_with($s, '0000-00-00')) {
return '—';
}
if (preg_match('/^(\d{4}-\d{1,2}-\d{1,2})/', $s, $m)) {
$ts = strtotime($m[1]);
if ($ts !== false) {
return date('d/m/Y', $ts);
}
}
foreach (['!d/m/Y', '!d-m-Y', '!j/n/Y', '!j-n-Y'] as $fmt) {
$dt = \DateTimeImmutable::createFromFormat($fmt, $s);
if ($dt instanceof \DateTimeImmutable) {
return $dt->format('d/m/Y');
}
}
$ts = strtotime($s);
return $ts !== false ? date('d/m/Y', $ts) : '—';
}
}
if (! function_exists('cuti_tanggal_label_from_row')) {
/**
* Ambil tanggal cuti dari baris API/DB (kunci case-insensitive + fallback kolom umum).
*/
function cuti_tanggal_label_from_row(array $row): string
{
$lower = array_change_key_case($row, CASE_LOWER);
$raw = $lower['tanggal_cuti'] ?? $lower['tanggal'] ?? $lower['tgl_cuti'] ?? null;
return cuti_tanggal_label($raw);
}
}

104
app/Helpers/rbac_helper.php Normal file
View File

@@ -0,0 +1,104 @@
<?php
declare(strict_types=1);
use Config\AdminAccess;
if (! function_exists('admin_ion_roles')) {
/**
* Nama grup Ion dari sesi (sudah dinormalisasi string).
*
* @return list<string>
*/
function admin_ion_roles(): array
{
$raw = session()->get('admin_ion_groups');
if (! is_array($raw)) {
return [];
}
$out = [];
foreach ($raw as $g) {
$s = strtolower(trim((string) $g));
if ($s !== '') {
$out[] = $s;
}
}
return array_values(array_unique($out));
}
}
if (! function_exists('rbac_enforce_ion')) {
/**
* Grup Ion hanya relevan bila login dari tabel admin_users (Ion Auth).
* Login `pegawai` saja (tanpa admin terhubung) memakai {@see AdminAccess::$pegawaiPanelFeatures}.
*/
function rbac_enforce_ion(): bool
{
return session()->get('admin_auth_source') === 'admin_users';
}
}
if (! function_exists('hasRole')) {
function hasRole(string $role): bool
{
$want = strtolower(trim($role));
if ($want === '') {
return false;
}
foreach (admin_ion_roles() as $g) {
if ($g === $want) {
return true;
}
}
return false;
}
}
if (! function_exists('hasAnyRole')) {
/**
* @param list<string>|array<int, string> $roles
*/
function hasAnyRole(array $roles): bool
{
foreach ($roles as $r) {
if (hasRole((string) $r)) {
return true;
}
}
return false;
}
}
if (! function_exists('canAccess')) {
/**
* Cek akses fitur berdasarkan `Config\AdminAccess::$features`.
*/
function canAccess(string $feature): bool
{
/** @var AdminAccess $cfg */
$cfg = config('AdminAccess');
if (! isset($cfg->features[$feature])) {
return false;
}
if (! rbac_enforce_ion()) {
return in_array($feature, $cfg->pegawaiPanelFeatures, true);
}
$required = $cfg->features[$feature];
if ($required === []) {
return true;
}
if (admin_ion_roles() === []) {
return false;
}
return hasAnyRole($required);
}
}