PMCORE-3515
This commit is contained in:
@@ -96,6 +96,18 @@ $factory->state(\ProcessMaker\Model\Application::class, 'draft', function (Faker
|
||||
];
|
||||
});
|
||||
|
||||
$factory->state(\ProcessMaker\Model\Application::class, 'paused', function (Faker $faker) {
|
||||
$user = factory(\ProcessMaker\Model\User::class)->create();
|
||||
|
||||
return [
|
||||
'APP_NUMBER' => $faker->unique()->numberBetween(1000),
|
||||
'APP_STATUS_ID' => 1,
|
||||
'APP_STATUS' => 'PAUSED',
|
||||
'APP_INIT_USER' => $user->USR_UID,
|
||||
'APP_INIT_USER_ID' => $user->USR_ID,
|
||||
];
|
||||
});
|
||||
|
||||
$factory->state(\ProcessMaker\Model\Application::class, 'completed', function (Faker $faker) {
|
||||
return [
|
||||
'APP_NUMBER' => $faker->unique()->numberBetween(1000),
|
||||
|
||||
@@ -28,6 +28,7 @@ class DraftTest extends TestCase
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
Delegation::truncate();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -881,4 +882,18 @@ class DraftTest extends TestCase
|
||||
$res = $draft->getCasesRisk($process->PRO_ID, null, null, 'OVERDUE');
|
||||
$this->assertCount(1, $res);
|
||||
}
|
||||
|
||||
/**
|
||||
* This tests the getCounterMetrics() method
|
||||
*
|
||||
* @covers \ProcessMaker\BusinessModel\Cases\Draft::getCounterMetrics()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_get_counter_metrics()
|
||||
{
|
||||
$this->createDraft();
|
||||
$draft = new Draft();
|
||||
$result = $draft->getCounterMetrics();
|
||||
$this->assertTrue($result > 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,14 @@ class InboxTest extends TestCase
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
Delegation::truncate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method tearDown
|
||||
*/
|
||||
public function tearDown() {
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -272,9 +280,14 @@ class InboxTest extends TestCase
|
||||
public function it_filter_by_thread_title()
|
||||
{
|
||||
// Create factories related to the to_do cases
|
||||
$cases = $this->createInbox();
|
||||
$usrId = $cases->USR_ID;
|
||||
$title = $cases->DEL_TITLE;
|
||||
$delegation = factory(Delegation::class)->states('foreign_keys')->create([
|
||||
'DEL_THREAD_STATUS' => 'OPEN',
|
||||
'DEL_PREVIOUS' => 1,
|
||||
'DEL_INDEX' => 2,
|
||||
'DEL_TITLE' => 'Test',
|
||||
]);
|
||||
$usrId = $delegation->USR_ID;
|
||||
$title = 'Test';
|
||||
// We need to commit the records inserted because is needed for the "fulltext" index
|
||||
DB::commit();
|
||||
// Create new Inbox object
|
||||
@@ -830,4 +843,18 @@ class InboxTest extends TestCase
|
||||
$res = $inbox->getCasesRisk($process->PRO_ID, null, null, "OVERDUE");
|
||||
$this->assertCount(1, $res);
|
||||
}
|
||||
|
||||
/**
|
||||
* It tests the getCounterMetrics method
|
||||
*
|
||||
* @covers \ProcessMaker\BusinessModel\Cases\Inbox::getCounterMetrics()
|
||||
* @test
|
||||
*/
|
||||
public function it_tests_get_counter_metrics()
|
||||
{
|
||||
$this->createInbox();
|
||||
$inbox = new Inbox();
|
||||
$res = $inbox->getCounterMetrics();
|
||||
$this->assertTrue($res > 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ class PausedTest extends TestCase
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
Delegation::truncate();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -911,4 +912,19 @@ class PausedTest extends TestCase
|
||||
$res = $paused->getCasesRisk($process1->PRO_ID, null, null, 'OVERDUE');
|
||||
$this->assertCount(1, $res);
|
||||
}
|
||||
|
||||
/**
|
||||
* It tests the getCounterMetrics() method
|
||||
*
|
||||
* @covers \ProcessMaker\BusinessModel\Cases\Paused::getCounterMetrics()
|
||||
* @test
|
||||
*/
|
||||
public function it_tests_get_counter_metrics()
|
||||
{
|
||||
$this->createMultiplePaused(3);
|
||||
$paused = new Paused();
|
||||
|
||||
$res = $paused->getCounterMetrics();
|
||||
$this->assertTrue($res > 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ class UnassignedTest extends TestCase
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
Delegation::truncate();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -951,4 +952,18 @@ class UnassignedTest extends TestCase
|
||||
$res = $unassigned->getCasesRisk($process1->PRO_ID, null, null, 'OVERDUE');
|
||||
$this->assertCount(1, $res);
|
||||
}
|
||||
|
||||
/**
|
||||
* This the getCounterMetrics method
|
||||
*
|
||||
* @covers \ProcessMaker\BusinessModel\Cases\Unassigned::getCounterMetrics()
|
||||
* @test
|
||||
*/
|
||||
public function it_tests_get_counter_metrics()
|
||||
{
|
||||
$this->createSelfServiceUserOrGroup();
|
||||
$unassigned = new Unassigned;
|
||||
$result = $unassigned->getCounterMetrics();
|
||||
$this->assertTrue($result > 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1154,7 +1154,11 @@ class DelegationTest extends TestCase
|
||||
*/
|
||||
public function it_should_search_and_filter_by_app_title()
|
||||
{
|
||||
$delegations = factory(Delegation::class, 1)->states('foreign_keys')->create();
|
||||
$delegations = factory(Delegation::class, 1)->states('foreign_keys')->create([
|
||||
'APP_NUMBER' => function () {
|
||||
return factory(Application::class)->create()->APP_NUMBER;
|
||||
}
|
||||
]);
|
||||
$title = $delegations->last()->DEL_TITLE;
|
||||
// We need to commit the records inserted because is needed for the "fulltext" index
|
||||
DB::commit();
|
||||
@@ -3596,4 +3600,83 @@ class DelegationTest extends TestCase
|
||||
$res = $table->joinApplication()->participatedUser($table->USR_ID)->get();
|
||||
$this->assertCount(1, $res);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the scopeInboxMetrics
|
||||
*
|
||||
* @covers \ProcessMaker\Model\Delegation::scopeInboxMetrics()
|
||||
* @test
|
||||
*/
|
||||
public function it_tests_scope_inbox_metrics()
|
||||
{
|
||||
$application = factory(Application::class)->states('todo')->create();
|
||||
$table = factory(Delegation::class)->states('foreign_keys')->create([
|
||||
'APP_NUMBER' => $application->APP_NUMBER,
|
||||
'APP_UID' => $application->APP_UID,
|
||||
]);
|
||||
$res = $table->inboxMetrics()->get();
|
||||
$this->assertCount(1, $res);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the scopeDraftMetrics
|
||||
*
|
||||
* @covers \ProcessMaker\Model\Delegation::scopeDraftMetrics()
|
||||
* @test
|
||||
*/
|
||||
public function it_tests_scope_draft_metrics()
|
||||
{
|
||||
$application = factory(Application::class)->states('draft')->create();
|
||||
$table = factory(Delegation::class)->states('foreign_keys')->create([
|
||||
'APP_NUMBER' => $application->APP_NUMBER,
|
||||
'APP_UID' => $application->APP_UID,
|
||||
]);
|
||||
$res = $table->draftMetrics()->get();
|
||||
$this->assertCount(1, $res);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the scopePausedMetrics
|
||||
*
|
||||
* @covers \ProcessMaker\Model\Delegation::scopePausedMetrics()
|
||||
* @test
|
||||
*/
|
||||
public function it_tests_scope_paused_metrics()
|
||||
{
|
||||
$application = factory(Application::class)->states('paused')->create();
|
||||
$appDelay = factory(AppDelay::class)->states('paused_foreign_keys')->create([
|
||||
'APP_NUMBER' => $application->APP_NUMBER,
|
||||
'APP_UID' => $application->APP_UID,
|
||||
]);
|
||||
$table = factory(Delegation::class)->states('foreign_keys')->create([
|
||||
'APP_NUMBER' => $application->APP_NUMBER,
|
||||
'APP_UID' => $application->APP_UID,
|
||||
'DEL_INDEX' => $appDelay->APP_DEL_INDEX,
|
||||
]);
|
||||
$res = $table->pausedMetrics()->get();
|
||||
$this->assertCount(1, $res);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the scopeSelfServiceMetrics
|
||||
*
|
||||
* @covers \ProcessMaker\Model\Delegation::scopeSelfServiceMetrics()
|
||||
* @test
|
||||
*/
|
||||
public function it_tests_scope_self_service_metrics()
|
||||
{
|
||||
$application = factory(Application::class)->states('paused')->create();
|
||||
$task = factory(Task::class)->create([
|
||||
'TAS_ASSIGN_TYPE' => 'SELF_SERVICE',
|
||||
]);
|
||||
$delegation = factory(Delegation::class)->states('foreign_keys')->create([
|
||||
'APP_NUMBER' => $application->APP_NUMBER,
|
||||
'APP_UID' => $application->APP_UID,
|
||||
'TAS_ID' => $task->TAS_ID,
|
||||
'DEL_THREAD_STATUS' => 'OPEN',
|
||||
'USR_ID' => 0,
|
||||
]);
|
||||
$res = $delegation->selfServiceMetrics()->get();
|
||||
$this->assertCount(1, $res);
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1552,16 +1552,16 @@ class AbstractCases implements CasesInterface
|
||||
$list = end($listArray);
|
||||
switch ($list) {
|
||||
case 'Inbox':
|
||||
$query->inbox($this->getUserId());
|
||||
$query->inboxMetrics();
|
||||
break;
|
||||
case 'Draft':
|
||||
$query->draft($this->getUserId());
|
||||
$query->draftMetrics();
|
||||
break;
|
||||
case 'Paused':
|
||||
$query->paused($this->getUserId());
|
||||
$query->pausedMetrics();
|
||||
break;
|
||||
case 'Unassigned':
|
||||
$query->selfService($this->getUserUid());
|
||||
$query->selfServiceMetrics();
|
||||
break;
|
||||
}
|
||||
$query->joinProcess();
|
||||
@@ -1604,16 +1604,16 @@ class AbstractCases implements CasesInterface
|
||||
$list = end($listArray);
|
||||
switch ($list) {
|
||||
case 'Inbox':
|
||||
$query->inbox($this->getUserId());
|
||||
$query->inboxMetrics();
|
||||
break;
|
||||
case 'Draft':
|
||||
$query->draft($this->getUserId());
|
||||
$query->draftMetrics();
|
||||
break;
|
||||
case 'Paused':
|
||||
$query->paused($this->getUserId());
|
||||
$query->pausedMetrics();
|
||||
break;
|
||||
case 'Unassigned':
|
||||
$query->selfService($this->getUserUid());
|
||||
$query->selfServiceMetrics();
|
||||
break;
|
||||
}
|
||||
$query->joinProcess();
|
||||
@@ -1657,16 +1657,16 @@ class AbstractCases implements CasesInterface
|
||||
$list = end($listArray);
|
||||
switch ($list) {
|
||||
case 'Inbox':
|
||||
$query->inbox($this->getUserId());
|
||||
$query->inboxMetrics();
|
||||
break;
|
||||
case 'Draft':
|
||||
$query->draft($this->getUserId());
|
||||
$query->draftMetrics();
|
||||
break;
|
||||
case 'Paused':
|
||||
$query->paused($this->getUserId());
|
||||
$query->pausedMetrics();
|
||||
break;
|
||||
case 'Unassigned':
|
||||
$query->selfService($this->getUserUid());
|
||||
$query->selfServiceMetrics();
|
||||
break;
|
||||
}
|
||||
$query->joinProcess();
|
||||
|
||||
@@ -244,4 +244,16 @@ class Draft extends AbstractCases
|
||||
'total' => $count
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Count how many cases there are in DRAFT
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getCounterMetrics()
|
||||
{
|
||||
$query = Delegation::query()->select();
|
||||
$query->draftMetrics();
|
||||
return $query->count(['APPLICATION.APP_NUMBER']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -260,4 +260,16 @@ class Inbox extends AbstractCases
|
||||
'total' => $count
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Count how many cases there are in TO_DO
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getCounterMetrics()
|
||||
{
|
||||
$query = Delegation::query()->select();
|
||||
$query->inboxMetrics();
|
||||
return $query->count(['APP_DELEGATION.APP_NUMBER']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -254,4 +254,16 @@ class Paused extends AbstractCases
|
||||
'total' => $count
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Count how many cases there are in PAUSED
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getCounterMetrics()
|
||||
{
|
||||
$query = Delegation::query()->select();
|
||||
$query->pausedMetrics();
|
||||
return $query->count(['APP_DELEGATION.APP_NUMBER']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -263,4 +263,16 @@ class Unassigned extends AbstractCases
|
||||
'total' => $count
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Count how many cases there are in SELF_SERVICE
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getCounterMetrics()
|
||||
{
|
||||
$query = Delegation::query()->select();
|
||||
$query->selfServiceMetrics();
|
||||
return $query->count(['APP_DELEGATION.APP_NUMBER']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1069,6 +1069,64 @@ class Delegation extends Model
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope the Inbox cases no matter the user
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeInboxMetrics($query)
|
||||
{
|
||||
$query->joinApplication();
|
||||
$query->status(Application::STATUS_TODO);
|
||||
$query->threadOpen();
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope a draft cases no matter the user
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeDraftMetrics($query)
|
||||
{
|
||||
$query->joinApplication();
|
||||
$query->status(Application::STATUS_DRAFT);
|
||||
$query->threadOpen();
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope paused cases list no matter the user
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopePausedMetrics($query)
|
||||
{
|
||||
$query->joinAppDelay('PAUSE');
|
||||
$query->joinApplication();
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope a self service cases no matter the user
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeSelfServiceMetrics($query)
|
||||
{
|
||||
$query->taskAssignType('SELF_SERVICE');
|
||||
$query->threadOpen()->withoutUserId();
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get specific cases unassigned that the user can view
|
||||
*
|
||||
|
||||
@@ -3,11 +3,11 @@
|
||||
namespace ProcessMaker\Services\Api;
|
||||
|
||||
use Exception;
|
||||
use Luracast\Restler\RestException;
|
||||
use ProcessMaker\BusinessModel\Cases\Draft;
|
||||
use ProcessMaker\BusinessModel\Cases\Inbox;
|
||||
use ProcessMaker\BusinessModel\Cases\Paused;
|
||||
use ProcessMaker\BusinessModel\Cases\Unassigned;
|
||||
use ProcessMaker\Model\User;
|
||||
use ProcessMaker\Services\Api;
|
||||
use RBAC;
|
||||
|
||||
@@ -46,8 +46,6 @@ class Metrics extends Api
|
||||
*/
|
||||
public function getProcessTotalCases($caseList, $category = null, $topTen = false, $processes = [])
|
||||
{
|
||||
$usrUid = $this->getUserId();
|
||||
$usrId = !empty($usrUid) ? User::getId($usrUid) : 0;
|
||||
try {
|
||||
switch ($caseList) {
|
||||
case 'inbox':
|
||||
@@ -61,10 +59,8 @@ class Metrics extends Api
|
||||
break;
|
||||
case 'unassigned':
|
||||
$list = new Unassigned();
|
||||
$list->setUserUid($usrUid);
|
||||
break;
|
||||
}
|
||||
$list->setUserId($usrId);
|
||||
$result = $list->getCountersByProcesses($category, $topTen, $processes);
|
||||
return $result;
|
||||
} catch (Exception $e) {
|
||||
@@ -91,8 +87,6 @@ class Metrics extends Api
|
||||
*/
|
||||
public function getTotalCasesByRange($caseList, $processId = null, $dateFrom = null, $dateTo = null, $groupBy = 'day')
|
||||
{
|
||||
$usrUid = $this->getUserId();
|
||||
$usrId = !empty($usrUid) ? User::getId($usrUid) : 0;
|
||||
try {
|
||||
switch ($caseList) {
|
||||
case 'inbox':
|
||||
@@ -106,10 +100,8 @@ class Metrics extends Api
|
||||
break;
|
||||
case 'unassigned':
|
||||
$list = new Unassigned();
|
||||
$list->setUserUid($usrUid);
|
||||
break;
|
||||
}
|
||||
$list->setUserId($usrId);
|
||||
$result = $list->getCountersByRange($processId, $dateFrom, $dateTo, $groupBy);
|
||||
return $result;
|
||||
} catch (Exception $e) {
|
||||
@@ -125,31 +117,21 @@ class Metrics extends Api
|
||||
* @return array
|
||||
*
|
||||
* @throws RestException
|
||||
*
|
||||
* @class AccessControl {@permission TASK_METRICS_VIEW}
|
||||
*/
|
||||
public function getCountersList()
|
||||
{
|
||||
try {
|
||||
$usrUid = $this->getUserId();
|
||||
$properties['user'] = !empty($usrUid) ? User::getId($usrUid) : 0;
|
||||
|
||||
$listInbox = new Inbox();
|
||||
$listInbox->setProperties($properties);
|
||||
|
||||
$listDraft = new Draft();
|
||||
$listDraft->setUserUid($usrUid);
|
||||
$listDraft->setProperties($properties);
|
||||
|
||||
$listPaused = new Paused();
|
||||
$listPaused->setProperties($properties);
|
||||
|
||||
$listUnassigned = new Unassigned();
|
||||
$listUnassigned->setUserUid($usrUid);
|
||||
$listUnassigned->setProperties($properties);
|
||||
|
||||
$casesInbox = $listInbox->getCounter();
|
||||
$casesDraft = $listDraft->getCounter();
|
||||
$casesPaused = $listPaused->getCounter();
|
||||
$casesUnassigned = $listUnassigned->getCounter();
|
||||
$casesInbox = $listInbox->getCounterMetrics();
|
||||
$casesDraft = $listDraft->getCounterMetrics();
|
||||
$casesPaused = $listPaused->getCounterMetrics();
|
||||
$casesUnassigned = $listUnassigned->getCounterMetrics();
|
||||
|
||||
$result = [
|
||||
['List Name' => 'Inbox', 'Total' => $casesInbox, 'Color' => 'green'],
|
||||
@@ -179,12 +161,12 @@ class Metrics extends Api
|
||||
* @return array
|
||||
*
|
||||
* @throws RestException
|
||||
*
|
||||
* @class AccessControl {@permission TASK_METRICS_VIEW}
|
||||
*/
|
||||
public function getCasesRiskByProcess($caseList = 'inbox', $process, $dateFrom = null, $dateTo = null, $riskStatus = 'ON_TIME', $topCases = null)
|
||||
{
|
||||
try {
|
||||
$usrUid = $this->getUserId();
|
||||
$usrId = !empty($usrUid) ? User::getId($usrUid) : 0;
|
||||
switch ($caseList) {
|
||||
case 'inbox':
|
||||
$list = new Inbox();
|
||||
@@ -197,10 +179,8 @@ class Metrics extends Api
|
||||
break;
|
||||
case 'unassigned':
|
||||
$list = new Unassigned();
|
||||
$list->setUserUid($usrUid);
|
||||
break;
|
||||
}
|
||||
$list->setUserId($usrId);
|
||||
$result = $list->getCasesRisk($process, $dateFrom, $dateTo, $riskStatus, $topCases);
|
||||
return $result;
|
||||
} catch (Exception $e) {
|
||||
|
||||
Reference in New Issue
Block a user