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

72 lines
2.1 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
/**
* 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');
}
/**
* 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');
2019-05-13 16:44:40 -04:00
//Add Join with process filtering only the active process
$query->join('PROCESS', function ($join) {
$join->on('PROCESS.PRO_UID', '=', 'TASK.PRO_UID')
->where('PROCESS.PRO_STATUS', 'ACTIVE');
});
//Add join with with the task users
$query->join('TASK_USER', function ($join) {
$join->on('TASK.TAS_UID', '=', 'TASK_USER.TAS_UID')
//We not considered the Ad-hoc
->where('TASK_USER.TU_TYPE', '=', 1);
});
//Filtering only the task self-service
$query->isSelfService();
//Filtering the task related to the user
$query->where(function ($query) use ($usrUid, $groups) {
//Filtering the user assigned in the task
$query->where('TASK_USER.USR_UID', '=', $usrUid);
if (!empty($groups)) {
//Consider the group related to the user
$query->orWhere(function ($query) use ($groups) {
$query->whereIn('TASK_USER.USR_UID', $groups);
});
}
});
$query->distinct();
$tasks = $query->get()->values()->toArray();
return $tasks;
}
2019-04-25 19:11:37 -04:00
}