This commit is contained in:
Paula Quispe
2019-05-13 16:44:40 -04:00
parent 4064c1bebf
commit ff33075228
14 changed files with 1655 additions and 303 deletions

View File

@@ -2,13 +2,13 @@
namespace ProcessMaker\BusinessModel;
use \G;
use \Criteria;
use \UsersPeer;
use \PMLicensedFeatures;
use G;
use Criteria;
use PMLicensedFeatures;
use ProcessMaker\Model\Delegation;
use UsersPeer;
/**
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
* @copyright Colosa - Bolivia
*/
class Lists
@@ -258,6 +258,7 @@ class Lists
/**
* Get counters for lists
*
* @param $userId
* @return array
*/
@@ -271,6 +272,13 @@ class Lists
$total = $this->$listObject->getCountList($userId, array('action' => 'draft'));
array_push($response, (array('count' => $total, 'item' => $item)));
break;
case 'ListSelfService':
$total = Delegation::countSelfService($userId);
array_push($response, ([
'count' => $total,
'item' => $item
]));
break;
/*----------------------------------********---------------------------------*/
case 'ListConsolidated':
$licensedFeatures = PMLicensedFeatures::getSingleton();

View File

@@ -10,5 +10,63 @@ class AppAssignSelfServiceValue extends Model
protected $primaryKey = 'ID';
// We do not have create/update timestamps for this table
public $timestamps = false;
/**
* Return the case number this belongs to
*/
public function appNumber()
{
return $this->belongsTo(Delegation::class, 'APP_NUMBER', 'APP_NUMBER');
}
/**
* Return the index this belongs to
*/
public function index()
{
return $this->belongsTo(Delegation::class, 'DEL_INDEX', 'DEL_INDEX');
}
/**
* Return the task this belongs to
*/
public function task()
{
return $this->belongsTo(Task::class, 'TAS_ID', 'TAS_ID');
}
/**
* Get cases with assignment Self-Service Value Based
*
* @param string $usrUid
*
* @return array
*/
public static function getSelfServiceCasesByEvaluatePerUser($usrUid)
{
//Get the groups related to the user
$groups = GroupUser::getGroups($usrUid);
// Build query
$query = AppAssignSelfServiceValue::query()->select();
$query->join('APP_ASSIGN_SELF_SERVICE_VALUE_GROUP', function ($join) {
$join->on('APP_ASSIGN_SELF_SERVICE_VALUE.ID', '=', 'APP_ASSIGN_SELF_SERVICE_VALUE_GROUP.ID');
});
$query->where(function ($query) use ($usrUid, $groups) {
//Filtering the user assigned in the task
$query->where('APP_ASSIGN_SELF_SERVICE_VALUE_GROUP.GRP_UID', '=', $usrUid);
if (!empty($groups)) {
//Consider the group related to the user
$query->orWhere(function ($query) use ($groups) {
$query->whereIn('APP_ASSIGN_SELF_SERVICE_VALUE_GROUP.ASSIGNEE_ID', $groups);
$query->where('APP_ASSIGN_SELF_SERVICE_VALUE_GROUP.ASSIGNEE_TYPE', '=', 2);
});
}
});
$query->distinct();
$result = $query->get()->values()->toArray();
return $result;
}
}

View File

@@ -9,5 +9,13 @@ class AppAssignSelfServiceValueGroup extends Model
protected $table = 'APP_ASSIGN_SELF_SERVICE_VALUE_GROUP';
// We do not have create/update timestamps for this table
public $timestamps = false;
/**
* Return the appSelfServiceValue this belongs to
*/
public function appSelfService()
{
return $this->belongsTo(AppAssignSelfServiceValue::class, 'ID', 'ID');
}
}

View File

@@ -58,6 +58,79 @@ class Delegation extends Model
return $query->where('APP_UID', '=', $appUid);
}
/**
* Scope a query to only include open threads
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeIsThreadOpen($query)
{
return $query->where('DEL_THREAD_STATUS', '=', 'OPEN');
}
/**
* Scope a query to only include threads without user
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeNoUserInThread($query)
{
return $query->where('USR_ID', '=', 0);
}
/**
* Scope a query to only include specific tasks
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param array $tasks
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeTasksIn($query, array $tasks)
{
return $query->whereIn('APP_DELEGATION.TAS_ID', $tasks);
}
/**
* Scope a query to only include a specific case
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param integer $appNumber
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeCase($query, $appNumber)
{
return $query->where('APP_NUMBER', '=', $appNumber);
}
/**
* Scope a query to only include a specific index
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param integer $index
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeIndex($query, $index)
{
return $query->where('DEL_INDEX', '=', $index);
}
/**
* Scope a query to only include a specific task
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param integer $task
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeTask($query, $task)
{
return $query->where('APP_DELEGATION.TAS_ID', '=', $task);
}
/**
* Searches for delegations which match certain criteria
*
@@ -389,4 +462,47 @@ class Delegation extends Model
return $arrayData;
}
/**
* Count the self-services cases by user
*
* @param string $usrUid
*
* @return integer
*/
public static function countSelfService($usrUid)
{
//Get the task self services related to the user
$taskSelfService = TaskUser::getSelfServicePerUser($usrUid);
//Get the task self services value based related to the user
$selfServiceValueBased = AppAssignSelfServiceValue::getSelfServiceCasesByEvaluatePerUser($usrUid);
//Start the query for get the cases related to the user
$query = Delegation::query()->select('APP_NUMBER');
//Add Join with task filtering only the type self-service
$query->join('TASK', function ($join) {
$join->on('APP_DELEGATION.TAS_ID', '=', 'TASK.TAS_ID')
->where('TASK.TAS_ASSIGN_TYPE', '=', 'SELF_SERVICE');
});
//Filtering the open threads and without users
$query->isThreadOpen()->noUserInThread();
//Get the cases unassigned
if (!empty($selfServiceValueBased)) {
$query->where(function ($query) use ($selfServiceValueBased, $taskSelfService) {
//Get the cases related to the task self service
$query->tasksIn($taskSelfService);
foreach ($selfServiceValueBased as $case) {
//Get the cases related to the task self service value based
$query->orWhere(function ($query) use ($case) {
$query->case($case['APP_NUMBER'])->index($case['DEL_INDEX'])->task($case['TAS_ID']);
});
}
});
} else {
//Get the cases related to the task self service
$query->tasksIn($taskSelfService);
}
return $query->count();
}
}

View File

@@ -9,5 +9,53 @@ class GroupUser extends Model
protected $table = 'GROUP_USER';
// We do not have create/update timestamps for this table
public $timestamps = false;
/**
* Return the user this belongs to
*/
public function user()
{
return $this->belongsTo(User::class, 'USR_UID', 'USR_UID');
}
/**
* Return the group user this belongs to
*/
public function groupsWf()
{
return $this->belongsTo(Groupwf::class, 'GRP_ID', 'GRP_ID');
}
/**
* Scope a query to specific user
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param string $user
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeUser($query, $user)
{
return $query->where('USR_UID', '=', $user);
}
/**
* Return the groups from a user
*
* @param string $usrUid
* @param string $column
*
* @return array
*/
public static function getGroups($usrUid, $column = 'GRP_ID')
{
$groups = GroupUser::query()->select(['GROUP_USER.' . $column])
->join('GROUPWF', function ($join) use ($usrUid) {
$join->on('GROUPWF.GRP_ID', '=', 'GROUP_USER.GRP_ID')
->where('GROUPWF.GRP_STATUS', 'ACTIVE')
->where('GROUP_USER.USR_UID', $usrUid);
})->get()->values()->toArray();
return $groups;
}
}

View File

@@ -10,5 +10,24 @@ class Groupwf extends Model
protected $primaryKey = 'GRP_ID';
// We do not have create/update timestamps for this table
public $timestamps = false;
/**
* Scope a query to active groups
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeActive($query)
{
return $query->where('GRP_STATUS', '=', 'ACTIVE');
}
/**
* Return the user this belongs to
*/
public function groupUsers()
{
return $this->belongsTo(GroupUser::class, 'GRP_ID', 'GRP_ID');
}
}

View File

@@ -35,6 +35,57 @@ class ListUnassigned extends Model
return $this->belongsTo(Process::class, 'PRO_ID', 'PRO_ID');
}
/**
* Scope a query to only include specific tasks
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param array $tasks
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeTasksIn($query, array $tasks)
{
return $query->whereIn('TAS_ID', $tasks);
}
/**
* Scope a query to only include a specific case
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param integer $appNumber
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeCase($query, $appNumber)
{
return $query->where('APP_NUMBER', '=', $appNumber);
}
/**
* Scope a query to only include a specific index
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param integer $index
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeIndex($query, $index)
{
return $query->where('DEL_INDEX', '=', $index);
}
/**
* Scope a query to only include a specific task
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param integer $task
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeTask($query, $task)
{
return $query->where('TAS_ID', '=', $task);
}
/**
* Get count
*
@@ -51,6 +102,43 @@ class ListUnassigned extends Model
return $result;
}
/**
* Count the self-services cases by user
*
* @param string $usrUid
*
* @return integer
*/
public static function countSelfService($usrUid)
{
//Get the task self services related to the user
$taskSelfService = TaskUser::getSelfServicePerUser($usrUid);
//Get the task self services value based related to the user
$selfServiceValueBased = AppAssignSelfServiceValue::getSelfServiceCasesByEvaluatePerUser($usrUid);
//Start the query for get the cases related to the user
$query = ListUnassigned::query()->select('APP_NUMBER');
//Get the cases unassigned
if (!empty($selfServiceValueBased)) {
$query->where(function ($query) use ($selfServiceValueBased, $taskSelfService) {
//Get the cases related to the task self service
$query->tasksIn($taskSelfService);
foreach ($selfServiceValueBased as $case) {
//Get the cases related to the task self service value based
$query->orWhere(function ($query) use ($case) {
$query->case($case['APP_NUMBER'])->index($case['DEL_INDEX'])->task($case['TAS_ID']);
});
}
});
} else {
//Get the cases related to the task self service
$query->tasksIn($taskSelfService);
}
return $query->count();
}
/**
* Search data
*

View File

@@ -20,4 +20,16 @@ class Task extends Model
{
return $this->hasMany(Delegation::class, 'TAS_ID', 'TAS_ID');
}
/**
* Scope a query to only include self-service
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeIsSelfService($query)
{
return $query->where('TAS_ASSIGN_TYPE', '=', 'SELF_SERVICE')
->where('TAS_GROUP_VARIABLE', '=', '');
}
}

View File

@@ -9,4 +9,64 @@ class TaskUser extends Model
protected $table = 'TASK_USER';
public $timestamps = false;
/**
* 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
$query = Task::query()->select('TAS_ID');
//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;
}
}

View File

@@ -7,6 +7,7 @@ use Illuminate\Database\Eloquent\Model;
class User extends Model
{
protected $table = "USERS";
protected $primaryKey = 'USR_ID';
// Our custom timestamp columns
const CREATED_AT = 'USR_CREATE_DATE';
const UPDATED_AT = 'USR_UPDATE_DATE';
@@ -18,4 +19,24 @@ class User extends Model
{
return $this->hasMany(Delegation::class, 'USR_ID', 'USR_ID');
}
/**
* 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();
}
}