PMCORE-1884
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace ProcessMaker\Model;
|
||||
|
||||
use DateTime;
|
||||
use G;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
@@ -687,4 +688,53 @@ class Delegation extends Model
|
||||
|
||||
return ($query->count() > 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the thread related to the specific task-index
|
||||
*
|
||||
* @param string $appUid
|
||||
* @param string $delIndex
|
||||
* @param string $tasUid
|
||||
* @param string $taskType
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getDatesFromThread(string $appUid, string $delIndex, string $tasUid, string $taskType)
|
||||
{
|
||||
$query = Delegation::query()->select([
|
||||
'DEL_INIT_DATE',
|
||||
'DEL_DELEGATE_DATE',
|
||||
'DEL_FINISH_DATE',
|
||||
'DEL_RISK_DATE',
|
||||
'DEL_TASK_DUE_DATE'
|
||||
]);
|
||||
$query->where('APP_UID', $appUid);
|
||||
$query->where('DEL_INDEX', $delIndex);
|
||||
$query->where('TAS_UID', $tasUid);
|
||||
$results = $query->get();
|
||||
|
||||
$thread = [];
|
||||
$results->each(function ($item, $key) use (&$thread, $taskType) {
|
||||
$thread = $item->toArray();
|
||||
if (in_array($taskType, Task::$typesRunAutomatically)) {
|
||||
$startDate = $thread['DEL_DELEGATE_DATE'];
|
||||
} else {
|
||||
$startDate = $thread['DEL_INIT_DATE'];
|
||||
}
|
||||
$endDate = $thread['DEL_FINISH_DATE'];
|
||||
// Calculate the task-thread duration
|
||||
if (!empty($startDate) && !empty($endDate)) {
|
||||
$initDate = new DateTime($startDate);
|
||||
$finishDate = new DateTime($endDate);
|
||||
$diff = $initDate->diff($finishDate);
|
||||
$format = ' %a ' . G::LoadTranslation('ID_DAY_DAYS');
|
||||
$format .= ' %H '. G::LoadTranslation('ID_HOUR_ABBREVIATE');
|
||||
$format .= ' %I '. G::LoadTranslation('ID_MINUTE_ABBREVIATE');
|
||||
$format .= ' %S '. G::LoadTranslation('ID_SECOND_ABBREVIATE');
|
||||
$thread['DEL_THREAD_DURATION'] = $diff->format($format);
|
||||
}
|
||||
});
|
||||
|
||||
return $thread;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,17 @@ class Task extends Model
|
||||
protected $primaryKey = 'TAS_ID';
|
||||
// We do not have create/update timestamps for this table
|
||||
public $timestamps = false;
|
||||
// The following types will execute without user and run automatically
|
||||
public static $typesRunAutomatically = [
|
||||
"WEBENTRYEVENT",
|
||||
"END-MESSAGE-EVENT",
|
||||
"START-MESSAGE-EVENT",
|
||||
"INTERMEDIATE-THROW-MESSAGE-EVENT",
|
||||
"INTERMEDIATE-CATCH-MESSAGE-EVENT",
|
||||
"SCRIPT-TASK",
|
||||
"START-TIMER-EVENT",
|
||||
"INTERMEDIATE-CATCH-TIMER-EVENT"
|
||||
];
|
||||
|
||||
public function process()
|
||||
{
|
||||
@@ -67,4 +78,45 @@ class Task extends Model
|
||||
|
||||
return $title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get task data
|
||||
*
|
||||
* @param string $tasUid
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function load($tasUid)
|
||||
{
|
||||
$query = Task::query();
|
||||
$query->where('TAS_UID', $tasUid);
|
||||
|
||||
return $query->get()->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get task thread information
|
||||
*
|
||||
* @param string $appUid
|
||||
* @param string $tasUid
|
||||
* @param string $delIndex
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function information(string $appUid, string $tasUid, string $delIndex)
|
||||
{
|
||||
// Load the the task information
|
||||
$taskInfo = $this->load($tasUid);
|
||||
$taskInfo = head($taskInfo);
|
||||
$taskType = $taskInfo['TAS_TYPE'];
|
||||
// Load the dates related to the thread
|
||||
$dates = Delegation::getDatesFromThread($appUid, $delIndex, $tasUid, $taskType);
|
||||
// Set the dates
|
||||
$taskInfo['INIT_DATE'] = !empty($dates['DEL_INIT_DATE']) ? $dates['DEL_INIT_DATE'] : G::LoadTranslation('ID_CASE_NOT_YET_STARTED');
|
||||
$taskInfo['DUE_DATE'] = !empty($dates['DEL_TASK_DUE_DATE']) ? $dates['DEL_TASK_DUE_DATE'] : G::LoadTranslation('ID_NOT_FINISHED');
|
||||
$taskInfo['FINISH'] = !empty($dates['DEL_FINISH_DATE']) ? $dates['DEL_FINISH_DATE'] : G::LoadTranslation('ID_NOT_FINISHED');
|
||||
$taskInfo['DURATION'] = !empty($dates['DEL_THREAD_DURATION']) ? $dates['DEL_THREAD_DURATION'] : G::LoadTranslation('ID_NOT_FINISHED');
|
||||
|
||||
return $taskInfo;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user