Files
2026-03-26 09:28:14 +07:00

72 lines
3.0 KiB
PHP

<?php
use App\Models\User;
use App\Models\Role;
if (!function_exists('constructMenuLeft')) {
function constructMenuLeft($type, $user_id = '')
{
$result_data = [];
if ($type == 'backend_menu') {
$data = User::leftJoin('user_roles as user_role', 'users.id', '=', 'user_role.user_id')
->leftJoin('roles as role', 'user_role.role_id', '=', 'role.id')
->where('users.id', $user_id)
->where('role.is_menu_backend', 1)
->where('role_status', 1)
->select('role.*')
->orderBy('role.role_order', 'asc')->orderBy('role.role_name', 'asc')->get();
foreach ($data as $item) {
$result_data[] = Array(
'route' => $item['role_route'],
'menu_name' => $item['role_name'],
'icon' => $item['role_icon']
);
}
return $result_data;
} else if ($type == 'frontend_menu') {
$data = Role::where('is_menu_frontend', 1)
->where('role_status', 1)
->orderBy('role_order', 'asc')->orderBy('role_name', 'asc')->get();
foreach ($data as $item) {
$result_data[] = Array(
'route' => $item['role_route'],
'role_div_id' => $item['role_div_id'],
'menu_name' => $item['role_name'],
'role_param' => $item['role_param'],
'icon' => $item['icon']
);
}
return $result_data;
}
}
}
if (!function_exists('formatStringToUrl')) {
function formatStringToUrl($str)
{
$unicode = array(
'a'=>'á|à|ả|ã|ạ|ă|ắ|ặ|ằ|ẳ|ẵ|â|ấ|ầ|ẩ|ẫ|ậ',
'd'=>'đ',
'e'=>'é|è|ẻ|ẽ|ẹ|ê|ế|ề|ể|ễ|ệ',
'i'=>'í|ì|ỉ|ĩ|ị',
'o'=>'ó|ò|ỏ|õ|ọ|ô|ố|ồ|ổ|ỗ|ộ|ơ|ớ|ờ|ở|ỡ|ợ',
'u'=>'ú|ù|ủ|ũ|ụ|ư|ứ|ừ|ử|ữ|ự',
'y'=>'ý|ỳ|ỷ|ỹ|ỵ',
'A'=>'Á|À|Ả|Ã|Ạ|Ă|Ắ|Ặ|Ằ|Ẳ|Ẵ|Â|Ấ|Ầ|Ẩ|Ẫ|Ậ',
'D'=>'Đ',
'E'=>'É|È|Ẻ|Ẽ|Ẹ|Ê|Ế|Ề|Ể|Ễ|Ệ',
'I'=>'Í|Ì|Ỉ|Ĩ|Ị',
'O'=>'Ó|Ò|Ỏ|Õ|Ọ|Ô|Ố|Ồ|Ổ|Ỗ|Ộ|Ơ|Ớ|Ờ|Ở|Ỡ|Ợ',
'U'=>'Ú|Ù|Ủ|Ũ|Ụ|Ư|Ứ|Ừ|Ử|Ữ|Ự',
'Y'=>'Ý|Ỳ|Ỷ|Ỹ|Ỵ',
);
foreach($unicode as $nonUnicode=>$uni){
$str = preg_replace("/($uni)/i", $nonUnicode, $str);
}
$str = str_replace(' ','_',$str);
$str = str_replace(',','',$str);
return trim(strtolower($str));
}
}