| 
				Server : Apache System : Linux server.mata-lashes.com 3.10.0-1160.90.1.el7.x86_64 #1 SMP Thu May 4 15:21:22 UTC 2023 x86_64 User : matalashes ( 1004) PHP Version : 8.1.29 Disable Function : NONE Directory : /home/matalashes/public_html/simulasikite.mata-lashes.com/app.bak/Libraries/Ps/  | 
Upload File :  | 
<?php
namespace App\Libraries\Ps;
use App\Models\PsAdmAccess;
use App\Models\PsAdmListmenuParent;
use App\Models\PsAdmListmenuChild;
use App\Models\PsStoreAccess;
use Config\Services;
class Mylibmenu
{
    public static function getAksesListMenu($sess_user_id_name, $sess_role_id_name)
    {
        $myLib = new Mylib();
        $session = Services::session();
        $listMenuParent = new PsAdmListmenuParent();
        $listMenuChild = new PsAdmListmenuChild();
        if ($sess_user_id_name == 'ps_au_id') {
            $dataAkses = new PsAdmAccess();
        } else {
            $dataAkses = new PsStoreAccess();
        }
        $parent = $listMenuParent::get_all();
        $hakakses = $dataAkses::get_by_role_id($session->get($sess_role_id_name));
        $str = '';
        if (isset($hakakses->list) && $hakakses->list != '') {
            $list = explode('~', $hakakses->list);
            $where = ''; //kondisi untuk menentukan jumlah grup parent yang diizinkan
            for ($a = 0; $a < count($list); $a++) {
                if ($list[$a] != '') {
                    if ($a != count($list) - 1) {
                        $where .= ' alc_kode LIKE "' . $list[$a] . '" OR alp_kode LIKE "' . $list[$a] . '" OR ';
                    } else {
                        $where .= ' alc_kode LIKE "' . $list[$a] . '" OR alp_kode LIKE "' . $list[$a] . '"';
                    }
                }
            }
            $allowed_parent = $listMenuParent::get_group_parent_by_alc_kode($where); //jumlah grup parent yang diizinkan
            foreach ($allowed_parent as $p) {
                $hightlight = self::checkListChild($p, $myLib->getOnlyControllersName());
                $str .= '<div data-kt-menu-trigger="click" class="menu-item menu-accordion ' . $hightlight . '">
                            <span class="menu-link">
                                <span class="menu-icon">
                                    <i class="' . $p->alp_fontaw . '"></i>
                                </span>
                                <span class="menu-title">' . $p->alp_nama . '</span>
                                <span class="menu-arrow"></span>
                            </span>';
                $condition = array();   //untuk menampung menu setiap parentnya.
                for ($a = 0; $a < count($list); $a++) {
                    $temp_menu = $listMenuChild::get_by_kode($list[$a]);
                    if ($temp_menu != null) {
                        if ($temp_menu->ps_alp_id == $p->ps_alp_id) {
                            array_push($condition, 'alc_kode LIKE "' . $list[$a] . '"');
                        }
                    }
                }
                $where_query = '';      // build where condition agar setiap parent menampilkan menu yang diperbolehkan
                for ($w = 0; $w < count($condition); $w++) {
                    if ($w != count($condition) - 1) {
                        $where_query .= $condition[$w] . ' OR ';
                    } else {
                        $where_query .= $condition[$w];
                    }
                }
                $where_query .= ' AND ps_adm_listmenu_child.ps_alp_id=' . $p->ps_alp_id;
                $allowed_menu = $listMenuChild::get_by_alc_kode($where_query);
                foreach ($allowed_menu as $dtl) {
                    $hightlight = '';
                    if ($myLib->getOnlyControllersName() == $dtl->alc_url) {
                        $hightlight = 'here show';
                    }
                    $str .= '<div class="menu-sub menu-sub-accordion menu-active-bg">
                                <div class="menu-item ' . $hightlight . '">
                                    <a class="menu-link" href="' . site_url($dtl->alc_basedir . '/' . $dtl->alc_url) . '">
                                        <span class="menu-bullet">
                                            <span class="bullet bullet-dot"></span>
                                        </span>
                                        <span class="menu-title">' . $dtl->alc_nama . '</span>
                                    </a>
                                </div>
                            </div>';
                }
                $str .= '</div>';
            }
        }
        echo $str;
    }
    public static function checkListChild($parent, $url)
    {
        $listMenuChild = new PsAdmListmenuChild();
        $menu = $listMenuChild::get_by_parent($parent->ps_alp_id);
        $hightlight = '';
        foreach ($menu as $m) {
            if ($url == $m->alc_url) {
                $hightlight = 'hover show';
                break;
            }
        }
        return $hightlight;
    }
}