Fix conflicts with develop branch

This commit is contained in:
Julio Cesar Laura Avendaño
2020-01-17 11:27:11 -04:00
400 changed files with 7056 additions and 86309 deletions

View File

@@ -0,0 +1,105 @@
<?php
namespace ProcessMaker\Model;
use AdditionalTables as ModelAdditionalTables;
use Illuminate\Database\Eloquent\Model;
class AdditionalTables extends Model
{
protected $table = 'ADDITIONAL_TABLES';
public $timestamps = false;
/**
* Get the fields related to the table belongs to
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function columns()
{
return $this->belongsTo(Fields::class, 'ADD_TAB_UID', 'ADD_TAB_UID');
}
/**
* Scope a query to get the offline tables
*
* @param \Illuminate\Database\Eloquent\Builder $query
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeOffline($query)
{
return $query->where('ADD_TAB_OFFLINE', '=', 1);
}
/**
* Get the structure of offline tables
*
* @return array
*/
public static function getTablesOfflineStructure()
{
$query = AdditionalTables::query()->select([
'ADD_TAB_UID',
'ADD_TAB_NAME',
'ADD_TAB_DESCRIPTION',
'ADD_TAB_CLASS_NAME'
]);
$query->offline();
$results = $query->get();
$data = [];
$results->each(function ($item, $key) use (&$data) {
$data[$key] = array_change_key_case($item->toArray(), CASE_LOWER);
$data[$key]['fields'] = Fields::getFields($item->ADD_TAB_UID);
});
return $data;
}
/**
* Get the data of offline tables
*
* @return array
*/
public static function getTablesOfflineData()
{
$query = AdditionalTables::query()->select([
'ADD_TAB_UID',
'ADD_TAB_NAME',
'ADD_TAB_DESCRIPTION',
'ADD_TAB_CLASS_NAME'
]);
$query->offline();
$results = $query->get();
$data = [];
$results->each(function ($item, $key) use (&$data) {
$data[$key] = array_change_key_case($item->toArray(), CASE_LOWER);
$additionalTables = new ModelAdditionalTables();
$result = $additionalTables->getAllData($item->ADD_TAB_UID);
if (empty($result['rows'])) {
$data[$key]['rows'] = [];
} else {
foreach ($result['rows'] as $i => $row) {
$data[$key]['rows'][$i] = $row;
}
}
});
return $data;
}
/**
* Update the offline property.
* @param array $tablesUid
* @param int $value
* @return void
*/
public static function updatePropertyOffline(array $tablesUid, $value): void
{
$query = AdditionalTables::whereIn('ADD_TAB_UID', $tablesUid)
->update(['ADD_TAB_OFFLINE' => $value]);
}
}

View File

@@ -27,24 +27,23 @@ class Application extends Model
}
/**
* Get Applications by PRO_UID, ordered by APP_NUMBER.
* @param string $proUid
* @return object
* @see ReportTables->populateTable()
* Scope for query to get the application by APP_UID.
* @param \Illuminate\Database\Eloquent\Builder $query
* @param string $appUid
* @return \Illuminate\Database\Eloquent\Builder
*/
public static function getByProUid($proUid)
public function scopeAppUid($query, $appUid)
{
$query = Application::query()
->select()
->proUid($proUid)
->orderBy('APP_NUMBER', 'ASC');
return $query->get();
$result = $query->where('APP_UID', '=', $appUid);
return $result;
}
/**
* Scope for query to get the applications by PRO_UID.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param string $proUid
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeProUid($query, $proUid)
@@ -52,4 +51,38 @@ class Application extends Model
$result = $query->where('PRO_UID', '=', $proUid);
return $result;
}
/**
* Get Applications by PRO_UID, ordered by APP_NUMBER.
*
* @param string $proUid
*
* @return object
* @see ReportTables->populateTable()
*/
public static function getByProUid($proUid)
{
$query = Application::query()
->select()
->proUid($proUid)
->orderBy('APP_NUMBER', 'ASC');
return $query->get();
}
/**
* Get information related to the created case
*
* @param string $appUid
*
* @return array|bool
*/
public static function getCase($appUid)
{
$query = Application::query()->select(['APP_STATUS', 'APP_INIT_USER']);
$query->appUid($appUid);
$result = $query->get()->toArray();
$firstElement = head($result);
return $firstElement;
}
}

View File

@@ -13,6 +13,10 @@ class Delegation extends Model
// We don't have our standard timestamp columns
public $timestamps = false;
// Static properties to preserve values
public static $usrUid = '';
public static $groups = [];
/**
* Returns the application this delegation belongs to
*/
@@ -478,39 +482,81 @@ class Delegation extends Model
*/
public static function countSelfService($usrUid)
{
//Get the task self services related to the user
$taskSelfService = TaskUser::getSelfServicePerUser($usrUid);
//Get the task self services value based related to the user
$selfServiceValueBased = AppAssignSelfServiceValue::getSelfServiceCasesByEvaluatePerUser($usrUid);
// Set the 'usrUid' property to preserve
Delegation::$usrUid = $usrUid;
//Start the query for get the cases related to the user
$query = Delegation::query()->select('APP_NUMBER');
//Add Join with task filtering only the type self-service
$query->join('TASK', function ($join) {
$join->on('APP_DELEGATION.TAS_ID', '=', 'TASK.TAS_ID')
->where('TASK.TAS_ASSIGN_TYPE', '=', 'SELF_SERVICE');
// Get and build the groups parameter related to the user
$groups = GroupUser::getGroups($usrUid);
$groups = array_map(function ($value) {
return "'" . $value['GRP_ID'] . "'";
}, $groups);
// Add dummy value to avoid syntax error in complex join
$groups[] = "'-1'";
// Set the 'groups' property to preserve
Delegation::$groups = $groups;
// Start the first query
$query1 = Delegation::query()->select('APP_NUMBER');
// Add the join clause
$query1->join('TASK', function ($join) {
// Build partial plain query for a complex Join, because Eloquent doesn't support this type of Join
$complexJoin = "
((`APP_DELEGATION`.`APP_NUMBER`, `APP_DELEGATION`.`DEL_INDEX`, `APP_DELEGATION`.`TAS_ID`) IN (
SELECT
`APP_ASSIGN_SELF_SERVICE_VALUE`.`APP_NUMBER`,
`APP_ASSIGN_SELF_SERVICE_VALUE`.`DEL_INDEX`,
`APP_ASSIGN_SELF_SERVICE_VALUE`.`TAS_ID`
FROM
`APP_ASSIGN_SELF_SERVICE_VALUE`
INNER JOIN `APP_ASSIGN_SELF_SERVICE_VALUE_GROUP` ON
`APP_ASSIGN_SELF_SERVICE_VALUE`.`ID` = `APP_ASSIGN_SELF_SERVICE_VALUE_GROUP`.`ID`
WHERE (
`APP_ASSIGN_SELF_SERVICE_VALUE_GROUP`.`GRP_UID` = '%s' OR (
`APP_ASSIGN_SELF_SERVICE_VALUE_GROUP`.`ASSIGNEE_ID` IN (%s) AND
`APP_ASSIGN_SELF_SERVICE_VALUE_GROUP`.`ASSIGNEE_TYPE` = '2')
)
))";
$groups = implode(',', Delegation::$groups);
$complexJoin = sprintf($complexJoin, Delegation::$usrUid, $groups);
// Add joins
$join->on('APP_DELEGATION.TAS_ID', '=', 'TASK.TAS_ID');
$join->on('TASK.TAS_ASSIGN_TYPE', '=', DB::raw("'SELF_SERVICE'"));
$join->on('APP_DELEGATION.DEL_THREAD_STATUS', '=', DB::raw("'OPEN'"));
$join->on('APP_DELEGATION.USR_ID', '=', DB::raw("'0'"))->
whereRaw($complexJoin);
});
//Filtering the open threads and without users
$query->isThreadOpen()->noUserInThread();
//Get the cases unassigned
if (!empty($selfServiceValueBased)) {
$query->where(function ($query) use ($selfServiceValueBased, $taskSelfService) {
//Get the cases related to the task self service
$query->tasksIn($taskSelfService);
foreach ($selfServiceValueBased as $case) {
//Get the cases related to the task self service value based
$query->orWhere(function ($query) use ($case) {
$query->case($case['APP_NUMBER'])->index($case['DEL_INDEX'])->task($case['TAS_ID']);
});
}
});
// Get self services tasks related to the user
$selfServiceTasks = TaskUser::getSelfServicePerUser($usrUid);
if (!empty($selfServiceTasks)) {
// Start the first query
$query2 = Delegation::query()->select('APP_NUMBER');
$query2->tasksIn($selfServiceTasks);
$query2->noUserInThread();
// Build the complex query that uses "UNION DISTINCT" clause
$unionQuery = sprintf('select count(*) as aggregate from ((%s) union distinct (%s)) self_service_cases',
toSqlWithBindings($query1), toSqlWithBindings($query2));
// Execute the query
$result = DB::selectOne($unionQuery);
$count = $result->aggregate;
} else {
//Get the cases related to the task self service
$query->tasksIn($taskSelfService);
// Execute the query
$count = $query1->count();
}
return $query->count();
// Clean static properties
Delegation::$usrUid = '';
Delegation::$groups = [];
// Return value
return $count;
}
/**

View File

@@ -0,0 +1,55 @@
<?php
namespace ProcessMaker\Model;
use Illuminate\Database\Eloquent\Model;
class Fields extends Model
{
protected $table = 'FIELDS';
public $timestamps = false;
/**
* Get the fields related to the table belongs to
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function table()
{
return $this->belongsTo(AdditionalTables::class, 'ADD_TAB_UID', 'ADD_TAB_UID');
}
/**
* Scope a query to get the offline tables
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param string $tabUid
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeTable($query, $tabUid)
{
return $query->where('ADD_TAB_UID', '=', $tabUid);
}
/**
* Get the offline tables
*
* @param string $tabUid
*
* @return array
*/
public static function getFields($tabUid)
{
$query = Fields::query();
$query->table($tabUid);
$results = $query->get();
$data = [];
$results->each(function ($item, $key) use (&$data) {
$data[$key] = array_change_key_case($item->toArray(), CASE_LOWER);
});
return $data;
}
}