142 lines
3.6 KiB
PHP
142 lines
3.6 KiB
PHP
<?php
|
|
|
|
use App\Directory;
|
|
use App\Absent;
|
|
use App\User;
|
|
use App\PermissionRole;
|
|
|
|
/**
|
|
* Open Translation File
|
|
* @return Response
|
|
*/
|
|
if (! function_exists('check_permissions')) {
|
|
function check_permissions($permission)
|
|
{
|
|
$return_val = false;
|
|
$user = App\User::join('role_user', 'users.id', '=', 'role_user.user_id')
|
|
->join('roles', 'role_user.role_id', '=', 'roles.id')
|
|
->where('users.id', '=', Auth::user()->id)
|
|
->select('users.*', 'roles.name as role_name', 'roles.id as role_id', 'users.id as id')
|
|
->first();
|
|
$permissionRoles = PermissionRole::where('role_id', $user->role_id)
|
|
->where('department_id', $user->department_id)
|
|
->first();
|
|
if($permissionRoles){
|
|
$permission_array = json_decode($permissionRoles->permission_ids, true);
|
|
if(is_array($permission_array)){
|
|
if(in_array($permission, $permission_array)){
|
|
$return_val = true;
|
|
}
|
|
}
|
|
}
|
|
return $return_val;
|
|
}
|
|
}
|
|
if (! function_exists('user_status')) {
|
|
function user_status($user)
|
|
{
|
|
$data=[];
|
|
$absent = Absent::where([
|
|
['user_id', '=', $user->id],
|
|
['start_date', '<=', date('Y-m-d')],
|
|
['end_date', '>=', date('Y-m-d')]
|
|
])->orderBy('start_date','desc')
|
|
->first();
|
|
if(isset($absent) && !empty($absent)){
|
|
$data['status'] = __("Absent");
|
|
$data['class'] = "avatar-away";
|
|
$data['avatar-suffix'] = "away";
|
|
}
|
|
elseif($user->working_status == 0){
|
|
$data['status'] = __("Off");
|
|
$data['class'] = "avatar-off";
|
|
$data['avatar-suffix'] = "off";
|
|
}
|
|
elseif($user->is_log_in == 1){
|
|
$data['status'] = __("Online");
|
|
$data['class'] = "avatar-online";
|
|
$data['avatar-suffix'] = "online";
|
|
}
|
|
else{
|
|
$data['status'] = __("Busy");
|
|
$data['class'] = "avatar-busy";
|
|
$data['avatar-suffix'] = "busy";
|
|
}
|
|
return $data;
|
|
}
|
|
}
|
|
if (! function_exists('previous_route')) {
|
|
/**
|
|
* Generate a route name for the previous request.
|
|
*
|
|
* @return string|null
|
|
*/
|
|
function previous_route()
|
|
{
|
|
$previousRequest = app('request')->create(app('url')->previous());
|
|
|
|
try {
|
|
$routeName = app('router')->getRoutes()->match($previousRequest)->getName();
|
|
} catch (NotFoundHttpException $exception) {
|
|
return null;
|
|
}
|
|
|
|
return $routeName;
|
|
}
|
|
}
|
|
|
|
if (! function_exists('directory_path')) {
|
|
function directory_path($id, $path)
|
|
{
|
|
$directory = Directory::where('id', $id)->first();
|
|
if($directory !== null)
|
|
{
|
|
if($directory->parent_id > 0)
|
|
{
|
|
$directory_path = $directory->name.'/'.$path;
|
|
return directory_path($directory->parent_id, $directory_path);
|
|
}
|
|
else
|
|
{
|
|
return $directory_path = $directory->name.'/'.$path;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
function dataTranslation($data, $vlocale=null){
|
|
$data_val='';
|
|
if(Session::has('locale')){
|
|
$locale = Session::get('locale') ?? Config::get('app.locale');
|
|
}
|
|
else{
|
|
$locale = 'tm';
|
|
}
|
|
$locale = ($vlocale !=null) ? $vlocale: $locale;
|
|
$jsonString = json_decode($data, true);
|
|
if(isset($jsonString[$locale]))
|
|
$data_val = $jsonString[$locale];
|
|
return $data_val;
|
|
}
|
|
|
|
function openJSONFile($code){
|
|
$jsonString = [];
|
|
if(File::exists(base_path('resources/lang/'.$code.'.json'))){
|
|
$jsonString = file_get_contents(base_path('resources/lang/'.$code.'.json'));
|
|
$jsonString = json_decode($jsonString, true);
|
|
}
|
|
return $jsonString;
|
|
}
|
|
|
|
/**
|
|
* Save JSON File
|
|
* @return Response
|
|
*/
|
|
function saveJSONFile($code, $data){
|
|
ksort($data);
|
|
$jsonData = json_encode($data, JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE);
|
|
file_put_contents(base_path('resources/lang/'.$code.'.json'), stripslashes($jsonData));
|
|
}
|
|
|
|
?>
|