PMCORE-2524: Conflicts with develop

This commit is contained in:
Paula Quispe
2020-12-09 12:26:20 -04:00
26 changed files with 969 additions and 547 deletions

View File

@@ -7,6 +7,7 @@ use G;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
use ProcessMaker\Core\System;
use ProcessMaker\Model\Task;
class Delegation extends Model
{
@@ -1026,7 +1027,7 @@ class Delegation extends Model
'APPLICATION.APP_CREATE_DATE',
'APPLICATION.APP_FINISH_DATE',
'APPLICATION.APP_UPDATE_DATE',
'APPLICATION.APP_TITLE',
'APP_DELEGATION.DEL_TITLE AS APP_TITLE',
'APP_DELEGATION.USR_UID',
'APP_DELEGATION.TAS_UID',
'APP_DELEGATION.USR_ID',
@@ -1082,12 +1083,11 @@ class Delegation extends Model
// Build the "fulltext" expression
$search = '+"' . preg_replace('/\s+/', '" +"', addslashes($search)) . '"';
// Searching using "fulltext" index
$join->whereRaw("MATCH(APPLICATION.APP_TITLE) AGAINST('{$search}' IN BOOLEAN MODE)");
$join->whereRaw("MATCH(APP_DELEGATION.DEL_TITLE) AGAINST('{$search}' IN BOOLEAN MODE)");
} else {
// Searching using "like" operator
$join->where('APPLICATION.APP_TITLE', 'LIKE', "%${search}%");
$join->where('APP_DELEGATION.DEL_TITLE', 'LIKE', "%${search}%");
}
}
// Based on the below, we can further limit the join so that we have a smaller data set based on join criteria
@@ -1111,7 +1111,6 @@ class Delegation extends Model
// Don't do anything here, we'll need to do the more advanced where below
}
});
// Add join for process, but only for certain scenarios such as category or process
if ($category || $process || $sort == 'APP_PRO_TITLE') {
$query->join('PROCESS', function ($join) use ($category) {
@@ -1412,7 +1411,7 @@ class Delegation extends Model
});
// Add join clause with APPLICATION table if required
if (array_search('APPLICATION.APP_TITLE', $selectedColumns) !== false || !empty($textToSearch) || $sort == 'APP_TITLE') {
if (array_search('APP_DELEGATION.DEL_TITLE AS APP_TITLE', $selectedColumns) !== false || array_search('APPLICATION.APP_TITLE', $selectedColumns) !== false || !empty($textToSearch) || $sort == 'APP_TITLE') {
$query1->join('APPLICATION', function ($join) {
$join->on('APP_DELEGATION.APP_NUMBER', '=', 'APPLICATION.APP_NUMBER');
});
@@ -1433,7 +1432,7 @@ class Delegation extends Model
// Build where clause for the text to search
if (!empty($textToSearch)) {
$query1->where('APPLICATION.APP_TITLE', 'LIKE', "%$textToSearch%")
$query1->where('APP_DELEGATION.DEL_TITLE', 'LIKE', "%$textToSearch%")
->orWhere('TASK.TAS_TITLE', 'LIKE', "%$textToSearch%")
->orWhere('PROCESS.PRO_TITLE', 'LIKE', "%$textToSearch%");
}
@@ -1467,7 +1466,7 @@ class Delegation extends Model
});
}
// Add join clause with APPLICATION table if required
if (array_search('APPLICATION.APP_TITLE', $selectedColumns) !== false || !empty($textToSearch) || $sort == 'APP_TITLE') {
if (array_search('APP_DELEGATION.DEL_TITLE AS APP_TITLE', $selectedColumns) !== false || !empty($textToSearch) || $sort == 'APP_TITLE') {
$query2->join('APPLICATION', function ($join) {
$join->on('APP_DELEGATION.APP_NUMBER', '=', 'APPLICATION.APP_NUMBER');
});
@@ -1488,7 +1487,7 @@ class Delegation extends Model
// Build where clause for the text to search
if (!empty($textToSearch)) {
$query2->where('APPLICATION.APP_TITLE', 'LIKE', "%$textToSearch%")
$query2->where('APP_DELEGATION.DEL_TITLE', 'LIKE', "%$textToSearch%")
->orWhere('TASK.TAS_TITLE', 'LIKE', "%$textToSearch%")
->orWhere('PROCESS.PRO_TITLE', 'LIKE', "%$textToSearch%");
}
@@ -1671,6 +1670,25 @@ class Delegation extends Model
return ($query->count() > 0);
}
/**
* Return the task related to the thread
*
* @param int $appNumber
* @param int $index
*
* @return array
*/
public static function getThreadInfo(int $appNumber, int $index)
{
$query = Delegation::query()->select(['APP_NUMBER', 'TAS_UID', 'TAS_ID', 'DEL_PREVIOUS', 'DEL_TITLE']);
$query->where('APP_NUMBER', $appNumber);
$query->where('DEL_INDEX', $index);
$query->limit(1);
$result = $query->get()->toArray();
return head($result);
}
/**
* Return the thread related to the specific task-index
*
@@ -1720,7 +1738,6 @@ class Delegation extends Model
return $thread;
}
/**
* Return the open thread related to the task
*
@@ -1746,4 +1763,49 @@ class Delegation extends Model
return $results;
}
/**
* Get the thread title related to the delegation
*
* @param string $tasUid
* @param int $appNumber
* @param int $delIndexPrevious
* @param array $caseData
*
* @return string
*/
public static function getThreadTitle(string $tasUid, int $appNumber, int $delIndexPrevious, $caseData = [])
{
// Get task title defined
$task = new Task();
$taskTitle = $task->taskCaseTitle($tasUid);
// If exist we will to replace the variables data
if (!empty($taskTitle)) {
$threadTitle = G::replaceDataField($taskTitle, $caseData, 'mysql', false);
} else {
// If is empty get the previous title
if ($delIndexPrevious > 0) {
$thread = self::getThreadInfo($appNumber, $delIndexPrevious);
$threadTitle = $thread['DEL_TITLE'];
} else {
$threadTitle = '# '. $appNumber;
}
}
return $threadTitle;
}
/**
* Get the DEL_TITLE related to DELEGATION table
*
* @param int $appNumber
* @param int $delIndex
* @return string
*/
public static function getDeltitle($appNumber, $delIndex)
{
$query = Delegation::select(['DEL_TITLE'])->where('APP_NUMBER', $appNumber)->where('DEL_INDEX', $delIndex);
$res = $query->first();
return $res->DEL_TITLE;
}
}