PMCORE-871

This commit is contained in:
Paula Quispe
2019-06-14 13:05:21 -04:00
parent 9e16fc0bd8
commit 0b2086591a
4 changed files with 645 additions and 0 deletions

View File

@@ -2,7 +2,61 @@
namespace ProcessMaker\BusinessModel\Cases;
use ProcessMaker\Model\Delegation;
class Draft extends AbstractCases
{
/**
* Get data self-services cases by user
*
* @return array
*/
public function getData()
{
$query = Delegation::query()->select();
// Add the initial scope for draft cases
$query->draft($this->getUserId());
// Add join with task
$query->specificTaskTypes(['NORMAL', 'ADHOC']);
// Add join for process, but only for certain scenarios such as category or process
if ($this->getCategoryUid() || $this->getProcessUid() || $this->getOrderByColumn() === 'PRO_TITLE') {
$query->categoryProcess($this->getCategoryUid());
}
// Specific process
if ($this->getProcessId()) {
$query->processId($this->getProcessId());
}
// Specific case uid
if (!empty($this->getCaseUid())) {
$query->appUid($this->getCaseUid());
}
// Specific cases
if (!empty($this->getCasesUids())) {
$query->specificCasesByUid($this->getCasesUids());
}
// Add any sort if needed
if ($this->getOrderByColumn()) {
$query->orderBy($this->getOrderByColumn(), $this->getOrderDirection());
}
// Add pagination to the query
$query->offset($this->getOffset())->limit($this->getLimit());
// Get the data
$results = $query->get();
return $results->values()->toArray();
}
/**
* Count the self-services cases by user
*
* @return int
*/
public function getCounter()
{
$query = Delegation::query()->select();
// Add the initial scope for draft cases
$query->draft($this->getUserId());
return $query->count();
}
}