Merged in feature/PMCORE-3049 (pull request #7964)

PMCORE-3049 PRD

Approved-by: Henry Jonathan Quispe Quispe
Approved-by: Julio Cesar Laura Avendaño
This commit is contained in:
Paula Quispe
2021-09-06 20:40:34 +00:00
committed by Julio Cesar Laura Avendaño
214 changed files with 29643 additions and 4643 deletions

View File

@@ -8,4 +8,116 @@ class AppDelay extends Model
{
protected $table = 'APP_DELAY';
public $timestamps = false;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'APP_DELAY_UID',
'PRO_UID',
'PRO_ID',
'APP_UID',
'APP_NUMBER',
'APP_THREAD_INDEX',
'APP_DEL_INDEX',
'APP_TYPE',
'APP_STATUS',
'APP_DELEGATION_USER',
'APP_DELEGATION_USER_ID'.
'APP_ENABLE_ACTION_USER',
'APP_ENABLE_ACTION_DATE',
'APP_DISABLE_ACTION_DATE',
];
/**
* Scope a query to filter a specific type
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param string $type
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeType($query, string $type = 'PAUSE')
{
return $query->where('APP_DELAY.APP_TYPE', $type);
}
/**
* Scope a query to filter a specific disable action
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeNotDisabled($query)
{
return $query->where('APP_DELAY.APP_DISABLE_ACTION_USER', 0);
}
/**
* Scope a query to filter a specific case
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param int $appNumber
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeCase($query, int $appNumber)
{
return $query->where('APP_DELAY.APP_NUMBER', $appNumber);
}
/**
* Scope a query to filter a specific index
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param int $index
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeIndex($query, int $index)
{
return $query->where('APP_DELAY.APP_DEL_INDEX', $index);
}
/**
* Scope a query to filter a specific user
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param string $user
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeDelegateUser($query, string $user)
{
return $query->where('APP_DELAY.APP_DELEGATION_USER', $user);
}
/**
* Get the thread paused
*
* @param int $appNumber
* @param int $index
* @param string $userUid
*
* @return array
*/
public static function getPaused(int $appNumber, int $index, string $userUid = '')
{
$query = AppDelay::query()->select([
'APP_NUMBER',
'APP_DEL_INDEX AS DEL_INDEX',
'PRO_UID'
]);
$query->type('PAUSE')->notDisabled();
$query->case($appNumber);
// Filter specific index
if ($index > 0) {
$query->index($index);
}
// Filter specific delegate user
if (!empty($userUid)) {
$query->delegateUser($userUid);
}
// Get the result
$results = $query->get();
return $results->values()->toArray();
}
}

View File

@@ -9,4 +9,46 @@ class AppThread extends Model
protected $table = 'APP_THREAD';
// We do not have create/update timestamps for this table
public $timestamps = false;
/**
* Scope a query to filter a specific case
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param string $appUid
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeAppUid($query, string $appUid)
{
return $query->where('APP_UID', $appUid);
}
/**
* Scope a query to filter a specific index
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param int $index
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeIndex($query, int $index)
{
return $query->where('DEL_INDEX', $index);
}
/**
* Get thread related to the specific case and index
*
* @param string $appUid
* @param int $index
*
* @return array
*/
public static function getThread(string $appUid, int $index)
{
$query = AppThread::query()->select(['APP_THREAD_INDEX']);
$query->appUid($appUid);
$query->index($index);
$results = $query->get()->toArray();
return $results;
}
}

View File

@@ -43,7 +43,7 @@ class Application extends Model
* @param int $user
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeUserId($query, $user)
public function scopeUserId($query, int $user)
{
return $query->where('APP_DELEGATION.USR_ID', '=', $user);
}
@@ -135,18 +135,49 @@ class Application extends Model
*/
public function scopeRangeOfCases($query, array $rangeCases)
{
foreach ($rangeCases as $fromTo) {
$fromTo = explode("-", $fromTo);
if (count($fromTo) === 2) {
$from = $fromTo[0];
$to = $fromTo[1];
if ($to > $from) {
$query->orWhere(function ($query) use ($from, $to) {
$query->casesFrom($from)->casesTo($to);
});
$query->where(function ($query) use ($rangeCases) {
foreach ($rangeCases as $fromTo) {
$fromTo = explode("-", $fromTo);
if (count($fromTo) === 2) {
$from = $fromTo[0];
$to = $fromTo[1];
if ($to > $from) {
$query->orWhere(function ($query) use ($from, $to) {
$query->casesFrom($from)->casesTo($to);
});
}
}
}
}
});
}
/**
* Scope more than one range of cases
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param array $cases
* @param array $rangeCases
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeCasesOrRangeOfCases($query, array $cases, array $rangeCases)
{
$query->where(function ($query) use ($cases, $rangeCases) {
// Get the cases related to the task self service
$query->specificCases($cases);
foreach ($rangeCases as $fromTo) {
$fromTo = explode("-", $fromTo);
if (count($fromTo) === 2) {
$from = $fromTo[0];
$to = $fromTo[1];
if ($to > $from) {
$query->orWhere(function ($query) use ($from, $to) {
$query->casesFrom($from)->casesTo($to);
});
}
}
}
});
}
/**
@@ -201,6 +232,19 @@ class Application extends Model
return $query->whereIn('APPLICATION.APP_STATUS_ID', $statuses);
}
/**
* Scope a query to only include specific category
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param int $category
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeCategory($query, $category)
{
return $query->where('PROCESS.CATEGORY_ID', $category);
}
/**
* Scope for query to get the applications by PRO_UID.
*
@@ -311,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.
*
@@ -330,7 +392,7 @@ class Application extends Model
}
/**
* Get information related to the created case
* Get information related to the case, avoiding to load the APP_DATA
*
* @param string $appUid
*
@@ -338,7 +400,13 @@ class Application extends Model
*/
public static function getCase($appUid)
{
$query = Application::query()->select(['APP_STATUS', 'APP_INIT_USER']);
$query = Application::query()->select([
'APP_NUMBER',
'APP_STATUS',
'PRO_UID',
'PRO_ID',
'APP_INIT_USER'
]);
$query->appUid($appUid);
$result = $query->get()->toArray();
$firstElement = head($result);

View File

@@ -0,0 +1,551 @@
<?php
namespace ProcessMaker\Model;
use Exception;
use G;
use ProcessMaker\BusinessModel\Table;
use ProcessMaker\Core\System;
use ProcessMaker\Model\AdditionalTables;
use ProcessMaker\Model\Fields;
use ProcessMaker\Model\User;
use Illuminate\Database\Eloquent\Model;
class CaseList extends Model
{
/**
* The table associated with the model.
* @var string
*/
protected $table = 'CASE_LIST';
/**
* The primary key for the model.
* @var string
*/
protected $primaryKey = 'CAL_ID';
/**
* Indicates if the IDs are auto-incrementing.
* @var bool
*/
public $incrementing = true;
/**
* Indicates if the model should be timestamped.
* @var bool
*/
public $timestamps = false;
/**
* The attributes that aren't mass assignable.
* @var array
*/
protected $guarded = [];
/**
* Represents the column aliases.
* @var array
*/
private static $columnAliases = [
'CAL_ID' => 'id',
'CAL_TYPE' => 'type',
'CAL_NAME' => 'name',
'CAL_DESCRIPTION' => 'description',
'ADD_TAB_UID' => 'tableUid',
'CAL_COLUMNS' => 'columns',
'USR_ID' => 'userId',
'CAL_ICON_LIST' => 'iconList',
'CAL_ICON_COLOR' => 'iconColor',
'CAL_ICON_COLOR_SCREEN' => 'iconColorScreen',
'CAL_CREATE_DATE' => 'createDate',
'CAL_UPDATE_DATE' => 'updateDate',
'USR_USERNAME' => 'userName',
'USR_FIRSTNAME' => 'userFirstname',
'USR_LASTNAME' => 'userLastname',
'USR_EMAIL' => 'userEmail',
'USR_POSITION' => 'userPosition',
'ADD_TAB_NAME' => 'tableName',
'PRO_TITLE' => 'process'
];
/**
* Represents the columns exclude from report table.
* @var array
*/
public static $excludeColumns = ['APP_UID', 'APP_NUMBER', 'APP_STATUS'];
/**
* Get column name from alias.
* @param array $array
* @return array
*/
public static function getColumnNameFromAlias(array $array): array
{
foreach (self::$columnAliases as $key => $value) {
if (array_key_exists($value, $array)) {
$array[$key] = $array[$value];
unset($array[$value]);
}
}
return $array;
}
/**
* Get alias from column name.
* @param array $array
* @return array
*/
public static function getAliasFromColumnName(array $array)
{
foreach (self::$columnAliases as $key => $value) {
if (array_key_exists($key, $array)) {
$array[$value] = $array[$key];
unset($array[$key]);
}
}
return $array;
}
/**
* Create and save this model from array values.
* @param array $values
* @param int $ownerId
* @return object
*/
public static function createSetting(array $values, int $ownerId)
{
$attributes = CaseList::getColumnNameFromAlias($values);
$attributes['USR_ID'] = $ownerId;
$attributes['CAL_CREATE_DATE'] = date("Y-m-d H:i:s");
$attributes['CAL_UPDATE_DATE'] = date("Y-m-d H:i:s");
if (empty($attributes['CAL_COLUMNS'])) {
$attributes['CAL_COLUMNS'] = [];
}
$attributes['CAL_COLUMNS'] = json_encode($attributes['CAL_COLUMNS']);
$model = CaseList::create($attributes);
$model->CAL_COLUMNS = json_decode($model->CAL_COLUMNS);
return $model;
}
/**
* Update and save this model from array values.
* @param int $id
* @param array $values
* @param int $ownerId
* @return object
*/
public static function updateSetting(int $id, array $values, int $ownerId)
{
$attributes = CaseList::getColumnNameFromAlias($values);
$attributes['USR_ID'] = $ownerId;
$attributes['CAL_UPDATE_DATE'] = date("Y-m-d H:i:s");
if (empty($attributes['CAL_COLUMNS'])) {
$attributes['CAL_COLUMNS'] = [];
}
$attributes['CAL_COLUMNS'] = json_encode($attributes['CAL_COLUMNS']);
$caseList = CaseList::where('CAL_ID', '=', $id);
$caseList->update($attributes);
$model = $caseList->get()->first();
if (!is_null($model)) {
$model->CAL_COLUMNS = json_decode($model->CAL_COLUMNS);
}
return $model;
}
/**
* Delete this model.
* @param int $id
* @return object
*/
public static function deleteSetting(int $id)
{
$caseList = CaseList::where('CAL_ID', '=', $id);
$model = $caseList->get()->first();
if (!is_null($model)) {
$caseList->delete();
$model->CAL_COLUMNS = json_decode($model->CAL_COLUMNS);
}
return $model;
}
/**
* Get the array of the elements of this model, this method supports the filter by:
* name, description, user name, first user name, second user name, user email.
* The result is returned based on the delimiters to allow pagination and the total
* of the existing models.
* @param string $type
* @param string $search
* @param int $offset
* @param int $limit
* @param bool $paged
* @return array
*/
public static function getSetting(string $type, string $search, int $offset, int $limit, bool $paged = true): array
{
$order = 'asc';
$model = CaseList::where('CAL_TYPE', '=', $type)
->leftJoin('USERS', 'USERS.USR_ID', '=', 'CASE_LIST.USR_ID')
->leftJoin('ADDITIONAL_TABLES', 'ADDITIONAL_TABLES.ADD_TAB_UID', '=', 'CASE_LIST.ADD_TAB_UID')
->leftJoin('PROCESS', 'PROCESS.PRO_UID', '=', 'ADDITIONAL_TABLES.PRO_UID')
->select([
'CASE_LIST.*',
'PROCESS.PRO_TITLE',
'ADDITIONAL_TABLES.ADD_TAB_NAME',
'USERS.USR_UID', 'USERS.USR_USERNAME', 'USERS.USR_FIRSTNAME', 'USERS.USR_LASTNAME', 'USERS.USR_EMAIL', 'USERS.USR_POSITION'
])
->where(function ($query) use ($search) {
$query
->orWhere('CASE_LIST.CAL_NAME', 'like', '%' . $search . '%')
->orWhere('PROCESS.PRO_TITLE', 'like', '%' . $search . '%')
->orWhere('ADDITIONAL_TABLES.ADD_TAB_NAME', 'like', '%' . $search . '%');
})
->orderBy('CASE_LIST.CAL_NAME', $order);
$count = $model->count();
if ($paged === true) {
$model->offset($offset)->limit($limit);
}
$data = $model->get();
$data->transform(function ($item, $key) {
if (is_null($item->CAL_COLUMNS)) {
$item->CAL_COLUMNS = '[]';
}
$result = CaseList::getAliasFromColumnName($item->toArray());
$columns = json_decode($result['columns']);
$columns = CaseList::formattingColumns($result['type'], $result['tableUid'], $columns);
$result['columns'] = $columns;
$result['userAvatar'] = System::getServerMainPath() . '/users/users_ViewPhotoGrid?pUID=' . $result['USR_UID'] . '&h=' . microtime(true);
unset($result['USR_UID']);
return $result;
});
return [
'total' => $count,
'data' => $data
];
}
/**
* The export creates a temporary file with record data in json format.
* @param int $id
* @throws Exception
*/
public static function export(int $id)
{
$model = CaseList::where('CAL_ID', '=', $id)
->leftJoin('USERS', 'USERS.USR_ID', '=', 'CASE_LIST.USR_ID')
->leftJoin('ADDITIONAL_TABLES', 'ADDITIONAL_TABLES.ADD_TAB_UID', '=', 'CASE_LIST.ADD_TAB_UID')
->select([
'CASE_LIST.*',
'ADDITIONAL_TABLES.ADD_TAB_NAME'
])
->get()
->first();
if (empty($model)) {
throw new Exception(G::LoadTranslation('ID_DOES_NOT_EXIST'));
}
$result = CaseList::getAliasFromColumnName($model->toArray());
$result['columns'] = json_decode($result['columns']);
$result['tableName'] = $model->ADD_TAB_NAME;
//clean invalid items
unset($result['id']);
unset($result['userId']);
unset($result['createDate']);
unset($result['updateDate']);
//random name to distinguish the different sessions
$filename = sys_get_temp_dir() . "/pm" . random_int(10000, 99999);
file_put_contents($filename, json_encode($result));
return [
'filename' => $filename,
'downloadFilename' => $result['name'] . ' ' . date('Y-m-d H:i:s') . '.json',
'data' => $result
];
}
/**
* The import requires a $ _FILES content in json format to create a record.
* @param array $requestData
* @param int $ownerId
* @return array
* @throws Exception
*/
public static function import(array $requestData, int $ownerId)
{
if ($_FILES['file_content']['error'] !== UPLOAD_ERR_OK ||
$_FILES['file_content']['tmp_name'] === '') {
throw new Exception(G::LoadTranslation('ID_ERROR_UPLOAD_FILE_CONTACT_ADMINISTRATOR'));
}
$content = file_get_contents($_FILES['file_content']['tmp_name']);
try {
$array = json_decode($content, true);
$tableName = $array['tableName'];
unset($array['tableName']);
//the pmtable not exist
$table = AdditionalTables::where('ADD_TAB_NAME', '=', $tableName)
->get()
->first();
if ($table === null) {
return [
'status' => 'tableNotExist',
'message' => G::LoadTranslation('ID_CASELIST_CAN_NOT_BE_IMPORTED_THE_PMTABLE_NOT_EXIST', [$_FILES['file_content']['name']])
];
}
$array['tableUid'] = $table->ADD_TAB_UID;
//the fields have differences between the import file and the current table
$requestData['invalidFields'] = $requestData['invalidFields'] ?? '';
if ($requestData['invalidFields'] !== 'continue') {
$fields = [];
$columns = CaseList::formattingColumns($array['type'], $array['tableUid'], []);
foreach ($columns as $column) {
$fields[] = $column['field'];
}
foreach ($array['columns'] as $value) {
if (!in_array($value['field'], $fields)) {
return [
'status' => 'invalidFields',
'message' => G::LoadTranslation('ID_PMTABLE_NOT_HAVE_ALL_CASELIST_FIELDS_WOULD_YOU_LIKE_CONTINUE', [$tableName, $_FILES['file_content']['name']])
];
}
}
}
//the name of the case list already exist
$list = CaseList::where('CAL_NAME', '=', $array['name'])
->get()
->first();
$requestData['duplicateName'] = $requestData['duplicateName'] ?? '';
if ($requestData['duplicateName'] !== 'continue') {
if ($list !== null) {
return [
'status' => 'duplicateName',
'message' => G::LoadTranslation('ID_IMPORTING_CASELIST_WITH_THE_SAME_NAME_SELECT_OPTION', [$array['name']])
];
}
}
if ($requestData['duplicateName'] === 'continue' && $list !== null) {
$caseList = CaseList::updateSetting($list->CAL_ID, $array, $ownerId);
} else {
$caseList = CaseList::createSetting($array, $ownerId);
}
$result = CaseList::getAliasFromColumnName($caseList->toArray());
return $result;
} catch (Exception $e) {
throw new Exception($e->getMessage());
}
}
/**
* Formatting columns from minimal stored columns configuration in custom cases list.
* @param string $type
* @param string $tableUid
* @param array $storedColumns
* @return array
*/
public static function formattingColumns(string $type = 'inbox', string $tableUid = '', array $storedColumns = [])
{
$default = [
[
'list' => ['inbox', 'draft', 'paused', 'unassigned'],
'field' => 'case_number',
'name' => G::LoadTranslation('ID_MYCASE_NUMBER'),
'type' => 'integer',
'source' => 'APPLICATION',
'typeSearch' => 'integer range',
'enableFilter' => false,
'set' => true
], [
'list' => ['inbox', 'draft', 'paused', 'unassigned'],
'field' => 'case_title',
'name' => G::LoadTranslation('ID_CASE_TITLE'),
'type' => 'string',
'source' => 'APPLICATION',
'typeSearch' => 'search text',
'enableFilter' => false,
'set' => true
], [
'list' => ['inbox', 'draft', 'paused', 'unassigned'],
'field' => 'process_name',
'name' => G::LoadTranslation('ID_PROCESS_NAME'),
'type' => 'string',
'source' => 'APPLICATION',
'typeSearch' => 'search text',
'enableFilter' => false,
'set' => true
], [
'list' => ['inbox', 'draft', 'paused', 'unassigned'],
'field' => 'task',
'name' => G::LoadTranslation('ID_TASK'),
'type' => 'string',
'source' => 'APPLICATION',
'typeSearch' => 'search text',
'enableFilter' => false,
'set' => true
], [
'list' => ['inbox', 'draft', 'paused', 'unassigned'],
'field' => 'send_by',
'name' => G::LoadTranslation('ID_SEND_BY'),
'type' => 'string',
'source' => 'APPLICATION',
'typeSearch' => 'search text',
'enableFilter' => false,
'set' => true
], [
'list' => ['inbox', 'paused', 'unassigned'],
'field' => 'due_date',
'name' => G::LoadTranslation('ID_DUE_DATE'),
'type' => 'date',
'source' => 'APPLICATION',
'typeSearch' => 'date range',
'enableFilter' => false,
'set' => true
], [
'list' => ['inbox', 'paused', 'unassigned'],
'field' => 'delegation_date',
'name' => G::LoadTranslation('ID_DELEGATION_DATE'),
'type' => 'date',
'source' => 'APPLICATION',
'typeSearch' => 'date range',
'enableFilter' => false,
'set' => true
], [
'list' => ['inbox', 'draft', 'paused', 'unassigned'],
'field' => 'priority',
'name' => G::LoadTranslation('ID_PRIORITY'),
'type' => 'string',
'source' => 'APPLICATION',
'typeSearch' => 'option',
'enableFilter' => false,
'set' => true
],
];
//filter by type
$result = [];
foreach ($default as &$column) {
if (in_array($type, $column['list'])) {
unset($column['list']);
$result[] = $column;
}
}
$default = $result;
//get additional tables
$additionalTables = AdditionalTables::where('ADD_TAB_UID', '=', $tableUid)
->where('PRO_UID', '<>', '')
->whereNotNull('PRO_UID')
->get();
$additionalTables->transform(function ($object) {
$table = new Table();
return $table->getTable($object->ADD_TAB_UID, $object->PRO_UID, true, false);
});
$result = $additionalTables->toArray();
if (!empty($result)) {
$result = $result[0];
if (isset($result['fields'])) {
foreach ($result['fields'] as $column) {
if (in_array($column['fld_name'], self::$excludeColumns)) {
continue;
}
$default[] = [
'field' => $column['fld_name'],
'name' => $column['fld_name'],
'type' => $column['fld_type'],
'source' => $result['rep_tab_name'],
'typeSearch' => 'search text',
'enableFilter' => false,
'set' => false
];
}
}
}
//merge with stored information
$result = [];
foreach ($default as &$column) {
foreach ($storedColumns as $storedColumn) {
if (!is_object($storedColumn)) {
continue;
}
$storedColumn = (array) $storedColumn;
if (!isset($storedColumn['field'])) {
continue;
}
if ($column['field'] === $storedColumn['field']) {
if (isset($storedColumn['enableFilter'])) {
$column['enableFilter'] = $storedColumn['enableFilter'];
}
if (isset($storedColumn['set'])) {
$column['set'] = $storedColumn['set'];
}
break;
}
}
$result[] = $column;
}
return $result;
}
/**
* Get the report tables, this can filter the results by the search parameter.
* @param string $search
* @return array
*/
public static function getReportTables(string $search = '')
{
$additionalTables = AdditionalTables::where('ADD_TAB_NAME', 'LIKE', "%{$search}%")
->where('PRO_UID', '<>', '')
->whereNotNull('PRO_UID')
->get();
$additionalTables->transform(function ($object) {
$table = new Table();
$result = $table->getTable($object->ADD_TAB_UID, $object->PRO_UID, true, false);
$fields = [];
if (isset($result['fields'])) {
foreach ($result['fields'] as $column) {
if (in_array($column['fld_name'], self::$excludeColumns)) {
continue;
}
$fields[] = [
'field' => $column['fld_name'],
'name' => $column['fld_name'],
'type' => $column['fld_type'],
'source' => $result['rep_tab_name'],
'typeSearch' => 'search text',
'enableFilter' => false,
'set' => false
];
}
}
$format = [
'uid' => $result['rep_uid'],
'name' => $result['rep_tab_name'],
'description' => $result['rep_tab_description'],
'fields' => $fields
];
return $format;
});
$result = $additionalTables->toArray();
return $result;
}
}

View File

@@ -24,6 +24,8 @@ class Delegation extends Model
// Static properties to preserve values
public static $usrUid = '';
public static $groups = [];
// Status name and status id
public static $thread_status = ['CLOSED' => 0, 'OPEN' => 1, 'PAUSED' => 3];
/**
* Returns the application this delegation belongs to
@@ -92,6 +94,34 @@ class Delegation extends Model
return $query->where('APP_DELEGATION.DEL_THREAD_STATUS', '=', 'OPEN');
}
/**
* Scope a query to only include pause threads
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeThreadPause($query)
{
return $query->where('APP_DELEGATION.DEL_THREAD_STATUS_ID', '=', 3);
}
/**
* Scope a query to only include open and pause threads
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeOpenAndPause($query)
{
$query->where(function ($query) {
$query->threadOpen();
$query->orWhere(function ($query) {
$query->threadPause();
});
});
return $query;
}
/**
* Scope to use when the case is IN_PROGRESS like DRAFT or TO_DO
*
@@ -101,7 +131,7 @@ class Delegation extends Model
*/
public function scopeCasesInProgress($query, array $ids)
{
$query->isThreadOpen()->statusIds($ids);
$query->threadOpen()->statusIds($ids);
return $query;
}
@@ -143,18 +173,6 @@ class Delegation extends Model
return $query->where('DEL_INDEX', '=', 1);
}
/**
* Scope a query to get the in-progress
*
* @param \Illuminate\Database\Eloquent\Builder $query
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeCaseInProgress($query)
{
return $query->statusIds([Application::STATUS_DRAFT, Application::STATUS_TODO]);
}
/**
* Scope a query to get the to_do cases
*
@@ -351,36 +369,39 @@ class Delegation extends Model
* Scope a query to get only the date on time
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param string $now
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeOnTime($query)
public function scopeOnTime($query, $now)
{
return $query->whereRaw('TIMEDIFF(DEL_RISK_DATE, NOW()) > 0');
return $query->where('DEL_RISK_DATE', '>', $now);
}
/**
* Scope a query to get only the date at risk
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param string $now
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeAtRisk($query)
public function scopeAtRisk($query, $now)
{
return $query->whereRaw('TIMEDIFF(DEL_RISK_DATE, NOW()) < 0 AND TIMEDIFF(DEL_TASK_DUE_DATE, NOW()) > 0');
return $query->where('DEL_RISK_DATE', '<=', $now)->where('DEL_TASK_DUE_DATE', '>=', $now);
}
/**
* Scope a query to get only the date overdue
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param string $now
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeOverdue($query)
public function scopeOverdue($query, $now)
{
return $query->whereRaw('TIMEDIFF(DEL_TASK_DUE_DATE, NOW()) < 0');
return $query->where('DEL_TASK_DUE_DATE', '<', $now);
}
/**
@@ -421,7 +442,7 @@ class Delegation extends Model
$query->whereRaw("MATCH(APP_DELEGATION.DEL_TITLE) AGAINST('{$search}' IN BOOLEAN MODE)");
} else {
// Searching using "like" operator
$query->where('APP_DELEGATION.DEL_TITLE', 'LIKE', "%${$search}%");
$query->where('APP_DELEGATION.DEL_TITLE', 'LIKE', "%{$search}%");
}
return $query;
@@ -488,18 +509,49 @@ class Delegation extends Model
*/
public function scopeRangeOfCases($query, array $rangeCases)
{
foreach ($rangeCases as $fromTo) {
$fromTo = explode("-", $fromTo);
if (count($fromTo) === 2) {
$from = $fromTo[0];
$to = $fromTo[1];
if ($to > $from) {
$query->orWhere(function ($query) use ($from, $to) {
$query->casesFrom($from)->casesTo($to);
});
$query->where(function ($query) use ($rangeCases) {
foreach ($rangeCases as $fromTo) {
$fromTo = explode("-", $fromTo);
if (count($fromTo) === 2) {
$from = $fromTo[0];
$to = $fromTo[1];
if ($to > $from) {
$query->orWhere(function ($query) use ($from, $to) {
$query->casesFrom($from)->casesTo($to);
});
}
}
}
}
});
}
/**
* Scope more than one range of cases
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param array $cases
* @param array $rangeCases
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeCasesOrRangeOfCases($query, array $cases, array $rangeCases)
{
$query->where(function ($query) use ($cases, $rangeCases) {
// Get the cases related to the task self service
$query->specificCases($cases);
foreach ($rangeCases as $fromTo) {
$fromTo = explode("-", $fromTo);
if (count($fromTo) === 2) {
$from = $fromTo[0];
$to = $fromTo[1];
if ($to > $from) {
$query->orWhere(function ($query) use ($from, $to) {
$query->casesFrom($from)->casesTo($to);
});
}
}
}
});
}
/**
@@ -515,17 +567,6 @@ class Delegation extends Model
return $query->where('APP_DELEGATION.APP_UID', '=', $appUid);
}
/**
* Scope a query to only include open threads
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeIsThreadOpen($query)
{
return $query->where('APP_DELEGATION.DEL_THREAD_STATUS', '=', 'OPEN');
}
/**
* Scope a query to get the last thread
*
@@ -580,7 +621,7 @@ class Delegation extends Model
* @param int $user
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeUserId($query, $user)
public function scopeUserId($query, int $user)
{
return $query->where('APP_DELEGATION.USR_ID', '=', $user);
}
@@ -746,26 +787,6 @@ class Delegation extends Model
return $query;
}
/**
* Scope the Inbox cases
*
* @param \Illuminate\Database\Eloquent\Builder $query
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeInboxWithoutUser($query)
{
// This scope is for the join with the APP_DELEGATION table
$query->joinApplication();
$query->status(Application::STATUS_TODO);
// Scope for the restriction of the task that must not be searched for
$query->excludeTaskTypes(Task::DUMMY_TASKS);
// Scope that establish that the DEL_THREAD_STATUS must be OPEN
$query->threadOpen();
return $query;
}
/**
* Scope a self service cases
*
@@ -822,6 +843,33 @@ class Delegation extends Model
return $query;
}
/**
* Scope process category id
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param int $category
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeCategoryId($query, int $category)
{
return $query->where('PROCESS.CATEGORY_ID', $category);
}
/**
* Scope top ten
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param string $column
* @param string $order
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeTopTen($query, $column, $order)
{
return $query->orderBy($column, $order)->limit(10);
}
/**
* Scope join with delegation for get the previous index
*
@@ -1324,7 +1372,7 @@ class Delegation extends Model
* @param string $appUid
* @return array
*
* @see \ProcessMaker\BusinessModel\Cases:getStatusInfo()
* @see \ProcessMaker\BusinessModel\Cases::getStatusInfo()
*/
public static function getParticipatedInfo($appUid)
{
@@ -1488,7 +1536,7 @@ class Delegation extends Model
// Start the second query
$query2 = Delegation::query()->select($selectedColumns);
$query2->tasksIn($selfServiceTasks);
$query2->isThreadOpen();
$query2->threadOpen();
$query2->noUserInThread();
// Add join clause with the previous APP_DELEGATION record if required
@@ -1720,7 +1768,7 @@ class Delegation extends Model
*/
public static function getThreadInfo(int $appNumber, int $index)
{
$query = Delegation::query()->select(['APP_NUMBER', 'TAS_UID', 'TAS_ID', 'DEL_PREVIOUS', 'DEL_TITLE']);
$query = Delegation::query()->select(['APP_NUMBER', 'TAS_UID', 'TAS_ID', 'DEL_PREVIOUS', 'DEL_TITLE', 'USR_ID']);
$query->where('APP_NUMBER', $appNumber);
$query->where('DEL_INDEX', $index);
$query->limit(1);
@@ -1782,10 +1830,11 @@ class Delegation extends Model
* Return the open thread related to the task
*
* @param int $appNumber
* @param bool $onlyOpen
*
* @return array
*/
public static function getPendingThreads(int $appNumber)
public static function getPendingThreads(int $appNumber, $onlyOpen = true)
{
$query = Delegation::query()->select([
'TASK.TAS_UID',
@@ -1795,6 +1844,7 @@ class Delegation extends Model
'APP_DELEGATION.DEL_INDEX',
'APP_DELEGATION.DEL_TITLE',
'APP_DELEGATION.USR_ID',
'APP_DELEGATION.DEL_THREAD_STATUS',
'APP_DELEGATION.DEL_DELEGATE_DATE',
'APP_DELEGATION.DEL_FINISH_DATE',
'APP_DELEGATION.DEL_INIT_DATE',
@@ -1803,7 +1853,11 @@ class Delegation extends Model
// Join with task
$query->joinTask();
// Get the open threads
$query->threadOpen();
if ($onlyOpen) {
$query->threadOpen();
} else {
$query->openAndPause();
}
// Related to the specific case number
$query->case($appNumber);
// Get the results
@@ -1924,10 +1978,8 @@ class Delegation extends Model
'TASK.TAS_ASSIGN_TYPE', // Task assign rule
'APP_DELEGATION.DEL_TITLE', // Thread title
'APP_DELEGATION.DEL_THREAD_STATUS', // Thread status
'APP_DELEGATION.USR_UID', // Current UserUid
'APP_DELEGATION.USR_ID', // Current UserId
'USERS.USR_USERNAME', // Current UserName
'USERS.USR_FIRSTNAME', // Current User FirstName
'USERS.USR_LASTNAME', // Current User LastName
'APP_DELEGATION.DEL_TASK_DUE_DATE', // Due Date
// Additional column for other functionalities
'APP_DELEGATION.APP_UID', // Case Uid for Open case
@@ -1937,10 +1989,8 @@ class Delegation extends Model
]);
// Join with task
$query->joinTask();
// Join with task
$query->joinUser();
// Get the open threads
$query->threadOpen();
// Get the open and paused threads
$query->openAndPause();
// Related to the specific case number
$query->case($appNumber);
// Get the results
@@ -1950,6 +2000,12 @@ class Delegation extends Model
$item['TAS_COLOR'] = $abs->getTaskColor($item['DEL_TASK_DUE_DATE']);
$item['TAS_COLOR_LABEL'] = AbstractCases::TASK_COLORS[$item['TAS_COLOR']];
$item['UNASSIGNED'] = ($item['TAS_ASSIGN_TYPE'] === 'SELF_SERVICE' ? true : false);
$userInfo = User::getInformation($item['USR_ID']);
$item['user_tooltip'] = $userInfo;
$item['USR_USERNAME'] = !empty($userInfo['usr_username']) ? $userInfo['usr_username'] : '';
$item['USR_LASTNAME'] = !empty($userInfo['usr_lastname']) ? $userInfo['usr_lastname'] : '';
$item['USR_FIRSTNAME'] = !empty($userInfo['usr_firstname']) ? $userInfo['usr_firstname'] : '';
return $item;
});
@@ -1975,4 +2031,79 @@ class Delegation extends Model
}
return false;
}
/**
* Get cases completed by specific user
*
* @param int $userId
* @param int $offset
* @param int $limit
*
* @return array
*/
public static function casesCompletedBy(int $userId, int $offset = 0, int $limit = 15)
{
// Get the case numbers related to this filter
$query = Delegation::query()->select(['APP_NUMBER']);
// Filter the user
$query->participated($userId);
// Filter the last thread
$query->lastThread();
// Apply the limit
$query->offset($offset)->limit($limit);
// Get the result
$results = $query->get();
return $results->values()->toArray();
}
/**
* Get cases started by specific user
*
* @param int $userId
* @param int $offset
* @param int $limit
*
* @return array
*/
public static function casesStartedBy(int $userId, int $offset = 0, int $limit = 15)
{
// Get the case numbers related to this filter
$query = Delegation::query()->select(['APP_NUMBER']);
// Filter the user
$query->participated($userId);
// Filter the first thread
$query->caseStarted();
// Apply the limit
$query->offset($offset)->limit($limit);
// Get the result
$results = $query->get();
return $results->values()->toArray();
}
/**
* Get cases filter by thread title
*
* @param string $search
* @param int $offset
* @param int $limit
*
* @return array
*/
public static function casesThreadTitle(string $search, int $offset = 0, int $limit = 15)
{
// Get the case numbers related to this filter
$query = Delegation::query()->select(['APP_NUMBER']);
// Filter the title
$query->title($search);
// Group by
$query->groupBy('APP_NUMBER');
// Apply the limit
$query->offset($offset)->limit($limit);
// Get the result
$results = $query->get();
return $results->values()->toArray();
}
}

View File

@@ -17,6 +17,18 @@ class ProcessCategory extends Model
public $timestamps = false;
/**
* Scope a query to specific category name
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param string $name
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeCategoryName($query, $name)
{
return $query->where('CATEGORY_NAME', 'LIKE', "%{$name}%");
}
/**
* Get the categories
*
@@ -27,7 +39,7 @@ class ProcessCategory extends Model
* @see ProcessProxy::categoriesList()
* @link https://wiki.processmaker.com/3.0/Process_Categories
*/
public static function getCategories( $dir = 'ASC')
public static function getCategories($dir = 'ASC')
{
$query = ProcessCategory::query()
->select([
@@ -38,4 +50,46 @@ class ProcessCategory extends Model
return $query->get()->values()->toArray();
}
/**
* Get the process categories
*
* @param string $name
* @param int $start
* @param int $limit
*
* @return array
*
* @see ProcessMaker\Services\Api\Home::getCategories()
*/
public static function getProcessCategories($name = null, $start = null, $limit = null)
{
$query = ProcessCategory::query()->select(['CATEGORY_ID', 'CATEGORY_NAME']);
if (!is_null($name)) {
$query->categoryName($name);
}
if (!is_null($start) && !is_null($limit)) {
$query->offset($start)->limit($limit);
}
return $query->get()->toArray();
}
/**
* Get category Id
*
* @param string $categoryUid
*
* @return int
*/
public static function getCategoryId($categoryUid)
{
$query = ProcessCategory::query()->select(['CATEGORY_ID']);
$query->where('CATEGORY_UID', $categoryUid);
if ($query->first()) {
return $query->first()->CATEGORY_ID;
}
}
}

View File

@@ -95,7 +95,7 @@ class User extends Model
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeUserId($query, string $usrId)
public function scopeUserId($query, int $usrId)
{
return $query->where('USR_ID', '=', $usrId);
}
@@ -255,9 +255,10 @@ class User extends Model
*
* @return array
*/
public static function getInformation($usrId)
public static function getInformation(int $usrId)
{
$query = User::query()->select([
'USR_ID',
'USR_USERNAME',
'USR_FIRSTNAME',
'USR_LASTNAME',
@@ -269,6 +270,7 @@ class User extends Model
$results = $query->get();
$info = [];
$results->each(function ($item) use (&$info) {
$info['usr_id'] = $item->USR_ID;
$info['usr_username'] = $item->USR_USERNAME;
$info['usr_firstname'] = $item->USR_FIRSTNAME;
$info['usr_lastname'] = $item->USR_LASTNAME;

View File

@@ -0,0 +1,96 @@
<?php
namespace ProcessMaker\Model;
use Illuminate\Database\Eloquent\Model;
use stdClass;
class UserConfig extends Model
{
/**
* Bind table.
* @var string
*/
protected $table = 'USER_CONFIG';
/**
* Column timestamps.
* @var boolean
*/
public $timestamps = false;
/**
* Get user setting.
* @param int $id
* @param string $name
* @return mix array|null
*/
public static function getSetting(int $id, string $name)
{
$userConfig = UserConfig::where('USR_ID', '=', $id)
->where('USC_NAME', '=', $name)
->get()
->first();
if (empty($userConfig)) {
return null;
}
$setting = json_decode($userConfig->USC_SETTING);
if (empty($setting)) {
$setting = new stdClass();
}
return [
"id" => $userConfig->USR_ID,
"name" => $userConfig->USC_NAME,
"setting" => $setting
];
}
/**
* Add user setting.
* @param int $id
* @param string $name
* @param array $setting
* @return mix array|null
*/
public static function addSetting(int $id, string $name, array $setting)
{
$model = new UserConfig();
$model->USR_ID = $id;
$model->USC_NAME = $name;
$model->USC_SETTING = json_encode($setting);
$model->save();
$userConfig = UserConfig::getSetting($id, $name);
return $userConfig;
}
/**
* Edit user setting.
* @param int $id
* @param string $name
* @param array $setting
* @return mix array|null
*/
public static function editSetting(int $id, string $name, array $setting)
{
UserConfig::where('USR_ID', '=', $id)
->where('USC_NAME', '=', $name)
->update(["USC_SETTING" => json_encode($setting)]);
return UserConfig::getSetting($id, $name);
}
/**
* Delete user setting.
* @param int $id
* @param string $name
* @return mix array|null
*/
public static function deleteSetting(int $id, string $name)
{
$userConfig = UserConfig::getSetting($id, $name);
UserConfig::where('USR_ID', '=', $id)
->where('USC_NAME', '=', $name)
->delete();
return $userConfig;
}
}