<?php
namespace App\Models\common;

use CodeIgniter\Model;
class MenuModel extends Model
{
    // 메뉴목록조회
    public function getMenuList($usrLevel)
    {
        $sql = "SELECT a.mnu_id, a.mnu_pid, a.mnu_nm, a.mnu_url 
                FROM menu AS a
                JOIN menu_perms AS b ON b.mnu_id = a.mnu_id
                WHERE a.use_yn = 'Y' 
                AND b.mgrp_sq = ?
                AND a.mnu_pid = '0'
                ORDER BY a.view_odr ASC
                ";

        $query = $this->db->query($sql, binds: [$usrLevel]);
        $mainMenuList = $query->getResultArray();

        $sql = "SELECT a.mnu_id, a.mnu_pid, a.mnu_nm, a.mnu_url 
                FROM menu AS a
                JOIN menu_perms AS b ON b.mnu_id = a.mnu_id
                WHERE a.use_yn = 'Y' 
                AND b.mgrp_sq = ?
                ORDER BY a.view_odr ASC
                ";

        $query = $this->db->query($sql, [$usrLevel]);
        $subMenuList = $query->getResultArray();

        $data = [
            'mainMenu' => $mainMenuList,
            'subMenu' => $subMenuList,
        ];

        return $data;
    }
}