Merge develop

This commit is contained in:
Paula Quispe
2020-12-01 17:47:50 -04:00
66 changed files with 3721 additions and 1224 deletions

View File

@@ -0,0 +1,103 @@
<?php
namespace ProcessMaker\Model;
use Illuminate\Database\Eloquent\Model;
class AppTimeoutAction extends Model
{
protected $table = 'APP_TIMEOUT_ACTION_EXECUTED';
// We do not have create/update timestamps for this table
public $timestamps = false;
// Filter by a specific case using case number
private $caseUid = '';
// Filter by a specific index
private $index = 0;
/**
* Set Case Uid
*
* @param string $caseUid
*/
public function setCaseUid($caseUid)
{
$this->caseUid = $caseUid;
}
/**
* Get Case Uid
*
* @return string
*/
public function getCaseUid()
{
return $this->caseUid;
}
/**
* Set index
*
* @param int $index
*/
public function setIndex($index)
{
$this->index = $index;
}
/**
* Get index
*
* @return int
*/
public function getIndex()
{
return $this->index;
}
/**
* Scope a query to get specific case uid
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param string $appUid
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeCase($query, $appUid)
{
return $query->where('APP_UID', $appUid);
}
/**
* Scope a query to get index
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param int $index
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeIndex($query, $index)
{
return $query->where('DEL_INDEX', $index);
}
/**
* Get the records related to the case and index if it was defined
*
* @return array
*/
public function cases()
{
$query = AppTimeoutAction::query()->select();
// Specific case uid
if (!empty($this->getCaseUid())) {
$query->case($this->getCaseUid());
}
// Specific index
if (!empty($this->getIndex())) {
$query->index($this->getIndex());
}
$results = $query->get()->toArray();
return $results;
}
}

View File

@@ -35,6 +35,19 @@ class Application extends Model
return $this->belongsTo(User::class, 'APP_INIT_USER', 'USR_UID');
}
/**
* Scope for query to get the positive cases
*
* @param \Illuminate\Database\Eloquent\Builder $query
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopePositivesCases($query)
{
$result = $query->where('APP_NUMBER', '>', 0);
return $result;
}
/**
* Scope for query to get the application by APP_UID.
*
@@ -49,6 +62,20 @@ class Application extends Model
return $result;
}
/**
* Scope for query to get the application by status Id
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param integer $status
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeStatusId($query, int $status)
{
$result = $query->where('APP_STATUS_ID', '=', $status);
return $result;
}
/**
* Scope for query to get the applications by PRO_UID.
*
@@ -76,6 +103,7 @@ class Application extends Model
$query = Application::query()
->select()
->proUid($proUid)
->positivesCases()
->orderBy('APP_NUMBER', 'ASC');
return $query->get();
}
@@ -118,4 +146,24 @@ class Application extends Model
return $properties;
}
/**
* Get Applications by PRO_UID, ordered by APP_NUMBER.
*
* @param string $proUid
* @param int $status
*
* @return object
* @see ReportTables->populateTable()
*/
public static function getCountByProUid(string $proUid, $status = 2)
{
$query = Application::query()
->select()
->proUid($proUid)
->statusId($status)
->positivesCases();
return $query->get()->count();
}
}

View File

@@ -13,4 +13,20 @@ class BpmnProject extends Model
// We do not have create/update timestamps for this table
public $timestamps = false;
/**
* Check is the Process is BPMN.
*
* @param string $proUid
*
* @return int 1 if is BPMN process or 0 if a Normal process
*/
public static function isBpmnProcess(string $proUid)
{
$query = BpmnProject::query()
->select()
->where('PRJ_UID', '=', $proUid);
$result = $query->get()->values()->toArray();
return empty($result) ? 0 : 1;
}
}

View File

@@ -46,8 +46,9 @@ class ListUnassigned extends Model
/**
* Scope a query to only include specific tasks
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param array $tasks
* @param \Illuminate\Database\Eloquent\Builder $query
* @param array $tasks
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeTasksIn($query, array $tasks)
@@ -58,8 +59,8 @@ class ListUnassigned extends Model
/**
* Scope a query to only include a specific case
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param integer $appNumber
* @param \Illuminate\Database\Eloquent\Builder $query
* @param integer $appNumber
*
* @return \Illuminate\Database\Eloquent\Builder
*/
@@ -71,8 +72,8 @@ class ListUnassigned extends Model
/**
* Scope a query to only include a specific index
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param integer $index
* @param \Illuminate\Database\Eloquent\Builder $query
* @param integer $index
*
* @return \Illuminate\Database\Eloquent\Builder
*/
@@ -84,8 +85,8 @@ class ListUnassigned extends Model
/**
* Scope a query to only include a specific task
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param integer $task
* @param \Illuminate\Database\Eloquent\Builder $query
* @param integer $task
*
* @return \Illuminate\Database\Eloquent\Builder
*/
@@ -100,7 +101,7 @@ class ListUnassigned extends Model
* @param string $userUid
* @param array $filters
*
* @return array
* @return int
*/
public static function doCount($userUid, $filters = [])
{
@@ -125,4 +126,21 @@ class ListUnassigned extends Model
return $result;
}
/**
* Get the unassigned cases related to the self service timeout
*
* @return array
*/
public static function selfServiceTimeout()
{
$query = ListUnassigned::query()->select();
$query->join('TASK', function ($join) {
$join->on('LIST_UNASSIGNED.TAS_ID', '=', 'TASK.TAS_ID')
->where('TASK.TAS_SELFSERVICE_TIMEOUT', '=', 1);
});
$results = $query->get()->toArray();
return $results;
}
}

View File

@@ -2,8 +2,10 @@
namespace ProcessMaker\Model;
use Configurations;
use Exception;
use G;
use Illuminate\Database\Eloquent\Model;
use RbacUsers;
use RBAC;
/**
@@ -20,22 +22,164 @@ class Process extends Model
// Our custom timestamp columns
const CREATED_AT = 'PRO_CREATE_DATE';
const UPDATED_AT = 'PRO_UPDATE_DATE';
// Columns to see in the process list
public $listColumns = [
'PRO_UID',
'PRO_TITLE',
'PRO_DESCRIPTION',
'PRO_PARENT',
'PRO_STATUS',
'PRO_TYPE',
'PRO_CATEGORY',
'PRO_UPDATE_DATE',
'PRO_CREATE_DATE',
'PRO_CREATE_USER',
'PRO_DEBUG',
'PRO_TYPE_PROCESS',
'USR_UID',
'USR_USERNAME',
'USR_FIRSTNAME',
'USR_LASTNAME',
'CATEGORY_UID',
'CATEGORY_NAME'
];
/**
* Get the columns related to the process list
* @return array
*/
public function getListColumns()
{
return $this->listColumns;
}
/**
* Returns the task related to the process belongs to
*/
public function tasks()
{
return $this->belongsTo(Task::class, 'PRO_ID', 'PRO_ID');
}
/**
* Returns the user creator belongs to
*/
public function creator()
{
return $this->belongsTo(User::class, 'PRO_CREATE_USER', 'USR_UID');
}
/**
* Returns the category related to the process belongs to
*/
public function category()
{
return $this->belongsTo(ProcessCategory::class, 'PRO_CATEGORY', 'CATEGORY_UID');
}
/**
* Scope a query to specific process
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param string $proUid
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeProcess($query, $proUid)
{
return $query->where('PRO_UID', '=', $proUid);
}
/**
* Scope a query to specific title
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param string $title
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeTitle($query, $title)
{
return $query->where('PRO_TITLE', 'LIKE', "%{$title}%");
}
/**
* Scope a query to exclude a specific status
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param string $status
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeNoStatus($query, $status = 'DISABLED')
{
return $query->where('PRO_STATUS', '!=', $status);
}
/**
* Scope a query to include subprocess
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeSubProcess($query)
{
return $query->where('PRO_SUBPROCESS', '=', 1);
}
/**
* Scope a query to include a specific process category
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param string $category
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeCategory($query, $category)
{
return $query->where('PROCESS.PRO_CATEGORY', $category);
}
/**
* Scope a query to include the user owner or public process
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param string $userUid
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopePerUser($query, string $userUid)
{
$query->where(function ($query) use ($userUid) {
$query->orWhere('PRO_CREATE_USER', $userUid);
$query->orWhere('PRO_TYPE_PROCESS', 'PUBLIC');
});
return $query;
}
/**
* Scope a query to include the process related to the specific user
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeJoinUsers($query)
{
$query->join('USERS', function ($join) {
$join->on('PROCESS.PRO_CREATE_USER', '=', 'USERS.USR_UID');
});
return $query;
}
/**
* Scope a query to join with categories
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeJoinCategory($query)
{
$query->leftJoin('PROCESS_CATEGORY', function ($join) {
$join->on('PROCESS.PRO_CATEGORY', '=', 'PROCESS_CATEGORY.CATEGORY_UID');
});
return $query;
}
/**
* Obtains the process list for an specific user and/or for the specific category
*
@@ -82,12 +226,168 @@ class Process extends Model
* @param array $privateProcesses
* @return void
*/
public static function convertPrivateProcessesToPublic($privateProcesses)
public static function convertPrivateProcessesToPublicAndUpdateUser($privateProcesses, $userUid)
{
$admin = RBAC::ADMIN_USER_UID;
$processes = array_column($privateProcesses, 'PRO_ID');
Process::whereIn('PRO_ID', $processes)
->update(['PRO_TYPE_PROCESS' => 'PUBLIC', 'PRO_CREATE_USER' => $admin]);
->update(['PRO_TYPE_PROCESS' => 'PUBLIC']);
Process::where('PRO_CREATE_USER', $userUid)
->update(['PRO_CREATE_USER' => $admin]);
}
/**
* Get the process list applying some extra filters
*
* @param string $catUid
* @param string $proUid
* @param string $title
* @param string $userUid
* @param int $start
* @param int $limit
* @param string $dir
* @param string $sort
* @param boolean $counterByProcess
* @param boolean $subProcess
*
* @return array
* @throw Exception
*/
public static function getProcessesFilter(
$catUid = null,
$proUid = null,
$title = null,
$userUid = null,
$start = 0,
$limit = 25,
$dir = 'ASC',
$sort = 'PRO_CREATE_DATE',
$counterByProcess = true,
$subProcess = false
) {
$process = new Process();
$rows = $process->getListColumns();
if (!in_array($sort, $rows)) {
throw new Exception('The column ' . $sort . ' does not exist');
}
// Select rows
$query = Process::query()->select($rows)->noStatus();
// Join with users
$query->joinUsers();
// Join with category
$query->joinCategory();
// Check if the owner is the user logged or if the process is PUBLIC
if (!empty($userUid)) {
//Only process PRO_TYPE_PROCESS = "PUBLIC" or related user owner
$query->perUser($userUid);
}
// Check if we can list only the sub-process
if ($subProcess) {
$query->subProcess();
}
// Specific process
if ($proUid) {
$query->process($proUid);
}
// Specific process title
if ($title) {
$query->title($title);
}
// Search a specific category
if (!empty($catUid)) {
if ($catUid == 'NONE') {
// Processes without category
$query->category('');
} else {
// Processes with the category $catUid
$query->category($catUid);
}
}
// Order the data
$query->orderBy($sort, $dir);
// Define the pagination
$query->offset($start)->limit($limit);
// Get the results
$results = $query->get();
// Define the class for get workspace configurations
$systemConf = new Configurations();
$systemConf->loadConfig($obj, 'ENVIRONMENT_SETTINGS', '');
$mask = isset($systemConf->aConfig['dateFormat']) ? $systemConf->aConfig['dateFormat'] : '';
// Prepare the final result
$results->transform(function ($item, $key) use ($counterByProcess, $systemConf, $mask){
// Get the counter related to the status
// todo: those counters needs to remove when the PMCORE-2314 was implemented
$item['CASES_COUNT_DRAFT'] = $counterByProcess ? Application::getCountByProUid($item['PRO_UID'], 1) : 0;
$item['CASES_COUNT_TO_DO'] = $counterByProcess ? Application::getCountByProUid($item['PRO_UID'], 2) : 0;
$item['CASES_COUNT_COMPLETED'] = $counterByProcess ? Application::getCountByProUid($item['PRO_UID'], 3) : 0;
$item['CASES_COUNT_CANCELLED'] = $counterByProcess ? Application::getCountByProUid($item['PRO_UID'], 4) : 0;
$item['CASES_COUNT'] = $item['CASES_COUNT_DRAFT'] + $item['CASES_COUNT_TO_DO'] + $item['CASES_COUNT_COMPLETED'] + $item['CASES_COUNT_CANCELLED'];
// Get the description
// todo: we will to remove htmlspecialchars but frontEnd needs to add application wide XSS prevention measures
$item['PRO_DESCRIPTION'] = empty($item['PRO_DESCRIPTION']) ? '' : htmlspecialchars($item['PRO_DESCRIPTION']);
// Get the type: bpmn or classic
$bpmnProcess = BpmnProject::isBpmnProcess($item['PRO_UID']);
$item['PROJECT_TYPE'] = ($bpmnProcess) ? 'bpmn' : 'classic';
// Get the process type: PUBLIC or PRIVATE
$item['PRO_TYPE_PROCESS'] = ($item['PRO_TYPE_PROCESS'] == 'PUBLIC') ? G::LoadTranslation("ID_PUBLIC") : G::LoadTranslation("ID_PRIVATE");;
// Get information about the owner, with the format defined
$creatorOwner = $systemConf->usersNameFormat($item['USR_USERNAME'], $item['USR_FIRSTNAME'], $item['USR_LASTNAME']);
$item['PRO_CREATE_USER_LABEL'] = empty($creatorOwner) ? $item['USR_FIRSTNAME'] . ' ' . $item['USR_LASTNAME'] : $creatorOwner;
// Get debug label
$item['PRO_DEBUG_LABEL'] = ($item['PRO_DEBUG'] == '1') ? G::LoadTranslation('ID_ON') : G::LoadTranslation('ID_OFF');
// Get status label
$item['PRO_STATUS_LABEL'] = $item['PRO_STATUS'] == 'ACTIVE' ? G::LoadTranslation('ID_ACTIVE') : G::LoadTranslation('ID_INACTIVE');
// Get category label
$item['PRO_CATEGORY_LABEL'] = trim($item['PRO_CATEGORY']) != '' ? $item['CATEGORY_NAME'] : G::LoadTranslation('ID_PROCESS_NONE_CATEGORY');
// Apply the date format defined in environment
if (!empty($mask)) {
$item['PRO_CREATE_DATE_LABEL'] = $item['PRO_CREATE_DATE']->format($mask);
$item['PRO_UPDATE_DATE_LABEL'] = $item['PRO_UPDATE_DATE']->format($mask);
}
return $item;
});
return $results->values()->toArray();
}
/**
* Get the number of rows corresponding to the process
*
* @param string $userUid
* @return integer
*/
public static function getCounter($userUid = '')
{
$query = Process::query()->select();
$query->noStatus();
if (!empty($userUid)) {
//Only process PRO_TYPE_PROCESS = "PUBLIC" or related user owner
$query->perUser($userUid);
}
return $query->count();
}
}

View File

@@ -16,4 +16,26 @@ class ProcessCategory extends Model
protected $table = 'PROCESS_CATEGORY';
public $timestamps = false;
/**
* Get the categories
*
* @param string $dir
*
* @return array
*
* @see ProcessProxy::categoriesList()
* @link https://wiki.processmaker.com/3.0/Process_Categories
*/
public static function getCategories( $dir = 'ASC')
{
$query = ProcessCategory::query()
->select([
'CATEGORY_UID',
'CATEGORY_NAME'
])
->orderBy('CATEGORY_NAME', $dir);
return $query->get()->values()->toArray();
}
}

View File

@@ -10,11 +10,34 @@ class Triggers extends Model
protected $table = 'TRIGGERS';
// No timestamps
public $timestamps = false;
//primary key
// Primary key
protected $primaryKey = 'TRI_UID';
//No incrementing
// No incrementing
public $incrementing = false;
// Filter by a specific uid
private $triUid = '';
/**
* Set trigger uid
*
* @param string $triUid
*/
public function setTrigger($triUid)
{
$this->triUid = $triUid;
}
/**
* Get trigger uid
*
* @return int
*/
public function getTrigger()
{
return $this->triUid;
}
/**
* Scope a query to filter an specific process
*
@@ -22,8 +45,37 @@ class Triggers extends Model
* @param string $columns
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeProcess($query, string $proUID)
public function scopeProcess($query, string $proUid)
{
return $query->where('PRO_UID', $proUID);
return $query->where('PRO_UID', $proUid);
}
/**
* Scope a query to filter an specific trigger
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param string $triUid
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeTrigger($query, string $triUid)
{
return $query->where('TRI_UID', $triUid);
}
/**
* Get the records
*
* @return array
*/
public function triggers()
{
$query = Triggers::query()->select();
// Specific trigger
if (!empty($this->getTrigger())) {
$query->trigger($this->getTrigger());
}
$results = $query->get()->toArray();
return $results;
}
}