PMCORE-2539
This commit is contained in:
@@ -341,4 +341,43 @@ class ProcessTest extends TestCase
|
||||
$total = Process::getCounter($process->PRO_CREATE_USER);
|
||||
$this->assertEquals(1, $total);
|
||||
}
|
||||
|
||||
/**
|
||||
* It test get processes for the new home view
|
||||
*
|
||||
* @covers \ProcessMaker\Model\Process::getProcessesForHome()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_get_processes_for_home()
|
||||
{
|
||||
// Create a process category
|
||||
$processCategory = factory(ProcessCategory::class)->create();
|
||||
|
||||
// Create five processes (4 active, 1 inactive)
|
||||
factory(Process::class)->create([
|
||||
'PRO_TITLE' => 'My Process 1',
|
||||
'PRO_CATEGORY' => $processCategory->CATEGORY_UID
|
||||
]);
|
||||
factory(Process::class)->create([
|
||||
'PRO_TITLE' => 'My Process 2',
|
||||
'PRO_CATEGORY' => $processCategory->CATEGORY_UID
|
||||
]);
|
||||
factory(Process::class)->create([
|
||||
'PRO_TITLE' => 'My Process 3',
|
||||
]);
|
||||
factory(Process::class)->create([
|
||||
'PRO_TITLE' => 'Another Process',
|
||||
]);
|
||||
factory(Process::class)->create([
|
||||
'PRO_TITLE' => 'Inactive Process',
|
||||
'PRO_STATUS' => 'INACTIVE'
|
||||
]);
|
||||
|
||||
// Assertions
|
||||
$this->assertCount(4, Process::getProcessesForHome());
|
||||
$this->assertCount(3, Process::getProcessesForHome('My Process'));
|
||||
$this->assertCount(2, Process::getProcessesForHome(null, $processCategory->CATEGORY_UID));
|
||||
$this->assertCount(4, Process::getProcessesForHome(null, null, null, 2));
|
||||
$this->assertCount(1, Process::getProcessesForHome(null, null, 2, 1));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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