PMCORE-3104
This commit is contained in:
@@ -96,9 +96,9 @@ class CasesMenuHighlightTest extends TestCase
|
||||
|
||||
// Check if the object is valid
|
||||
$this->assertNotEmpty($result);
|
||||
$this->assertArrayHasKey('item', $result[0]);
|
||||
$this->assertArrayHasKey('highlight', $result[0]);
|
||||
$this->assertEquals('CASES_SELFSERVICE', $result[0]['item']);
|
||||
$this->assertEquals(true, $result[0]['highlight']);
|
||||
$this->assertArrayHasKey('item', $result[7]);
|
||||
$this->assertArrayHasKey('highlight', $result[7]);
|
||||
$this->assertEquals('CASES_SELFSERVICE', $result[7]['item']);
|
||||
$this->assertEquals(true, $result[7]['highlight']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,6 +42,18 @@ class CasesListTest extends TestCase
|
||||
return $delegation;
|
||||
}
|
||||
|
||||
/**
|
||||
* This test construct
|
||||
*
|
||||
* @covers \ProcessMaker\BusinessModel\Cases\CasesList::__construct()
|
||||
* @test
|
||||
*/
|
||||
public function it_test_construct()
|
||||
{
|
||||
$casesList = new CasesList();
|
||||
$this->assertInstanceOf(CasesList::class, $casesList);
|
||||
}
|
||||
|
||||
/**
|
||||
* This test getAllCounters
|
||||
*
|
||||
@@ -57,4 +69,29 @@ class CasesListTest extends TestCase
|
||||
$this->assertArrayHasKey('CASES_INBOX', $result);
|
||||
$this->assertArrayHasKey('CASES_DRAFT', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* This test getAllCounters
|
||||
*
|
||||
* @covers \ProcessMaker\BusinessModel\Cases\CasesList::atLeastOne()
|
||||
* @covers \ProcessMaker\BusinessModel\Cases\BatchRouting::atLeastOne()
|
||||
* @covers \ProcessMaker\BusinessModel\Cases\Canceled::atLeastOne()
|
||||
* @covers \ProcessMaker\BusinessModel\Cases\Completed::atLeastOne()
|
||||
* @covers \ProcessMaker\BusinessModel\Cases\Draft::atLeastOne()
|
||||
* @covers \ProcessMaker\BusinessModel\Cases\Inbox::atLeastOne()
|
||||
* @covers \ProcessMaker\BusinessModel\Cases\Participated::atLeastOne()
|
||||
* @covers \ProcessMaker\BusinessModel\Cases\Paused::atLeastOne()
|
||||
* @covers \ProcessMaker\BusinessModel\Cases\Unassigned::atLeastOne()
|
||||
* @test
|
||||
*/
|
||||
public function it_return_at_least_one()
|
||||
{
|
||||
$delegation = factory(Delegation::class)->states('foreign_keys')->create();
|
||||
$count = new CasesList();
|
||||
$result = $count->atLeastOne($delegation->USR_UID);
|
||||
$this->assertNotEmpty($result);
|
||||
$firstItem = head($result);
|
||||
$this->assertArrayHasKey('item', $firstItem);
|
||||
$this->assertArrayHasKey('highlight', $firstItem);
|
||||
}
|
||||
}
|
||||
@@ -1,27 +1,16 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use ProcessMaker\BusinessModel\Cases\CasesList;
|
||||
use ProcessMaker\Model\Delegation;
|
||||
|
||||
// Get the self service query for the current user
|
||||
$query = Delegation::getSelfServiceQuery($_SESSION['USER_LOGGED']);
|
||||
|
||||
// Mutate query and execute
|
||||
if (!is_string($query)) {
|
||||
$query->limit(1);
|
||||
$items = $query->get();
|
||||
$atLeastOne = $items->count() > 0;
|
||||
} else {
|
||||
$query .= " LIMIT 1";
|
||||
$items = DB::select($query);
|
||||
$atLeastOne = !empty($items);
|
||||
}
|
||||
|
||||
// Initializing the response variable
|
||||
// Get the user logged
|
||||
$usrUid = $_SESSION['USER_LOGGED'];
|
||||
// Instance the class
|
||||
$casesList = new CasesList();
|
||||
$response = [];
|
||||
|
||||
// The scope for the first version of this feature is only for unassigned list, so, this value is currently fixed
|
||||
$response[] = ['item' => 'CASES_SELFSERVICE', 'highlight' => $atLeastOne];
|
||||
// Get highlight for all task list
|
||||
$response = $casesList->atLeastOne($usrUid);
|
||||
|
||||
// Print the response in JSON format
|
||||
header('Content-Type: application/json');
|
||||
|
||||
@@ -1480,6 +1480,16 @@ class AbstractCases implements CasesInterface
|
||||
throw new Exception("Method '" . __FUNCTION__ . "' should be implemented in the extended class '" . get_class($this) . "'.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get true if the user has at least one case
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function atLeastOne()
|
||||
{
|
||||
throw new Exception("Method '" . __FUNCTION__ . "' should be implemented in the extended class '" . get_class($this) . "'.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list counter
|
||||
*
|
||||
|
||||
@@ -56,4 +56,15 @@ class BatchRouting extends AbstractCases
|
||||
// Return the number of rows
|
||||
return $query->count(['APP_DELEGATION.APP_NUMBER']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Count if the user has at least one case in the list
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function atLeastOne()
|
||||
{
|
||||
// This class does not require this value
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -61,4 +61,15 @@ class Canceled extends AbstractCases
|
||||
// Return the number of rows
|
||||
return $query->count(['APP_DELEGATION.APP_NUMBER']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Count if the user has at least one case in the list
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function atLeastOne()
|
||||
{
|
||||
// This class does not require this value
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,6 +41,7 @@ class CasesList
|
||||
'inbox' => 'CASES_INBOX',
|
||||
'participated' => 'CASES_SENT',
|
||||
'paused' => 'CASES_PAUSED',
|
||||
'unassigned' => 'CASES_SELFSERVICE',
|
||||
];
|
||||
|
||||
/*----------------------------------********---------------------------------*/
|
||||
@@ -83,4 +84,28 @@ class CasesList
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Count if the user has at least one case in the list
|
||||
*
|
||||
* @param string $usrUid
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function atLeastOne(string $usrUid)
|
||||
{
|
||||
// Get the usrId key
|
||||
$usrId = User::getId($usrUid);
|
||||
// Get the classes
|
||||
$list = $this->mapList;
|
||||
$response = [];
|
||||
foreach ($list as $listObject => $item) {
|
||||
$this->$listObject->setUserUid($usrUid);
|
||||
$this->$listObject->setUserId($usrId);
|
||||
$atLeastOne = $this->$listObject->atLeastOne($usrUid);
|
||||
$response[] = ['item' => $item, 'highlight' => $atLeastOne];
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,8 +53,18 @@ class Completed extends AbstractCases
|
||||
$participated->setParticipatedStatus('COMPLETED');
|
||||
$participated->setUserUid($this->getUserUid());
|
||||
$participated->setUserId($this->getUserId());
|
||||
$count = $participated->getCounter();
|
||||
|
||||
return $count;
|
||||
return $participated->getCounter();
|
||||
}
|
||||
|
||||
/**
|
||||
* Count if the user has at least one case in the list
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function atLeastOne()
|
||||
{
|
||||
// This class does not require this value
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -152,6 +152,24 @@ class Draft extends AbstractCases
|
||||
return $query->count(['APPLICATION.APP_NUMBER']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Count if the user has at least one case in the list
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function atLeastOne()
|
||||
{
|
||||
$query = Application::query()->select(['APPLICATION.APP_NUMBER']);
|
||||
// Add the initial scope for draft cases for specific user
|
||||
$query->draft($this->getUserUid());
|
||||
// Get only one case
|
||||
$query->limit(1);
|
||||
// Get result
|
||||
$items = $query->get();
|
||||
|
||||
return $items->count() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Count how many cases the user has in DRAFT, needs to apply filters
|
||||
*
|
||||
|
||||
@@ -165,6 +165,24 @@ class Inbox extends AbstractCases
|
||||
return $query->count(['APP_DELEGATION.APP_NUMBER']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Count if the user has at least one case in the list
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function atLeastOne()
|
||||
{
|
||||
$query = Delegation::query()->select(['APP_DELEGATION.APP_NUMBER']);
|
||||
// Scope that sets the queries for List Inbox for specific user
|
||||
$query->inbox($this->getUserId());
|
||||
// Get only one case
|
||||
$query->limit(1);
|
||||
// Get the result
|
||||
$items = $query->get();
|
||||
|
||||
return $items->count() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Count how many cases the user has in TO_DO, needs to apply filters
|
||||
*
|
||||
|
||||
@@ -266,6 +266,17 @@ class Participated extends AbstractCases
|
||||
return $query->count(['APP_DELEGATION.APP_NUMBER']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Count if the user has at least one case in the list
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function atLeastOne()
|
||||
{
|
||||
// This class does not require this value
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Count how many cases the user has Participation, needs to apply filters
|
||||
*
|
||||
|
||||
@@ -159,6 +159,24 @@ class Paused extends AbstractCases
|
||||
return $query->count(['APP_DELEGATION.APP_NUMBER']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Count if the user has at least one case in the list
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function atLeastOne()
|
||||
{
|
||||
$query = Delegation::query()->select(['APP_DELEGATION.APP_NUMBER']);
|
||||
// Scope that set the paused cases
|
||||
$query->paused($this->getUserId());
|
||||
// Get only one case
|
||||
$query->limit(1);
|
||||
// Get result
|
||||
$items = $query->get();
|
||||
|
||||
return $items->count() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Count how many cases the user has in PAUSED, needs to apply filters
|
||||
*
|
||||
|
||||
@@ -215,6 +215,17 @@ class Search extends AbstractCases
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Count if the user has at least one case in the list
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function atLeastOne()
|
||||
{
|
||||
// This class does not require this value
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of rows corresponding to the advanced search, needs to apply filters
|
||||
*
|
||||
|
||||
@@ -203,6 +203,17 @@ class Supervising extends AbstractCases
|
||||
return $query->count(['APP_DELEGATION.APP_NUMBER']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Count if the user has at least one case in the list
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function atLeastOne()
|
||||
{
|
||||
// This class does not require this value
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Count how many cases the user has in Supervising, needs to apply filters
|
||||
*
|
||||
|
||||
@@ -167,6 +167,24 @@ class Unassigned extends AbstractCases
|
||||
return $query->count(['APP_DELEGATION.APP_NUMBER']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Count if the user has at least one case in the list
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function atLeastOne()
|
||||
{
|
||||
$query = Delegation::query()->select(['APP_DELEGATION.APP_NUMBER']);
|
||||
// Add the initial scope for self-service cases
|
||||
$query->selfService($this->getUserUid());
|
||||
// Get only one case
|
||||
$query->limit(1);
|
||||
// Get result
|
||||
$items = $query->get();
|
||||
|
||||
return $items->count() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Count how many cases the user has in SELF_SERVICE, needs to apply filters
|
||||
*
|
||||
|
||||
@@ -355,6 +355,24 @@ class Application extends Model
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope the Draft cases
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param string $user
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeDraft($query, $user)
|
||||
{
|
||||
// Filter the status draft
|
||||
$query->statusId(Application::STATUS_DRAFT);
|
||||
// Filter the creator
|
||||
$query->creator($user);
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Applications by PRO_UID, ordered by APP_NUMBER.
|
||||
*
|
||||
|
||||
@@ -6,6 +6,7 @@ use Exception;
|
||||
use G;
|
||||
use Luracast\Restler\RestException;
|
||||
use Menu;
|
||||
use ProcessMaker\BusinessModel\Cases\CasesList;
|
||||
use ProcessMaker\BusinessModel\Cases\Draft;
|
||||
use ProcessMaker\BusinessModel\Cases\Filter;
|
||||
use ProcessMaker\BusinessModel\Cases\Inbox;
|
||||
@@ -795,7 +796,7 @@ class Home extends Api
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the tasks counters for todo, draft, paused and unassigned
|
||||
* Get the tasks counters for all task list: todo, draft, paused and unassigned
|
||||
*
|
||||
* @url GET /tasks/counter
|
||||
*
|
||||
@@ -833,6 +834,26 @@ class Home extends Api
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the tasks highlight for all task list
|
||||
*
|
||||
* @url GET /tasks/highlight
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @access protected
|
||||
* @class AccessControl {@permission PM_CASES}
|
||||
*/
|
||||
public function getHighlight()
|
||||
{
|
||||
$usrUid = $this->getUserId();
|
||||
$casesList = new CasesList();
|
||||
$result = [];
|
||||
$result = $casesList->atLeastOne($usrUid);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all tasks, paged optionally, can be sent a text to filter results by "TAS_TITLE"
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user