PMCORE-2698

This commit is contained in:
Paula Quispe
2021-01-13 12:41:53 -04:00
parent 3c13ad12c8
commit 38adeeadce
5 changed files with 73 additions and 14 deletions

View File

@@ -45,6 +45,19 @@ class User extends Model
return $result;
}
/**
* Scope for query to get the user by USR_ID
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param int $usrId
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeUserId($query, string $usrId)
{
return $query->where('USR_ID', '=', $usrId);
}
/**
* Return the groups from a user
*
@@ -171,6 +184,7 @@ class User extends Model
throw new Exception("Error getting the users: {$e->getMessage()}.");
}
}
/**
* Get the user id
*
@@ -191,4 +205,33 @@ class User extends Model
return $id;
}
/**
* Get user information for the tooltip
*
* @param int $usrId
*
* @return array
*/
public static function getInformation($usrId)
{
$query = User::query()->select([
'USR_USERNAME',
'USR_FIRSTNAME',
'USR_LASTNAME',
'USR_EMAIL',
])
->userId($usrId)
->limit(1);
$results = $query->get();
$info = [];
$results->each(function ($item) use (&$info) {
$info['usr_username'] = $item->USR_USERNAME;
$info['usr_firstname'] = $item->USR_FIRSTNAME;
$info['usr_lastname'] = $item->USR_LASTNAME;
$info['usr_email'] = $item->USR_EMAIL;
});
return $info;
}
}