PMCORE-2614

This commit is contained in:
Paula Quispe
2020-12-22 11:01:49 -04:00
parent 1c36a18904
commit e901f82e6e
5 changed files with 78 additions and 10 deletions

View File

@@ -31,6 +31,20 @@ class User extends Model
return $this->belongsTo(GroupUser::class, 'USR_UID', 'USR_UID');
}
/**
* Scope for query to get the user by USR_UID
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param string $usrUid
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeUser($query, string $usrUid)
{
$result = $query->where('USR_UID', '=', $usrUid);
return $result;
}
/**
* Return the groups from a user
*
@@ -157,4 +171,24 @@ class User extends Model
throw new Exception("Error getting the users: {$e->getMessage()}.");
}
}
/**
* Get the user id
*
* @param string $usrUid
*
* @return int
*/
public static function getId($usrUid)
{
$query = User::query()->select(['USR_ID'])
->user($usrUid)
->limit(1);
$results = $query->get();
$id = 0;
$results->each(function ($item) use (&$id) {
$id = $item->USR_ID;
});
return $id;
}
}