Files
luos/workflow/engine/src/ProcessMaker/Model/TaskUser.php

118 lines
3.2 KiB
PHP
Raw Normal View History

2019-04-25 19:11:37 -04:00
<?php
namespace ProcessMaker\Model;
use Illuminate\Database\Eloquent\Model;
class TaskUser extends Model
{
protected $table = 'TASK_USER';
public $timestamps = false;
2019-05-13 16:44:40 -04:00
2021-03-24 09:31:35 -04:00
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'TAS_UID',
'TAS_ID',
'USR_UID',
'TU_TYPE',
'TU_RELATION',
'ASSIGNED_ID',
];
2019-05-13 16:44:40 -04:00
/**
* Return the task this belongs to
*/
public function task()
{
return $this->belongsTo(Task::class, 'TAS_UID', 'TAS_UID');
}
/**
* Return the user this belongs to
*/
public function user()
{
return $this->belongsTo(User::class, 'USR_UID', 'USR_UID');
}
2021-03-24 09:31:35 -04:00
/**
* Scope for query to get the assigment
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param string $tasUid
* @param string $usrUid
* @param integer $type
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeAssigment($query, $tasUid, $usrUid, $type = 1)
{
return $query->where('TAS_UID', $tasUid)->where('USR_UID', $usrUid)->where('TU_TYPE', $type);
}
2019-05-13 16:44:40 -04:00
/**
* Get the task self services related to the user
*
* @param string $usrUid
*
* @return array
*/
public static function getSelfServicePerUser($usrUid)
{
//Get the groups related to the user
$groups = GroupUser::getGroups($usrUid, 'GRP_UID');
// Build query
2019-07-23 14:23:59 -04:00
$query = Task::query()->select('TASK.TAS_ID');
2021-03-30 10:03:46 -04:00
// Add Join with process filtering only the active process
$query->leftJoin('PROCESS', function ($join) {
2019-05-13 16:44:40 -04:00
$join->on('PROCESS.PRO_UID', '=', 'TASK.PRO_UID')
->where('PROCESS.PRO_STATUS', 'ACTIVE');
});
2021-03-30 10:03:46 -04:00
// Add join with with the task users
$query->leftJoin('TASK_USER', function ($join) {
2019-05-13 16:44:40 -04:00
$join->on('TASK.TAS_UID', '=', 'TASK_USER.TAS_UID')
2021-03-30 10:03:46 -04:00
// We not considered the Ad-hoc
2019-05-13 16:44:40 -04:00
->where('TASK_USER.TU_TYPE', '=', 1);
});
2021-03-30 10:03:46 -04:00
// Filtering only the task self-service
2019-05-13 16:44:40 -04:00
$query->isSelfService();
2021-03-30 10:03:46 -04:00
// Filtering the task related to the user
2019-05-13 16:44:40 -04:00
$query->where(function ($query) use ($usrUid, $groups) {
2021-03-30 10:03:46 -04:00
// Filtering the user assigned in the task
2019-05-13 16:44:40 -04:00
$query->where('TASK_USER.USR_UID', '=', $usrUid);
if (!empty($groups)) {
2021-03-30 10:03:46 -04:00
// Consider the group related to the user
2019-05-13 16:44:40 -04:00
$query->orWhere(function ($query) use ($groups) {
$query->whereIn('TASK_USER.USR_UID', $groups);
});
}
});
$query->distinct();
$tasks = $query->get()->values()->toArray();
return $tasks;
}
2021-03-24 09:31:35 -04:00
/**
* Get the specific assigment related to the task, by default the normal assigment
*
* @param string $tasUid
* @param string $uid
* @param integer $type, can be 1 = Normal or 2 = Ad-hoc
*
* @return array
*/
public static function getAssigment($tasUid, $uid, $type = 1)
{
$query = TaskUser::query()->select()
->assigment($tasUid, $uid, $type);
$result = $query->get()->toArray();
return head($result);
}
2019-04-25 19:11:37 -04:00
}