PMC-119
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace ProcessMaker\Model;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Exception;
|
||||
|
||||
class User extends Model
|
||||
{
|
||||
@@ -39,4 +40,26 @@ class User extends Model
|
||||
{
|
||||
return User::find($usrUid)->groups()->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope for the specified user
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param array $filters
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
* @throws Exception
|
||||
*/
|
||||
public function scopeUserFilters($query, array $filters)
|
||||
{
|
||||
if (!empty($filters['USR_ID'])) {
|
||||
$query->where('USR_ID', $filters['USR_ID']);
|
||||
} elseif (!empty($filters['USR_UID'])) {
|
||||
$query->where('USR_UID', $filters['USR_UID']);
|
||||
} else {
|
||||
throw new Exception("There are no filter for loading a user model");
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
use Illuminate\Session\TokenMismatchException;
|
||||
use Illuminate\Support\Str;
|
||||
use ProcessMaker\Model\User;
|
||||
|
||||
/**
|
||||
* We will send a case note in the actions by email
|
||||
@@ -493,3 +494,29 @@ if (!function_exists('set_magic_quotes_runtime')) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the USER table with the last login date
|
||||
*
|
||||
* @param array $userLog
|
||||
* @return int
|
||||
* @throws Exception
|
||||
*
|
||||
* @see workflow/engine/methods/login/authentication.php
|
||||
*/
|
||||
function updateUserLastLogin($userLog, $keyLastLogin = 'LOG_INIT_DATE')
|
||||
{
|
||||
try {
|
||||
$filters = [];
|
||||
$filters['USR_UID'] = $userLog['USR_UID'];
|
||||
|
||||
$user = User::query();
|
||||
$user->userFilters($filters);
|
||||
$res = $user->update(['USR_LAST_LOGIN' => $userLog[$keyLastLogin]]);
|
||||
|
||||
return $res;
|
||||
} catch (Exception $e) {
|
||||
throw new Exception($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user