$request->route()->getAction('prefix'), 'task' => taskLabel($request->route()->getActionMethod()), 'user_id' => session('uid'), 'ipaddress' => $request->getClientIp(), 'useragent' => $request->header('User-Agent'), 'note' => $note, 'created_at' => \Carbon\Carbon::now() ]; if (session('superuser') == false) $repository->create($data); } } if (!function_exists('trimId')) { /** * @param $val * @return array */ function trimId($val) { $string = explode('+', $val); return $string; } } if (!function_exists('dateTime')) { /** * make secure id * * @param string|null $val * * @return string */ function dateTime($date) { return date('d-m-Y H:i:s',strtotime(@$date)); } } if (!function_exists('encode_id')) { /** * make secure id * * @param string|null $val * * @return string */ function encode_id(?string $val = ''): string { $params = ['val' => $val]; return rtrim(base64_encode(serialize($params)), "="); } } if (!function_exists('decode_id')) { /** * @param string|null $val * ${STATIC} * * @return mixed|null * @author alex.gz * @created 02/12/2023 4:28 * */ function decode_id(?string $val = ''): mixed { $secure = unserialize(base64_decode($val)); return $secure ? $secure['val'] : null; } } if (!function_exists('permission')) { /** * @param $access * @param $key * @param string $method * @param bool $view * * @return mixed */ function permission($access, $key, string $method = 'menu', bool $view = false): mixed { if (@session('group_id') != 1) { if ($method == 'module') { if (is_array($access)) { $model = AccessMenu::where('module', 'LIKE', "{$key}%")->where('ms_group_id', session('group_id'))->first(); $query = count(array_intersect((array)$access, (array)$model->access)); } else { $query = AccessMenu::where($access, true)->where('module', 'LIKE', $key.'%')->where('ms_group_id', session('group_id'))->count(); if ($query > 0) { return true; } else { return abort('401'); } } } else { $query = AccessMenu::where($access, true)->where('ms_menu_id', $key)->where('ms_group_id', session('group_id'))->count(); } if ($query > 0) { return true; } else { return false; } } else { return true; } } } if (!function_exists('access')) { /** * @param $access * @param $key * * @return bool */ function access($access, $key) { if (session('group_alias') != 'administrator') { $query = AccessMenu::where($access, 1)->where('module', $key)->where('ms_group_id', session('group_id'))->count(); if ($query > 0) { return true; } else if (session('group_alias') == 'administrator') { return true; } else { return false; } } else { return true; } } } if (!function_exists('activeMenuClass')) { /** * Helper to grab the application version. * * @return mixed */ function activeMenuClass($route){ // dd(request()->route()->getName()); // if(request()->route()->getName() == $route){ // return true; // }else{ // return false; // } if (\Str::is($route, request()->route()->getName())) { return true; } else { return false; } } } if (!function_exists('renderMenu')) { /** * Loops through a folder and requires all PHP files * Searches sub-directories as well. * * @param $folder */ function renderMenu() { $parent = Menu::where('status',true)->where('menu_type','sidebar')->where('parent_id',0)->orderBy('ordering','ASC')->get(); $html = ''; foreach ($parent as $p1) { // echo $p1->MsMenuId.'
'; $child2 = Menu::where('status',true)->where('menu_type','sidebar')->where('parent_id',$p1->MsMenuId)->get(); $access1 = permission('is_read', $p1->MsMenuId, 'menu', true); $ch1 = count($child2) > 0 ? '' : ''; $link1 = count($child2) > 0 ? '' : 'menu-link'; $collapse1 = count($child2) > 0 ? 'data-fc-type="collapse"' : ''; $active = activeMenuClass($p1->module) ? 'active' : ''; // dd($p1->route); if ($access1) { $active1 = activeMenuClass($p1->module) ? 'active' : ''; $html .= ''; } } return $html; } } if (!function_exists('include_route_files')) { /** * Loops through a folder and requires all PHP files * Searches sub-directories as well. * * @param $folder */ function include_route_files($folder) { include_files_in_folder($folder); } } if (!function_exists('include_files_in_folder')) { /** * Loops through a folder and requires all PHP files * Searches sub-directories as well. * * @param $folder */ function include_files_in_folder($folder) { try { $rdi = new RecursiveDirectoryIterator($folder); $it = new RecursiveIteratorIterator($rdi); while ($it->valid()) { if (!$it->isDot() && $it->isFile() && $it->isReadable() && $it->current()->getExtension() === 'php') { require $it->key(); } $it->next(); } } catch (Exception $e) { echo $e->getMessage(); } } } if (!function_exists('topikById')) { function topikById($id){ $keyId = decode_id($id); $topik = Topik::find($keyId); return $topik; } } if (!function_exists('topikByDataset')) { function topikByDataset($json){ // $table = Dataset::find($id); $decode = json_decode($json); $res = "Belum ada data"; if(count($decode) > 0){ $res = []; $d = ''; foreach ($decode as $key => $value) { if (($value !== null) && ($value !== "")) { $d .= ''.topikById($value)->name.' '; } } // $d .= ''; array_push($res, $d); $res = implode("", $res); } return $res; } } if (!function_exists('tags')) { function tags($json){ // $table = Dataset::find($id); $decode = json_decode($json); $res = "Belum ada data"; if(count($decode) > 0){ $res = []; $d = ''; foreach ($decode as $key => $value) { if (($value !== null) && ($value !== "")) { $d .= ''.$value.' '; } } // $d .= ''; array_push($res, $d); $res = implode("", $res); } return $res; } }