118 lines
3.0 KiB
PHP
118 lines
3.0 KiB
PHP
<?php
|
|
|
|
namespace App;
|
|
|
|
use Illuminate\Notifications\Notifiable;
|
|
use Illuminate\Contracts\Auth\MustVerifyEmail;
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
|
use App\Department;
|
|
use DB;
|
|
|
|
class User extends Authenticatable
|
|
{
|
|
use Notifiable;
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $fillable = [
|
|
'parent_id',
|
|
'department_id',
|
|
'first_name',
|
|
'last_name',
|
|
'email',
|
|
'username',
|
|
'password',
|
|
'cell_phone_number',
|
|
'profile_picture',
|
|
'home_address',
|
|
'status',
|
|
'working_status',
|
|
'is_log_in',
|
|
'user_language',
|
|
'user_disk_quota',
|
|
'user_disk_uses',
|
|
];
|
|
|
|
/**
|
|
* The attributes that should be hidden for arrays.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $hidden = [
|
|
'password', 'remember_token',
|
|
];
|
|
|
|
/**
|
|
* The attributes that should be cast to native types.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $casts = [
|
|
'email_verified_at' => 'datetime',
|
|
];
|
|
|
|
|
|
public function role_user()
|
|
{
|
|
return $this->hasMany(RoleUser::class);
|
|
}
|
|
|
|
public function getFullName()
|
|
{
|
|
return $this->first_name . " " . $this->last_name;
|
|
}
|
|
|
|
public function getDepartmentName()
|
|
{
|
|
$department = Department::find($this->department_id);
|
|
if($department != null)
|
|
return $department->name;
|
|
|
|
return '';
|
|
}
|
|
|
|
public function getProfilePicture()
|
|
{
|
|
return ($this->profile_picture && trim($this->profile_picture)!='' && file_exists(public_path('uploads/user_folder/'.$this->profile_picture))) ? $this->profile_picture : 'male.png';
|
|
}
|
|
|
|
public function getPermissionList()
|
|
{
|
|
$results = DB::select('select u.id, p.permission_ids from users u, role_user r, permission_role p where u.id=r.user_id and r.role_id=p.role_id and u.id=? and u.department_id=p.department_id', [$this->id]);
|
|
|
|
$res = [];
|
|
foreach($results as $result)
|
|
{
|
|
$permission_ia = json_decode($result->permission_ids);
|
|
$permission_id = json_decode($result->permission_ids);
|
|
foreach($permission_id as $pid)
|
|
array_push($res, $pid);
|
|
|
|
foreach($permission_ia as $pid)
|
|
array_push($res, $pid);
|
|
}
|
|
|
|
return array_unique($res);
|
|
}
|
|
|
|
public static function getUserRole()
|
|
{
|
|
return User::join('role_user', 'users.id', '=', 'role_user.user_id')
|
|
->join('roles', 'role_user.role_id', '=', 'roles.id')
|
|
->where('users.working_status', '=', '1')
|
|
->where('users.status', '=', '1')
|
|
->select('users.*', 'roles.name as role_name', 'roles.id as role_id', 'users.id as id')
|
|
->orderBy('roles.id', 'asc');
|
|
}
|
|
|
|
public static function getUserDocument()
|
|
{
|
|
return User::join('role_user', 'users.id', '=', 'role_user.user_id')
|
|
->join('roles', 'role_user.role_id', '=', 'roles.id')
|
|
->select('users.*', 'roles.name as role_name', 'roles.id as role_id', 'users.id as id');
|
|
}
|
|
}
|