2019-04-25 13:47:21 -07:00
|
|
|
<?php
|
|
|
|
|
|
2019-04-25 13:54:39 -07:00
|
|
|
namespace ProcessMaker\Model;
|
2019-04-25 13:47:21 -07:00
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2019-07-05 16:00:43 -04:00
|
|
|
use Exception;
|
2019-04-25 13:47:21 -07:00
|
|
|
|
|
|
|
|
class User extends Model
|
|
|
|
|
{
|
|
|
|
|
protected $table = "USERS";
|
2019-05-13 16:44:40 -04:00
|
|
|
protected $primaryKey = 'USR_ID';
|
2019-04-25 14:15:41 -07:00
|
|
|
// Our custom timestamp columns
|
|
|
|
|
const CREATED_AT = 'USR_CREATE_DATE';
|
|
|
|
|
const UPDATED_AT = 'USR_UPDATE_DATE';
|
2019-04-25 13:47:21 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the delegations this user has (all of them)
|
|
|
|
|
*/
|
|
|
|
|
public function delegations()
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(Delegation::class, 'USR_ID', 'USR_ID');
|
|
|
|
|
}
|
2019-05-13 16:44:40 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return the user this belongs to
|
|
|
|
|
*/
|
|
|
|
|
public function groups()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(GroupUser::class, 'USR_UID', 'USR_UID');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return the groups from a user
|
|
|
|
|
*
|
|
|
|
|
* @param boolean $usrUid
|
|
|
|
|
*
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public static function getGroups($usrUid)
|
|
|
|
|
{
|
|
|
|
|
return User::find($usrUid)->groups()->get();
|
|
|
|
|
}
|
2019-07-05 16:00:43 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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;
|
|
|
|
|
}
|
2019-04-25 13:47:21 -07:00
|
|
|
}
|