Merged in feature/PMCORE-2537 (pull request #7635)

PMCORE-2537

Approved-by: Julio Cesar Laura Avendaño <contact@julio-laura.com>
This commit is contained in:
Andrea Adamczyk
2020-12-17 21:15:47 +00:00
committed by Julio Cesar Laura Avendaño
3 changed files with 152 additions and 13 deletions

View File

@@ -57,6 +57,36 @@ class Task extends Model
->where('TAS_GROUP_VARIABLE', '=', '');
}
/**
* Scope a query to specific title
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param string $title
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeTitle($query, $title)
{
return $query->where('TAS_TITLE', 'LIKE', "%{$title}%");
}
/**
* Scope a query to include a specific process
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param string $category
* @return \Illuminate\Database\Eloquent\Builder
* @todo Auto populate the PRO_ID in TASK table
*/
public function scopeProcessId($query, $proId)
{
$query->join('PROCESS', function ($join) use ($proId) {
$join->on('TASK.PRO_UID', '=', 'PROCESS.PRO_UID')
->where('PROCESS.PRO_ID', '=', $proId);
});
return $query;
}
/**
* Get the title of the task
*
@@ -166,11 +196,11 @@ class Task extends Model
$query = Task::select(['TASK.TAS_UID']);
$query->join('ELEMENT_TASK_RELATION', function ($join) use ($evnUid) {
$join->on('ELEMENT_TASK_RELATION.TAS_UID', '=', 'TASK.TAS_UID')
->where('ELEMENT_TASK_RELATION.ELEMENT_UID', '=', $evnUid);
->where('ELEMENT_TASK_RELATION.ELEMENT_UID', '=', $evnUid);
});
$query->update(['TASK.TAS_DEF_TITLE' => $caseTitle]);
return $query;
}
@@ -186,9 +216,47 @@ class Task extends Model
$query = Task::select(['TASK.TAS_DEF_TITLE']);
$query->join('ELEMENT_TASK_RELATION', function ($join) use ($evnUid) {
$join->on('ELEMENT_TASK_RELATION.TAS_UID', '=', 'TASK.TAS_UID')
->where('ELEMENT_TASK_RELATION.ELEMENT_UID', '=', $evnUid);
->where('ELEMENT_TASK_RELATION.ELEMENT_UID', '=', $evnUid);
});
return $query->get()->values()->toArray()['0']['TAS_DEF_TITLE'];
}
/**
* Get all tasks, paged optionally, can be sent a string to filter results by "TAS_TITLE"
*
* @param string $text
* @param string $proId
* @param int $offset
* @param int $limit
*
* @return array
*/
public static function getTasksForHome($text = null, $proId = null, $offset = null, $limit = null)
{
// Get base query
$query = Task::query()->select(['TAS_ID', 'TAS_TITLE']);
// Set "TAS_TITLE" condition if is sent
if (!is_null($text)) {
$query->title($text);
}
// Set "PRO_ID" condition if is sent
if (!is_null($proId)) {
$query->processId($proId);
}
// Set pagination if offset and limit are sent
if (!is_null($offset) && !is_null($limit)) {
$query->offset($offset);
$query->limit($limit);
}
// Order by "TAS_TITLE"
$query->orderBy('TAS_TITLE');
// Return tasks
return $query->get()->toArray();
}
}

View File

@@ -17,6 +17,7 @@ use ProcessMaker\BusinessModel\Cases\Unassigned;
use ProcessMaker\Model\Delegation;
use ProcessMaker\Model\Process;
use ProcessMaker\Model\User;
use ProcessMaker\Model\Task;
use ProcessMaker\Services\Api;
use RBAC;
use stdClass;
@@ -662,4 +663,31 @@ class Home extends Api
return $result;
}
/**
* Get all tasks, paged optionally, can be sent a text to filter results by "TAS_TITLE"
*
* @url GET /tasks
*
* @param string $text
* @param string $proId
* @param int $offset
* @param int $limit
*
* @return array
*
* @throws Exception
*
* @access protected
* @class AccessControl {@permission PM_CASES}
*/
public function getTasks($text = null, $proId = null, $offset = null, $limit = null)
{
try {
$tasks = Task::getTasksForHome($text, $proId, $offset, $limit);
return $tasks;
} catch (Exception $e) {
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
}
}
}