Merged in feature/PMCORE-2539 (pull request #7609)
PMCORE-2539 Approved-by: Julio Cesar Laura Avendaño <contact@julio-laura.com>
This commit is contained in:
@@ -180,6 +180,18 @@ class Process extends Model
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope a query to include a specific process status
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param string $status
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeStatus($query, $status)
|
||||
{
|
||||
return $query->where('PROCESS.PRO_STATUS', $status);
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtains the process list for an specific user and/or for the specific category
|
||||
*
|
||||
@@ -390,4 +402,46 @@ class Process extends Model
|
||||
|
||||
return $query->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all processes, paged optionally, can be sent a string to filter results by "PRO_TITLE"
|
||||
*
|
||||
* @param string $text
|
||||
* @param string $category
|
||||
* @param int $offset
|
||||
* @param int $limit
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getProcessesForHome($text = null, $category = null, $offset = null, $limit = null)
|
||||
{
|
||||
// Get base query
|
||||
$query = Process::query()->select(['PRO_ID', 'PRO_TITLE']);
|
||||
|
||||
// Set "PRO_TITLE" condition if is sent
|
||||
if (!is_null($text)) {
|
||||
$query->title($text);
|
||||
}
|
||||
|
||||
// Set "PRO_CATEGORY" condition if is sent
|
||||
if (!is_null($category)) {
|
||||
$query->category($category);
|
||||
}
|
||||
|
||||
// Set "PRO_STATUS" condition
|
||||
$query->status('ACTIVE');
|
||||
|
||||
// Set pagination if offset and limit are sent
|
||||
if (!is_null($offset) && !is_null($limit)) {
|
||||
$query->offset($offset);
|
||||
$query->limit($limit);
|
||||
}
|
||||
|
||||
// Order by "PRO_TITLE"
|
||||
$query->orderBy('PRO_TITLE');
|
||||
|
||||
// Return processes
|
||||
return $query->get()->toArray();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ use ProcessMaker\BusinessModel\Cases\Search;
|
||||
use ProcessMaker\BusinessModel\Cases\Supervising;
|
||||
use ProcessMaker\BusinessModel\Cases\Unassigned;
|
||||
use ProcessMaker\Model\Delegation;
|
||||
use ProcessMaker\Model\Process;
|
||||
use ProcessMaker\Model\User;
|
||||
use ProcessMaker\Services\Api;
|
||||
use RBAC;
|
||||
@@ -570,4 +571,31 @@ class Home extends Api
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all processes, paged optionally, can be sent a text to filter results by "PRO_TITLE"
|
||||
*
|
||||
* @url GET /processes
|
||||
*
|
||||
* @param string $text
|
||||
* @param string $category
|
||||
* @param int $offset
|
||||
* @param int $limit
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws Exception
|
||||
*
|
||||
* @access protected
|
||||
* @class AccessControl {@permission PM_CASES}
|
||||
*/
|
||||
public function getProcesses($text = null, $category = null, $offset = null, $limit = null)
|
||||
{
|
||||
try {
|
||||
$processes = Process::getProcessesForHome($text, $category, $offset, $limit);
|
||||
return $processes;
|
||||
} catch (Exception $e) {
|
||||
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user