2010-12-02 23:34:41 +00:00
< ? php
2012-10-09 12:40:24 -04:00
2020-08-10 17:11:55 -04:00
use Illuminate\Support\Facades\Log ;
2020-02-17 14:09:54 -04:00
use ProcessMaker\Model\Application as ModelApplication ;
2021-07-28 17:36:12 -04:00
use ProcessMaker\Model\Delegation ;
2020-04-30 16:08:24 -04:00
use ProcessMaker\Model\SubApplication as ModelSubApplication ;
2020-02-17 14:09:54 -04:00
2017-08-11 12:08:19 -04:00
class Derivation
2010-12-02 23:34:41 +00:00
{
2012-10-09 12:40:24 -04:00
var $case ;
2020-02-17 14:09:54 -04:00
protected $appCurrentUser ;
protected $arraySiblings ;
protected $aSP ;
protected $context ;
2016-04-14 15:51:36 -04:00
protected $flagControl ;
2016-04-15 16:46:47 -04:00
protected $flagControlMulInstance ;
2020-02-17 14:09:54 -04:00
protected $flagUpdateList ;
protected $iNewDelIndex ;
2017-03-23 09:26:12 -04:00
protected $regexpTaskTypeToInclude ;
2020-02-17 14:09:54 -04:00
protected $removeList ;
protected $sys ;
2016-08-12 07:41:52 -04:00
public $node ;
2016-11-21 16:36:30 -04:00
public $userLogged = null ;
2016-08-01 16:42:58 -04:00
public function __construct ()
{
2016-11-21 16:36:30 -04:00
$this -> userLogged = new Users ();
2017-03-08 11:39:32 -04:00
$this -> setRegexpTaskTypeToInclude ( " GATEWAYTOGATEWAY|END-MESSAGE-EVENT|END-EMAIL-EVENT " );
2016-08-01 16:42:58 -04:00
}
/**
* @ return mixed
*/
public function getRegexpTaskTypeToInclude ()
{
return $this -> regexpTaskTypeToInclude ;
}
/**
* @ param mixed $regexpTaskTypeToInclude
*/
public function setRegexpTaskTypeToInclude ( $regexpTaskTypeToInclude )
{
$this -> regexpTaskTypeToInclude = $regexpTaskTypeToInclude ;
}
2012-10-09 12:40:24 -04:00
2014-11-26 10:19:07 -04:00
/**
2014-12-04 11:40:52 -04:00
* prepareInformationTask
2014-11-26 10:19:07 -04:00
*
2014-12-04 11:40:52 -04:00
* @ param array $arrayTaskData Task data ( derivation )
2014-11-26 10:19:07 -04:00
*
2015-10-19 14:01:31 -04:00
* @ return array Return array
2017-08-07 10:58:08 -04:00
* @ throws Exception
2014-11-26 10:19:07 -04:00
*/
2017-03-23 09:26:12 -04:00
protected function prepareInformationTask ( array $arrayTaskData )
2014-11-26 10:19:07 -04:00
{
try {
$task = new Task ();
2014-12-04 11:40:52 -04:00
$arrayTaskData = G :: array_merges ( $arrayTaskData , $task -> load ( $arrayTaskData [ " TAS_UID " ]));
2014-11-26 10:19:07 -04:00
2014-12-04 11:40:52 -04:00
//2. If next case is an special case
if (( int )( $arrayTaskData [ " ROU_NEXT_TASK " ]) < 0 ) {
$arrayTaskData [ " NEXT_TASK " ][ " TAS_UID " ] = ( int )( $arrayTaskData [ " ROU_NEXT_TASK " ]);
$arrayTaskData [ " NEXT_TASK " ][ " TAS_ASSIGN_TYPE " ] = " nobody " ;
$arrayTaskData [ " NEXT_TASK " ][ " TAS_PRIORITY_VARIABLE " ] = " " ;
$arrayTaskData [ " NEXT_TASK " ][ " TAS_DEF_PROC_CODE " ] = " " ;
$arrayTaskData [ " NEXT_TASK " ][ " TAS_PARENT " ] = " " ;
$arrayTaskData [ " NEXT_TASK " ][ " TAS_TRANSFER_FLY " ] = " " ;
2014-11-26 10:19:07 -04:00
2014-12-04 11:40:52 -04:00
switch ( $arrayTaskData [ " ROU_NEXT_TASK " ]) {
2014-11-26 10:19:07 -04:00
case - 1 :
2014-12-04 11:40:52 -04:00
$arrayTaskData [ " NEXT_TASK " ][ " TAS_TITLE " ] = G :: LoadTranslation ( " ID_END_OF_PROCESS " );
2014-11-26 10:19:07 -04:00
break ;
case - 2 :
2014-12-04 11:40:52 -04:00
$arrayTaskData [ " NEXT_TASK " ][ " TAS_TITLE " ] = G :: LoadTranslation ( " ID_TAREA_COLGANTE " );
2014-11-26 10:19:07 -04:00
break ;
}
2014-12-04 11:40:52 -04:00
$arrayTaskData [ " NEXT_TASK " ][ " USR_UID " ] = " " ;
2014-12-18 15:40:43 -04:00
$arrayTaskData [ " NEXT_TASK " ][ " USER_ASSIGNED " ] = array ( " USR_UID " => " " , " USR_USERNAME " => " " );
2014-11-26 10:19:07 -04:00
} else {
2014-12-04 11:40:52 -04:00
//3. Load the task information of normal NEXT_TASK
$arrayTaskData [ " NEXT_TASK " ] = $task -> load ( $arrayTaskData [ " ROU_NEXT_TASK " ]); //print $arrayTaskData["ROU_NEXT_TASK"]." **** ".$arrayTaskData["NEXT_TASK"]["TAS_TYPE"]."<hr>";
2014-11-26 10:19:07 -04:00
2014-12-04 11:40:52 -04:00
if ( $arrayTaskData [ " NEXT_TASK " ][ " TAS_TYPE " ] == " SUBPROCESS " ) {
$taskParent = $arrayTaskData [ " NEXT_TASK " ][ " TAS_UID " ];
2014-11-26 10:19:07 -04:00
$criteria = new Criteria ( " workflow " );
2014-12-04 11:40:52 -04:00
$criteria -> add ( SubProcessPeer :: PRO_PARENT , $arrayTaskData [ " PRO_UID " ]);
$criteria -> add ( SubProcessPeer :: TAS_PARENT , $arrayTaskData [ " NEXT_TASK " ][ " TAS_UID " ]);
2014-11-26 10:19:07 -04:00
$rsCriteria = SubProcessPeer :: doSelectRS ( $criteria );
$rsCriteria -> setFetchmode ( ResultSet :: FETCHMODE_ASSOC );
$rsCriteria -> next ();
$row = $rsCriteria -> getRow ();
2014-12-04 11:40:52 -04:00
$arrayTaskData [ " ROU_NEXT_TASK " ] = $row [ " TAS_UID " ]; //print "<hr>Life is just a lonely highway";
$arrayTaskData [ " NEXT_TASK " ] = $task -> load ( $arrayTaskData [ " ROU_NEXT_TASK " ]); //print "<hr>Life is just a lonely highway";print"<hr>";
2014-11-26 10:19:07 -04:00
$process = new Process ();
$row = $process -> load ( $row [ " PRO_UID " ]);
2014-12-04 11:40:52 -04:00
$arrayTaskData [ " NEXT_TASK " ][ " TAS_TITLE " ] .= " ( " . $row [ " PRO_TITLE " ] . " ) " ;
$arrayTaskData [ " NEXT_TASK " ][ " TAS_PARENT " ] = $taskParent ;
2014-11-26 10:19:07 -04:00
2014-12-04 11:40:52 -04:00
//unset($task, $process, $row, $taskParent);
2014-11-26 10:19:07 -04:00
} else {
2014-12-04 11:40:52 -04:00
$arrayTaskData [ " NEXT_TASK " ][ " TAS_PARENT " ] = " " ;
2014-11-26 10:19:07 -04:00
}
2016-11-25 13:06:25 -05:00
$regexpTaskTypeToExclude = " GATEWAYTOGATEWAY|END-MESSAGE-EVENT|SCRIPT-TASK|SERVICE-TASK|INTERMEDIATE-CATCH-TIMER-EVENT|INTERMEDIATE-THROW-MESSAGE-EVENT|END-EMAIL-EVENT|INTERMEDIATE-THROW-EMAIL-EVENT|INTERMEDIATE-CATCH-MESSAGE-EVENT " ;
2015-09-11 09:27:16 -04:00
$arrayTaskData [ " NEXT_TASK " ][ " USER_ASSIGNED " ] = ( ! preg_match ( " /^(?: " . $regexpTaskTypeToExclude . " ) $ / " , $arrayTaskData [ " NEXT_TASK " ][ " TAS_TYPE " ])) ? $this -> getNextAssignedUser ( $arrayTaskData ) : array ( " USR_UID " => " " , " USR_FULLNAME " => " " );
2014-11-26 10:19:07 -04:00
}
//Return
2014-12-04 11:40:52 -04:00
return $arrayTaskData ;
2014-11-26 10:19:07 -04:00
} catch ( Exception $e ) {
throw $e ;
}
}
2017-03-23 09:28:09 -04:00
/**
2012-10-09 12:40:24 -04:00
* prepareInformation
*
2014-12-04 11:40:52 -04:00
* @ param array $arrayData Data
* @ param string $taskUid Unique id of Task
*
2017-08-07 10:58:08 -04:00
* @ return array
* @ throws Exception
2012-10-09 12:40:24 -04:00
*/
2014-12-04 11:40:52 -04:00
public function prepareInformation ( array $arrayData , $taskUid = " " )
2012-10-09 12:40:24 -04:00
{
2014-12-04 11:40:52 -04:00
try {
$this -> case = new Cases ();
$task = new Task ();
2014-11-26 10:19:07 -04:00
2015-09-09 10:46:31 -04:00
$arrayApplicationData = $this -> case -> loadCase ( $arrayData [ " APP_UID " ]);
2020-08-10 17:11:55 -04:00
$arrayNextTask = [];
$arrayNextTaskDefault = [];
2015-02-19 09:39:15 -04:00
$i = 0 ;
2014-12-04 11:40:52 -04:00
$criteria = new Criteria ( " workflow " );
2012-10-09 12:40:24 -04:00
2014-12-04 11:40:52 -04:00
$criteria -> addSelectColumn ( RoutePeer :: TAS_UID );
$criteria -> addSelectColumn ( RoutePeer :: ROU_NEXT_TASK );
$criteria -> addSelectColumn ( RoutePeer :: ROU_TYPE );
$criteria -> addSelectColumn ( RoutePeer :: ROU_DEFAULT );
$criteria -> addSelectColumn ( RoutePeer :: ROU_CONDITION );
if ( $taskUid != " " ) {
$criteria -> add ( RoutePeer :: TAS_UID , $taskUid , Criteria :: EQUAL );
$criteria -> addAscendingOrderByColumn ( RoutePeer :: ROU_CASE );
$rsCriteria = RoutePeer :: doSelectRS ( $criteria );
} else {
$criteria -> addJoin ( AppDelegationPeer :: TAS_UID , TaskPeer :: TAS_UID , Criteria :: LEFT_JOIN );
$criteria -> addJoin ( AppDelegationPeer :: TAS_UID , RoutePeer :: TAS_UID , Criteria :: LEFT_JOIN );
$criteria -> add ( AppDelegationPeer :: APP_UID , $arrayData [ " APP_UID " ], Criteria :: EQUAL );
$criteria -> add ( AppDelegationPeer :: DEL_INDEX , $arrayData [ " DEL_INDEX " ], Criteria :: EQUAL );
$criteria -> addAscendingOrderByColumn ( RoutePeer :: ROU_CASE );
$rsCriteria = AppDelegationPeer :: doSelectRS ( $criteria );
2012-10-09 12:40:24 -04:00
}
2010-12-02 23:34:41 +00:00
2014-12-04 11:40:52 -04:00
$rsCriteria -> setFetchmode ( ResultSet :: FETCHMODE_ASSOC );
2015-09-09 10:46:31 -04:00
2015-02-23 11:09:57 -04:00
$flagDefault = false ;
2020-08-10 17:11:55 -04:00
$aSecJoin = [];
2015-11-13 15:05:26 -04:00
$count = 0 ;
2015-09-09 10:46:31 -04:00
2014-12-04 11:40:52 -04:00
while ( $rsCriteria -> next ()) {
$arrayRouteData = G :: array_merges ( $rsCriteria -> getRow (), $arrayData );
if (( int )( $arrayRouteData [ " ROU_DEFAULT " ]) == 1 ) {
$arrayNextTaskDefault = $arrayRouteData ;
2015-02-23 11:09:57 -04:00
$flagDefault = true ;
continue ;
2012-10-09 12:40:24 -04:00
}
2010-12-02 23:34:41 +00:00
2015-09-09 10:46:31 -04:00
$flagAddDelegation = true ;
2014-12-04 11:40:52 -04:00
//Evaluate the condition if there are conditions defined
2015-09-09 10:46:31 -04:00
if ( trim ( $arrayRouteData [ " ROU_CONDITION " ]) != " " && $arrayRouteData [ " ROU_TYPE " ] != " SELECT " ) {
2014-12-04 11:40:52 -04:00
$pmScript = new PMScript ();
$pmScript -> setFields ( $arrayApplicationData [ " APP_DATA " ]);
2015-02-20 13:10:58 -04:00
$pmScript -> setScript ( $arrayRouteData [ " ROU_CONDITION " ]);
2018-10-30 13:41:00 -04:00
$pmScript -> setExecutedOn ( PMScript :: CONDITION );
2015-09-09 10:46:31 -04:00
$flagAddDelegation = $pmScript -> evaluate ();
2014-12-04 11:40:52 -04:00
}
2016-07-26 15:34:52 -04:00
if ( trim ( $arrayRouteData [ 'ROU_CONDITION' ]) == '' && $arrayRouteData [ 'ROU_NEXT_TASK' ] != '-1' ) {
$arrayTaskData = $task -> load ( $arrayRouteData [ 'ROU_NEXT_TASK' ]);
2016-06-30 10:15:46 -04:00
2016-07-26 15:34:52 -04:00
if ( $arrayRouteData [ 'ROU_TYPE' ] != 'SEC-JOIN' && $arrayTaskData [ 'TAS_TYPE' ] == 'GATEWAYTOGATEWAY' ) {
2015-11-13 15:05:26 -04:00
$flagAddDelegation = true ;
}
2016-07-26 15:34:52 -04:00
if ( $arrayRouteData [ 'ROU_TYPE' ] == 'SEC-JOIN' ){
$aSecJoin [ $count ][ 'ROU_PREVIOUS_TASK' ] = $arrayRouteData [ 'ROU_NEXT_TASK' ];
$aSecJoin [ $count ][ 'ROU_PREVIOUS_TYPE' ] = 'SEC-JOIN' ;
$count ++ ;
}
2016-06-30 10:15:46 -04:00
}
2015-11-13 15:05:26 -04:00
2016-07-26 15:34:52 -04:00
if ( $arrayRouteData [ 'ROU_TYPE' ] == 'EVALUATE' && ! empty ( $arrayNextTask )) {
$flagAddDelegation = false ;
2014-12-04 11:40:52 -04:00
}
2015-09-09 10:46:31 -04:00
if ( $flagAddDelegation &&
preg_match ( " /^(?:EVALUATE|PARALLEL-BY-EVALUATION) $ / " , $arrayRouteData [ " ROU_TYPE " ]) &&
trim ( $arrayRouteData [ " ROU_CONDITION " ]) == " "
) {
$flagAddDelegation = false ;
}
if ( $flagAddDelegation ) {
2015-02-19 09:39:15 -04:00
$arrayNextTask [ ++ $i ] = $this -> prepareInformationTask ( $arrayRouteData );
2014-12-04 11:40:52 -04:00
}
2012-10-09 12:40:24 -04:00
}
2015-09-09 10:46:31 -04:00
2015-09-11 09:27:16 -04:00
if ( count ( $arrayNextTask ) == 0 && count ( $arrayNextTaskDefault ) > 0 ) {
2015-02-19 09:39:15 -04:00
$arrayNextTask [ ++ $i ] = $this -> prepareInformationTask ( $arrayNextTaskDefault );
2014-12-04 11:40:52 -04:00
}
2014-11-26 10:19:07 -04:00
2015-09-09 10:46:31 -04:00
//Check Task GATEWAYTOGATEWAY, END-MESSAGE-EVENT, END-EMAIL-EVENT
2016-08-11 12:06:34 -04:00
$arrayNextTaskBackup = $arrayNextTask ;
2016-08-12 12:05:55 -04:00
2020-08-10 17:11:55 -04:00
$arrayNextTask = [];
2015-02-19 09:39:15 -04:00
$i = 0 ;
2015-02-21 15:59:12 -04:00
foreach ( $arrayNextTaskBackup as $value ) {
2014-12-04 11:40:52 -04:00
$arrayNextTaskData = $value ;
2016-08-12 07:41:52 -04:00
$this -> node [ $value [ 'TAS_UID' ]][ 'out' ][ $value [ 'ROU_NEXT_TASK' ]] = $value [ 'ROU_TYPE' ];
2015-02-21 15:59:12 -04:00
if ( $arrayNextTaskData [ " NEXT_TASK " ][ " TAS_UID " ] != " -1 " &&
2017-03-14 18:19:37 -04:00
preg_match ( " /^(?: " . $this -> regexpTaskTypeToInclude . " ) $ / " , $arrayNextTaskData [ " NEXT_TASK " ][ " TAS_TYPE " ])
2015-02-21 15:59:12 -04:00
) {
2014-12-04 11:40:52 -04:00
$arrayAux = $this -> prepareInformation ( $arrayData , $arrayNextTaskData [ " NEXT_TASK " ][ " TAS_UID " ]);
2016-08-12 07:41:52 -04:00
$this -> node [ $value [ 'ROU_NEXT_TASK' ]][ 'in' ][ $value [ 'TAS_UID' ]] = $value [ 'ROU_TYPE' ];
2014-12-04 11:40:52 -04:00
foreach ( $arrayAux as $value2 ) {
2016-08-01 16:42:58 -04:00
$key = ++ $i ;
$arrayNextTask [ $key ] = $value2 ;
2016-08-22 17:24:25 -04:00
$prefix = substr ( $value [ 'ROU_NEXT_TASK' ], 0 , 4 );
if ( $prefix !== 'gtg-' ){
$arrayNextTask [ $key ][ 'SOURCE_UID' ] = $value [ 'ROU_NEXT_TASK' ];
}
2015-11-13 15:05:26 -04:00
foreach ( $aSecJoin as $rsj ){
$arrayNextTask [ $i ][ " NEXT_TASK " ][ " ROU_PREVIOUS_TASK " ] = $rsj [ " ROU_PREVIOUS_TASK " ];
$arrayNextTask [ $i ][ " NEXT_TASK " ][ " ROU_PREVIOUS_TYPE " ] = " SEC-JOIN " ;
}
2014-12-04 11:40:52 -04:00
}
} else {
2016-06-09 16:14:50 -04:00
$regexpTaskTypeToInclude = " END-MESSAGE-EVENT|END-EMAIL-EVENT|INTERMEDIATE-THROW-EMAIL-EVENT " ;
2015-09-09 10:46:31 -04:00
if ( $arrayNextTaskData [ " NEXT_TASK " ][ " TAS_UID " ] == " -1 " &&
preg_match ( " /^(?: " . $regexpTaskTypeToInclude . " ) $ / " , $arrayNextTaskData [ " TAS_TYPE " ])
2015-02-21 15:59:12 -04:00
) {
$arrayNextTaskData [ " NEXT_TASK " ][ " TAS_UID " ] = $arrayNextTaskData [ " TAS_UID " ] . " / " . $arrayNextTaskData [ " NEXT_TASK " ][ " TAS_UID " ];
}
2016-08-22 17:24:25 -04:00
$prefix = substr ( $value [ 'ROU_NEXT_TASK' ], 0 , 4 );
if ( $prefix !== 'gtg-' ){
$arrayNextTaskData [ 'SOURCE_UID' ] = $value [ 'ROU_NEXT_TASK' ];
}
2015-02-19 09:39:15 -04:00
$arrayNextTask [ ++ $i ] = $arrayNextTaskData ;
2015-11-13 15:05:26 -04:00
foreach ( $aSecJoin as $rsj ){
$arrayNextTask [ $i ][ " NEXT_TASK " ][ " ROU_PREVIOUS_TASK " ] = $rsj [ " ROU_PREVIOUS_TASK " ];
$arrayNextTask [ $i ][ " NEXT_TASK " ][ " ROU_PREVIOUS_TYPE " ] = " SEC-JOIN " ;
}
2015-11-17 11:46:07 -04:00
//Start-Timer with Script-task
$criteriaE = new Criteria ( " workflow " );
$criteriaE -> addSelectColumn ( ElementTaskRelationPeer :: ELEMENT_UID );
$criteriaE -> addJoin ( BpmnEventPeer :: EVN_UID , ElementTaskRelationPeer :: ELEMENT_UID , Criteria :: LEFT_JOIN );
$criteriaE -> add ( ElementTaskRelationPeer :: TAS_UID , $arrayNextTaskData [ " TAS_UID " ], Criteria :: EQUAL );
$criteriaE -> add ( BpmnEventPeer :: EVN_TYPE , 'START' , Criteria :: EQUAL );
$criteriaE -> add ( BpmnEventPeer :: EVN_MARKER , 'TIMER' , Criteria :: EQUAL );
$rsCriteriaE = AppDelegationPeer :: doSelectRS ( $criteriaE );
$rsCriteriaE -> setFetchmode ( ResultSet :: FETCHMODE_ASSOC );
while ( $rsCriteriaE -> next ()) {
if ( $arrayNextTaskData [ " NEXT_TASK " ][ " TAS_TYPE " ] == " SCRIPT-TASK " ){
if ( isset ( $arrayNextTaskData [ " NEXT_TASK " ][ " USER_ASSIGNED " ][ " USR_UID " ]) && $arrayNextTaskData [ " NEXT_TASK " ][ " USER_ASSIGNED " ][ " USR_UID " ] == " " ){
$useruid = " 00000000000000000000000000000001 " ;
$userFields = $this -> getUsersFullNameFromArray ( $useruid );
$arrayNextTask [ $i ][ " NEXT_TASK " ][ " USER_ASSIGNED " ] = $userFields ;
}
}
}
2014-12-04 11:40:52 -04:00
}
}
2014-11-26 10:19:07 -04:00
2014-12-04 11:40:52 -04:00
//1. There is no rule
2015-09-09 10:46:31 -04:00
if ( empty ( $arrayNextTask )) {
2016-03-08 16:59:43 -04:00
$bpmn = new \ProcessMaker\Project\Bpmn ();
throw new Exception ( G :: LoadTranslation (
'ID_NO_DERIVATION_' . (( $bpmn -> exists ( $arrayApplicationData [ 'PRO_UID' ])) ? 'BPMN_RULE' : 'RULE' )
));
2014-12-04 11:40:52 -04:00
}
//Return
return $arrayNextTask ;
} catch ( Exception $e ) {
throw $e ;
}
2010-12-02 23:34:41 +00:00
}
2012-10-09 12:40:24 -04:00
/**
* getRouteCondition
*
* @ param array $aData
* @ return $routeCondition
*/
function getRouteCondition ( $aData )
{
$c = new Criteria ( 'workflow' );
$c -> clearSelectColumns ();
$c -> addSelectColumn ( AppDelegationPeer :: TAS_UID );
$c -> addSelectColumn ( RoutePeer :: ROU_CONDITION );
$c -> addSelectColumn ( RoutePeer :: ROU_NEXT_TASK );
$c -> addSelectColumn ( RoutePeer :: ROU_TYPE );
$c -> addSelectColumn ( RoutePeer :: ROU_OPTIONAL );
$c -> addJoin ( AppDelegationPeer :: TAS_UID , TaskPeer :: TAS_UID , Criteria :: LEFT_JOIN );
$c -> addJoin ( AppDelegationPeer :: TAS_UID , RoutePeer :: TAS_UID , Criteria :: LEFT_JOIN );
$c -> add ( AppDelegationPeer :: APP_UID , $aData [ 'APP_UID' ] );
$c -> add ( AppDelegationPeer :: DEL_INDEX , $aData [ 'DEL_INDEX' ] );
$c -> addAscendingOrderByColumn ( RoutePeer :: ROU_CASE );
$rs = AppDelegationPeer :: doSelectRs ( $c );
$rs -> setFetchmode ( ResultSet :: FETCHMODE_ASSOC );
$rs -> next ();
$aDerivation = $rs -> getRow ();
while ( is_array ( $aDerivation )) {
return $aDerivation ;
}
2010-12-02 23:34:41 +00:00
}
2012-10-09 12:40:24 -04:00
function GetAppParentIndex ( $aData )
{
//('SELECT * FROM APP_THREAD WHERE APP_UID='".$aData['APP_UID']."' AND DEL_INDEX = '".$aData['DEL_INDEX']."'");
try {
$aThreads = array ();
$c = new Criteria ();
$c -> addSelectColumn ( AppThreadPeer :: APP_THREAD_PARENT );
$c -> add ( AppThreadPeer :: APP_UID , $aData [ 'APP_UID' ] );
$c -> add ( AppThreadPeer :: DEL_INDEX , $aData [ 'DEL_INDEX' ] );
$rs = AppThreadPeer :: doSelectRs ( $c );
$rs -> setFetchmode ( ResultSet :: FETCHMODE_ASSOC );
$rs -> next ();
$row = $rs -> getRow ();
while ( is_array ( $row )) {
$aThreads = $row ;
$rs -> next ();
$row = $rs -> getRow ();
}
return $aThreads ;
} catch ( exception $e ) {
throw ( $e );
}
}
2010-12-02 23:34:41 +00:00
2012-10-09 12:40:24 -04:00
/* get all users , from any task , if the task have Groups , the function expand the group
2012-10-22 15:45:47 -04:00
*
* @ param string $sTasUid the task uidUser
2015-08-26 15:13:48 -04:00
* @ param bool $flagIncludeAdHocUsers
2012-10-22 15:45:47 -04:00
* @ return Array $users an array with userID order by USR_UID
*/
2015-08-26 15:13:48 -04:00
function getAllUsersFromAnyTask ( $sTasUid , $flagIncludeAdHocUsers = false )
2012-10-09 12:40:24 -04:00
{
$users = array ();
$c = new Criteria ( 'workflow' );
$c -> clearSelectColumns ();
$c -> addSelectColumn ( TaskUserPeer :: USR_UID );
$c -> addSelectColumn ( TaskUserPeer :: TU_RELATION );
$c -> add ( TaskUserPeer :: TAS_UID , $sTasUid );
2015-08-26 15:13:48 -04:00
if ( $flagIncludeAdHocUsers ) {
$c -> add (
$c -> getNewCriterion ( TaskUserPeer :: TU_TYPE , 1 , Criteria :: EQUAL ) -> addOr (
$c -> getNewCriterion ( TaskUserPeer :: TU_TYPE , 2 , Criteria :: EQUAL ))
);
} else {
$c -> add ( TaskUserPeer :: TU_TYPE , 1 );
}
2012-10-09 12:40:24 -04:00
$rs = TaskUserPeer :: DoSelectRs ( $c );
$rs -> setFetchmode ( ResultSet :: FETCHMODE_ASSOC );
$rs -> next ();
$row = $rs -> getRow ();
while ( is_array ( $row )) {
if ( $row [ 'TU_RELATION' ] == '2' ) {
$cGrp = new Criteria ( 'workflow' );
$cGrp -> add ( GroupwfPeer :: GRP_STATUS , 'ACTIVE' );
$cGrp -> add ( GroupUserPeer :: GRP_UID , $row [ 'USR_UID' ] );
$cGrp -> addJoin ( GroupUserPeer :: GRP_UID , GroupwfPeer :: GRP_UID , Criteria :: LEFT_JOIN );
$cGrp -> addJoin ( GroupUserPeer :: USR_UID , UsersPeer :: USR_UID , Criteria :: LEFT_JOIN );
2012-10-10 17:13:17 -04:00
$cGrp -> add ( UsersPeer :: USR_STATUS , 'INACTIVE' , Criteria :: NOT_EQUAL );
2012-10-09 12:40:24 -04:00
$rsGrp = GroupUserPeer :: DoSelectRs ( $cGrp );
$rsGrp -> setFetchmode ( ResultSet :: FETCHMODE_ASSOC );
$rsGrp -> next ();
$rowGrp = $rsGrp -> getRow ();
while ( is_array ( $rowGrp )) {
$users [ $rowGrp [ 'USR_UID' ]] = $rowGrp [ 'USR_UID' ];
$rsGrp -> next ();
$rowGrp = $rsGrp -> getRow ();
}
} else {
//filter to users that is in vacation or has an inactive estatus, and others
$oUser = UsersPeer :: retrieveByPK ( $row [ 'USR_UID' ] );
if ( $oUser -> getUsrStatus () == 'ACTIVE' ) {
$users [ $row [ 'USR_UID' ]] = $row [ 'USR_UID' ];
} else {
$userUID = $this -> checkReplacedByUser ( $oUser );
if ( $userUID != '' ) {
$users [ $userUID ] = $userUID ;
}
}
}
$rs -> next ();
$row = $rs -> getRow ();
2010-12-02 23:34:41 +00:00
}
2012-10-09 12:40:24 -04:00
//to do: different types of sort
sort ( $users );
2010-12-02 23:34:41 +00:00
2012-10-09 12:40:24 -04:00
return $users ;
}
2010-12-02 23:34:41 +00:00
2012-10-09 12:40:24 -04:00
/* get an array of users , and returns the same arrays with User ' s fullname and other fields
2012-10-22 15:45:47 -04:00
*
* @ param Array $aUsers the task uidUser
* @ return Array $aUsersData an array with with User ' s fullname
*/
2012-10-09 12:40:24 -04:00
function getUsersFullNameFromArray ( $aUsers )
{
$oUser = new Users ();
$aUsersData = array ();
if ( is_array ( $aUsers )) {
foreach ( $aUsers as $key => $val ) {
2012-10-10 17:13:17 -04:00
// $userFields = $oUser->load( $val );
$userFields = $oUser -> userVacation ( $val );
2012-10-09 12:40:24 -04:00
$auxFields [ 'USR_UID' ] = $userFields [ 'USR_UID' ];
$auxFields [ 'USR_USERNAME' ] = $userFields [ 'USR_USERNAME' ];
$auxFields [ 'USR_FIRSTNAME' ] = $userFields [ 'USR_FIRSTNAME' ];
$auxFields [ 'USR_LASTNAME' ] = $userFields [ 'USR_LASTNAME' ];
$auxFields [ 'USR_FULLNAME' ] = $userFields [ 'USR_LASTNAME' ] . ( $userFields [ 'USR_LASTNAME' ] != '' ? ', ' : '' ) . $userFields [ 'USR_FIRSTNAME' ];
$auxFields [ 'USR_EMAIL' ] = $userFields [ 'USR_EMAIL' ];
$auxFields [ 'USR_STATUS' ] = $userFields [ 'USR_STATUS' ];
$auxFields [ 'USR_COUNTRY' ] = $userFields [ 'USR_COUNTRY' ];
$auxFields [ 'USR_CITY' ] = $userFields [ 'USR_CITY' ];
$auxFields [ 'USR_LOCATION' ] = $userFields [ 'USR_LOCATION' ];
$auxFields [ 'DEP_UID' ] = $userFields [ 'DEP_UID' ];
$auxFields [ 'USR_HIDDEN_FIELD' ] = '' ;
$aUsersData [] = $auxFields ;
}
} else {
$oCriteria = new Criteria ();
$oCriteria -> add ( UsersPeer :: USR_UID , $aUsers );
if ( UsersPeer :: doCount ( $oCriteria ) < 1 ) {
return null ;
}
$userFields = $oUser -> load ( $aUsers );
$auxFields [ 'USR_UID' ] = $userFields [ 'USR_UID' ];
$auxFields [ 'USR_USERNAME' ] = $userFields [ 'USR_USERNAME' ];
$auxFields [ 'USR_FIRSTNAME' ] = $userFields [ 'USR_FIRSTNAME' ];
$auxFields [ 'USR_LASTNAME' ] = $userFields [ 'USR_LASTNAME' ];
$auxFields [ 'USR_FULLNAME' ] = $userFields [ 'USR_LASTNAME' ] . ( $userFields [ 'USR_LASTNAME' ] != '' ? ', ' : '' ) . $userFields [ 'USR_FIRSTNAME' ];
$auxFields [ 'USR_EMAIL' ] = $userFields [ 'USR_EMAIL' ];
$auxFields [ 'USR_STATUS' ] = $userFields [ 'USR_STATUS' ];
$auxFields [ 'USR_COUNTRY' ] = $userFields [ 'USR_COUNTRY' ];
$auxFields [ 'USR_CITY' ] = $userFields [ 'USR_CITY' ];
$auxFields [ 'USR_LOCATION' ] = $userFields [ 'USR_LOCATION' ];
$auxFields [ 'DEP_UID' ] = $userFields [ 'DEP_UID' ];
$aUsersData = $auxFields ;
}
return $aUsersData ;
2010-12-02 23:34:41 +00:00
}
2012-10-09 12:40:24 -04:00
/* get next assigned user
2012-10-22 15:45:47 -04:00
*
* @ param Array $tasInfo
* @ return Array $userFields
*/
2012-10-09 12:40:24 -04:00
function getNextAssignedUser ( $tasInfo )
2010-12-02 23:34:41 +00:00
{
2012-10-09 12:40:24 -04:00
$nextAssignedTask = $tasInfo [ 'NEXT_TASK' ];
$lastAssigned = $tasInfo [ 'NEXT_TASK' ][ 'TAS_LAST_ASSIGNED' ];
$sTasUid = $tasInfo [ 'NEXT_TASK' ][ 'TAS_UID' ];
2015-07-07 11:51:12 -04:00
2015-09-11 09:27:16 -04:00
$taskNext = TaskPeer :: retrieveByPK ( $nextAssignedTask [ " TAS_UID " ]);
$bpmnActivityNext = BpmnActivityPeer :: retrieveByPK ( $nextAssignedTask [ " TAS_UID " ]);
$flagTaskNextIsMultipleInstance = false ;
$flagTaskNextAssignTypeIsMultipleInstance = false ;
if ( ! is_null ( $taskNext ) && ! is_null ( $bpmnActivityNext )) {
2015-12-21 16:34:38 -04:00
$flagTaskNextIsMultipleInstance = $bpmnActivityNext -> getActType () == " TASK " && preg_match ( " /^(?:EMPTY|SENDTASK|RECEIVETASK|USERTASK|SERVICETASK|MANUALTASK|BUSINESSRULE) $ / " , $bpmnActivityNext -> getActTaskType ()) && $bpmnActivityNext -> getActLoopType () == " PARALLEL " ;
2015-09-11 09:27:16 -04:00
$flagTaskNextAssignTypeIsMultipleInstance = preg_match ( " /^(?:MULTIPLE_INSTANCE|MULTIPLE_INSTANCE_VALUE_BASED) $ / " , $taskNext -> getTasAssignType ());
}
$taskNextAssignType = $taskNext -> getTasAssignType ();
$taskNextAssignType = ( $flagTaskNextIsMultipleInstance && ! $flagTaskNextAssignTypeIsMultipleInstance ) ? " " : $taskNextAssignType ;
$taskNextAssignType = ( ! $flagTaskNextIsMultipleInstance && $flagTaskNextAssignTypeIsMultipleInstance ) ? " " : $taskNextAssignType ;
switch ( $taskNextAssignType ) {
2012-10-09 12:40:24 -04:00
case 'BALANCED' :
$users = $this -> getAllUsersFromAnyTask ( $sTasUid );
2015-09-11 09:27:16 -04:00
$uidUser = " " ;
2012-10-09 12:40:24 -04:00
if ( is_array ( $users ) && count ( $users ) > 0 ) {
//to do apply any filter like LOCATION assignment
$uidUser = $users [ 0 ];
$i = count ( $users ) - 1 ;
while ( $i > 0 ) {
2012-10-22 15:45:47 -04:00
if ( $lastAssigned < $users [ $i ]) {
2012-10-09 12:40:24 -04:00
$uidUser = $users [ $i ];
2012-10-22 15:45:47 -04:00
}
2012-10-09 12:40:24 -04:00
$i -- ;
}
} else {
throw ( new Exception ( G :: LoadTranslation ( 'ID_NO_USERS' ) ));
}
$userFields = $this -> getUsersFullNameFromArray ( $uidUser );
break ;
case 'STATIC_MI' :
case 'CANCEL_MI' :
case 'MANUAL' :
$users = $this -> getAllUsersFromAnyTask ( $sTasUid );
$userFields = $this -> getUsersFullNameFromArray ( $users );
break ;
case 'EVALUATE' :
$AppFields = $this -> case -> loadCase ( $tasInfo [ 'APP_UID' ] );
$variable = str_replace ( '@@' , '' , $nextAssignedTask [ 'TAS_ASSIGN_VARIABLE' ] );
if ( isset ( $AppFields [ 'APP_DATA' ][ $variable ] )) {
if ( $AppFields [ 'APP_DATA' ][ $variable ] != '' ) {
$value = $this -> checkReplacedByUser ( $AppFields [ 'APP_DATA' ][ $variable ] );
$userFields = $this -> getUsersFullNameFromArray ( $value );
if ( is_null ( $userFields )) {
throw ( new Exception ( " Task doesn't have a valid user in variable $variable . " ));
}
} else {
throw ( new Exception ( " Task doesn't have a valid user in variable $variable . " ));
}
2012-10-22 15:45:47 -04:00
} else {
2012-10-09 12:40:24 -04:00
throw ( new Exception ( " Task doesn't have a valid user in variable $variable or this variable doesn't exist. " ));
2012-10-22 15:45:47 -04:00
}
2012-10-09 12:40:24 -04:00
break ;
case 'REPORT_TO' :
//default error user when the reportsTo is not assigned to that user
//look for USR_REPORTS_TO to this user
$userFields [ 'USR_UID' ] = '' ;
$userFields [ 'USR_FULLNAME' ] = 'Current user does not have a valid Reports To user' ;
$userFields [ 'USR_USERNAME' ] = 'Current user does not have a valid Reports To user' ;
$userFields [ 'USR_FIRSTNAME' ] = '' ;
$userFields [ 'USR_LASTNAME' ] = '' ;
$userFields [ 'USR_EMAIL' ] = '' ;
//get the report_to user & its full info
2016-07-07 17:34:20 -04:00
$lastManager = $userTasInfo = $tasInfo [ " USER_UID " ];
do {
$userTasInfo = $this -> getDenpendentUser ( $userTasInfo );
$useruid = $this -> checkReplacedByUser ( $userTasInfo );
//When the lastManager is INACTIVE/VACATION and does not have a Replace by, the REPORT_TO is himself
if ( $lastManager === $userTasInfo ){
$useruid = $tasInfo [ " USER_UID " ];
} else {
$lastManager = $userTasInfo ;
}
} while ( $useruid === '' );
2012-10-09 12:40:24 -04:00
if ( isset ( $useruid ) && $useruid != '' ) {
$userFields = $this -> getUsersFullNameFromArray ( $useruid );
}
// if there is no report_to user info, throw an exception indicating this
if ( ! isset ( $userFields ) || $userFields [ 'USR_UID' ] == '' ) {
throw ( new Exception ( G :: LoadTranslation ( 'ID_MSJ_REPORSTO' ) )); // "The current user does not have a valid Reports To user. Please contact administrator.") ) ;
}
break ;
case 'SELF_SERVICE' :
2017-06-01 17:09:43 -04:00
//Check if is Self Service Value Based Assignment
if ( ! empty ( $nextAssignedTask [ 'TAS_GROUP_VARIABLE' ])) {
$appFields = $this -> case -> loadCase ( $tasInfo [ 'APP_UID' ]);
$variable = str_replace ( '@@' , '' , $nextAssignedTask [ 'TAS_GROUP_VARIABLE' ]);
//If the variable exists will be validate the UID's
if ( isset ( $appFields [ 'APP_DATA' ][ $variable ])) {
$arrVar = $appFields [ 'APP_DATA' ][ $variable ];
if ( is_array ( $arrVar )) {
$statusToCheck = $arrVar ;
} else {
$statusToCheck = array ( $arrVar );
}
$toValidate = array ( 'ACTIVE' , 'VACATION' );
$gpr = new GroupUser ();
if ( ! $gpr -> groupsUsersAvailable ( $statusToCheck , $toValidate )) {
if ( ! ( $gpr -> groupsUsersAvailable ( $statusToCheck , $toValidate , " groups " ))) {
throw ( new Exception ( " Task doesn't have a valid user in variable $variable or this variable doesn't exist. " ));
}
2017-06-01 12:10:02 -04:00
}
2017-06-01 17:09:43 -04:00
} else {
throw ( new Exception ( " Task doesn't have a valid user in variable $variable or this variable doesn't exist. " ));
2017-06-01 12:10:02 -04:00
}
}
2017-06-01 17:09:43 -04:00
2012-10-09 12:40:24 -04:00
//look for USR_REPORTS_TO to this user
$userFields [ 'USR_UID' ] = '' ;
2017-06-01 12:10:02 -04:00
$userFields [ 'USR_FULLNAME' ] = '<b>' . G :: LoadTranslation ( 'ID_UNASSIGNED' ) . '</b>' ;
$userFields [ 'USR_USERNAME' ] = '<b>' . G :: LoadTranslation ( 'ID_UNASSIGNED' ) . '</b>' ;
2012-10-09 12:40:24 -04:00
$userFields [ 'USR_FIRSTNAME' ] = '' ;
$userFields [ 'USR_LASTNAME' ] = '' ;
$userFields [ 'USR_EMAIL' ] = '' ;
break ;
2015-09-11 09:27:16 -04:00
case " MULTIPLE_INSTANCE " :
$userFields = $this -> getUsersFullNameFromArray ( $this -> getAllUsersFromAnyTask ( $nextAssignedTask [ " TAS_UID " ]));
2015-11-23 10:52:42 -04:00
if ( empty ( $userFields )){
throw ( new Exception ( G :: LoadTranslation ( 'ID_NO_USERS' ) ));
}
2015-09-11 09:27:16 -04:00
break ;
case " MULTIPLE_INSTANCE_VALUE_BASED " :
$arrayApplicationData = $this -> case -> loadCase ( $tasInfo [ " APP_UID " ]);
$nextTaskAssignVariable = trim ( $nextAssignedTask [ " TAS_ASSIGN_VARIABLE " ], " @# " );
2021-03-01 12:27:19 -04:00
// Verify the variable defined
if (
! empty ( $nextTaskAssignVariable )
&& isset ( $arrayApplicationData [ " APP_DATA " ][ $nextTaskAssignVariable ])
&& ! empty ( $arrayApplicationData [ " APP_DATA " ][ $nextTaskAssignVariable ])
2015-09-11 09:27:16 -04:00
) {
2021-03-01 12:27:19 -04:00
if ( is_array ( $arrayApplicationData [ " APP_DATA " ][ $nextTaskAssignVariable ])) {
$listUsers = $arrayApplicationData [ " APP_DATA " ][ $nextTaskAssignVariable ];
// Check if the array does not have an empty value
foreach ( $listUsers as $user ) {
if ( empty ( $user )) {
throw new Exception ( G :: LoadTranslation ( " ID_ACTIVITY_INVALID_USER_DATA_VARIABLE_FOR_MULTIPLE_INSTANCE_ACTIVITY " , [ strtolower ( " ACT_UID " ), $nextAssignedTask [ " TAS_UID " ], $nextTaskAssignVariable ]));
}
}
}
2015-09-11 09:27:16 -04:00
$userFields = $this -> getUsersFullNameFromArray ( $arrayApplicationData [ " APP_DATA " ][ $nextTaskAssignVariable ]);
} else {
2021-03-01 12:27:19 -04:00
throw new Exception ( G :: LoadTranslation ( " ID_ACTIVITY_INVALID_USER_DATA_VARIABLE_FOR_MULTIPLE_INSTANCE_ACTIVITY " , [ strtolower ( " ACT_UID " ), $nextAssignedTask [ " TAS_UID " ], $nextTaskAssignVariable ]));
2015-09-11 09:27:16 -04:00
}
break ;
2012-10-09 12:40:24 -04:00
default :
throw ( new Exception ( 'Invalid Task Assignment method for Next Task ' ));
2015-09-11 09:27:16 -04:00
break ;
2012-10-09 12:40:24 -04:00
}
return $userFields ;
2010-12-02 23:34:41 +00:00
}
2012-10-09 12:40:24 -04:00
/* getDenpendentUser
2012-10-22 15:45:47 -04:00
*
* @ param string $USR_UID
* @ return string $aRow [ 'USR_REPORTS_TO' ]
*/
function getDenpendentUser ( $USR_UID )
{
2016-03-07 10:53:56 -04:00
$user = new \ProcessMaker\BusinessModel\User ();
$manager = $user -> getUsersManager ( $USR_UID );
//Return
return ( $manager !== false ) ? $manager : $USR_UID ;
2012-10-09 12:40:24 -04:00
}
/* setTasLastAssigned
2012-10-22 15:45:47 -04:00
*
* @ param string $tasUid
* @ param string $usrUid
* @ throws Exception $e
* @ return void
*/
2012-10-09 12:40:24 -04:00
function setTasLastAssigned ( $tasUid , $usrUid )
{
try {
$oTask = TaskPeer :: retrieveByPk ( $tasUid );
$oTask -> setTasLastAssigned ( $usrUid );
$oTask -> save ();
} catch ( Exception $e ) {
throw ( $e );
}
2010-12-02 23:34:41 +00:00
}
2010-12-07 11:49:51 +00:00
2015-11-06 18:10:16 -04:00
/**
2016-06-09 16:14:50 -04:00
* Execute Event
2015-11-06 18:10:16 -04:00
*
2019-03-29 10:00:39 -04:00
* @ param string $dummyTaskUid Unique id of Element Origin ( unique id of Task ) This is the nextTask
* @ param array $applicationData Case data
* @ param bool $flagEventExecuteBeforeGateway Execute event before gateway
* @ param bool $flagEventExecuteAfterGateway Execute event after gateway
* @ param int $taskId
2015-11-06 18:10:16 -04:00
*
* @ return void
2019-03-29 10:00:39 -04:00
* @ see Derivation -> derivate ()
* @ see Derivation -> doRouteWithoutThread ()
* @ see Derivation -> finishProcess ()
* @ see Derivation -> finishTask ()
2015-11-06 18:10:16 -04:00
*/
2019-03-29 10:00:39 -04:00
private function executeEvent ( $dummyTaskUid , array $applicationData , $flagEventExecuteBeforeGateway = true , $flagEventExecuteAfterGateway = true , $elementOriUid = '' , $tasId = 0 )
2015-11-06 18:10:16 -04:00
{
try {
//Verify if the Project is BPMN
$bpmn = new \ProcessMaker\Project\Bpmn ();
2016-06-09 16:14:50 -04:00
if ( ! $bpmn -> exists ( $applicationData [ " PRO_UID " ])) {
2015-11-06 18:10:16 -04:00
return ;
}
//Element origin and dest
2020-08-10 17:11:55 -04:00
$arrayElement = [];
2015-11-06 18:10:16 -04:00
$elementTaskRelation = new \ProcessMaker\BusinessModel\ElementTaskRelation ();
2016-06-09 16:14:50 -04:00
$arrayElementTaskRelationData = $elementTaskRelation -> getElementTaskRelationWhere (
2015-11-06 18:10:16 -04:00
[
2016-06-09 16:14:50 -04:00
ElementTaskRelationPeer :: PRJ_UID => $applicationData [ " PRO_UID " ],
2015-11-06 18:10:16 -04:00
ElementTaskRelationPeer :: ELEMENT_TYPE => " bpmnEvent " ,
2016-06-09 16:14:50 -04:00
ElementTaskRelationPeer :: TAS_UID => $dummyTaskUid
2015-11-06 18:10:16 -04:00
],
true
2016-06-09 16:14:50 -04:00
);
if ( is_null ( $arrayElementTaskRelationData )){
2020-08-10 17:11:55 -04:00
$arrayOtherElement = [];
2016-06-09 16:14:50 -04:00
$arrayOtherElement = $bpmn -> getElementsBetweenElementOriginAndElementDest (
$elementOriUid ,
" bpmnActivity " ,
$dummyTaskUid ,
" bpmnActivity "
2015-11-06 18:10:16 -04:00
);
2016-06-09 16:14:50 -04:00
$count = 0 ;
foreach ( $arrayOtherElement as $value ) {
if ( $value [ 1 ] === 'bpmnEvent' ){
$arrayElement [ $count ][ " uid " ] = $value [ 0 ];
$arrayElement [ $count ++ ][ " type " ] = $value [ 1 ];
}
2015-11-06 18:10:16 -04:00
}
}
2016-06-09 16:14:50 -04:00
if ( ! is_null ( $arrayElementTaskRelationData )) {
$arrayElement [ 0 ][ " uid " ] = $arrayElementTaskRelationData [ " ELEMENT_UID " ];
$arrayElement [ 0 ][ " type " ] = " bpmnEvent " ;
}
2015-11-06 18:10:16 -04:00
//Throw Events
$messageApplication = new \ProcessMaker\BusinessModel\MessageApplication ();
$emailEvent = new \ProcessMaker\BusinessModel\EmailEvent ();
$arrayEventExecute = [ " BEFORE " => $flagEventExecuteBeforeGateway , " AFTER " => $flagEventExecuteAfterGateway ];
$positionEventExecute = " BEFORE " ;
2020-08-10 17:11:55 -04:00
$context = $this -> context ;
$context [ 'appUid' ] = $applicationData [ " APP_UID " ];
$context [ 'proUid' ] = $applicationData [ " PRO_UID " ];
2016-06-09 16:14:50 -04:00
if ( sizeof ( $arrayElement )){
foreach ( $arrayElement as $value ) {
switch ( $value [ 'type' ]) {
case 'bpmnEvent' :
if ( $arrayEventExecute [ $positionEventExecute ]) {
$event = \BpmnEventPeer :: retrieveByPK ( $value [ 'uid' ]);
if ( ! is_null ( $event )) {
if ( preg_match ( " /^(?:END|INTERMEDIATE) $ / " , $event -> getEvnType ()) && $event -> getEvnMarker () === 'MESSAGETHROW' ) {
//Message-Application throw
$result = $messageApplication -> create ( $applicationData [ " APP_UID " ], $applicationData [ " PRO_UID " ], $value [ 'uid' ], $applicationData );
2016-11-21 18:02:50 -05:00
2020-08-10 17:11:55 -04:00
$context [ 'envUid' ] = $value [ 'uid' ];
$context [ 'envType' ] = $event -> getEvnType ();
$context [ 'envMarker' ] = $event -> getEvnMarker ();
$context [ 'action' ] = 'Message application throw' ;
2016-11-21 18:02:50 -05:00
//Logger
2020-08-10 17:11:55 -04:00
$message = 'Case Derivation' ;
Log :: channel ( ':CaseDerivation' ) -> info ( $message , Bootstrap :: context ( $context ));
2016-06-09 16:14:50 -04:00
}
2015-11-06 18:10:16 -04:00
2016-06-09 16:14:50 -04:00
if ( preg_match ( " /^(?:END|INTERMEDIATE) $ / " , $event -> getEvnType ()) && $event -> getEvnMarker () === 'EMAIL' ) {
//Email-Event throw
2019-03-29 10:00:39 -04:00
$result = $emailEvent -> sendEmail ( $applicationData [ " APP_UID " ], $applicationData [ " PRO_UID " ], $value [ 'uid' ], $applicationData , $tasId );
2016-11-21 18:02:50 -05:00
2020-08-10 17:11:55 -04:00
$context [ 'envUid' ] = $value [ 'uid' ];
$context [ 'envType' ] = $event -> getEvnType ();
$context [ 'envMarker' ] = $event -> getEvnMarker ();
$context [ 'action' ] = 'Email event throw' ;
2016-11-21 18:02:50 -05:00
//Logger
2020-08-10 17:11:55 -04:00
$message = 'Case Derivation' ;
Log :: channel ( ':CaseDerivation' ) -> info ( $message , Bootstrap :: context ( $context ));
2016-06-09 16:14:50 -04:00
}
2015-11-06 18:10:16 -04:00
}
}
2016-06-09 16:14:50 -04:00
break ;
case 'bpmnGateway' :
$positionEventExecute = 'AFTER' ;
break ;
2015-11-22 13:43:30 -04:00
}
}
}
2015-11-20 15:17:47 -04:00
} catch ( Exception $e ) {
throw $e ;
}
}
2015-09-11 09:27:16 -04:00
/**
* Update counters
*
* @ param array $arrayCurrentDelegationData
* @ param array $arrayNextDelegationData
* @ param mixed $taskNextDelegation
* @ param array $arrayApplicationData
* @ param int $delIndexNew
* @ param mixed $aSp
* @ param bool $removeList
*
2015-10-19 14:01:31 -04:00
* @ return void
2021-03-11 11:59:42 -04:00
* @ deprecated function deprecated in Release 3.6 . x
2015-09-11 09:27:16 -04:00
*/
2016-11-18 15:11:22 -05:00
private function updateList ( array $arrayCurrentDelegationData , array $arrayNextDelegationData , $taskNextDelegation , array $arrayApplicationData , $delIndexNew , $aSp , $removeList )
2015-09-11 09:27:16 -04:00
{
try {
2016-08-01 15:30:30 -04:00
if ( $arrayNextDelegationData [ " TAS_UID " ] != " -1 " ) {
$regexpTaskTypeToExclude = " WEBENTRYEVENT|END-MESSAGE-EVENT|START-MESSAGE-EVENT|INTERMEDIATE-THROW-MESSAGE-EVENT|INTERMEDIATE-CATCH-MESSAGE-EVENT|SCRIPT-TASK|INTERMEDIATE-CATCH-TIMER-EVENT " ;
2015-09-11 09:27:16 -04:00
2016-08-01 15:30:30 -04:00
if ( ! preg_match ( " /^(?: " . $regexpTaskTypeToExclude . " ) $ / " , $taskNextDelegation -> getTasType ())) {
if ( ! empty ( $delIndexNew ) && empty ( $aSp )) {
$appDelegation = AppDelegationPeer :: retrieveByPK ( $arrayApplicationData [ " APP_UID " ], $delIndexNew );
$arrayApplicationData2 = $appDelegation -> toArray ( BasePeer :: TYPE_FIELDNAME );
2015-09-11 09:27:16 -04:00
2016-08-01 15:30:30 -04:00
$arrayApplicationData2 [ " APP_STATUS " ] = $arrayCurrentDelegationData [ " APP_STATUS " ];
2015-09-11 09:27:16 -04:00
2016-08-01 15:30:30 -04:00
$taskCurrent = TaskPeer :: retrieveByPK ( $arrayCurrentDelegationData [ " TAS_UID " ]);
2015-09-11 09:27:16 -04:00
2016-08-01 15:30:30 -04:00
if ( $taskCurrent -> getTasType () == " INTERMEDIATE-CATCH-MESSAGE-EVENT " ) {
$removeList = false ;
2015-09-11 09:27:16 -04:00
}
2016-08-01 15:30:30 -04:00
$arrayApplicationData2 [ " REMOVED_LIST " ] = $removeList ;
2021-04-26 17:57:12 -04:00
// Force to delete the row for avoid problems with duplicate key insert
$inbox = new ListInbox ();
$inbox -> remove ( $arrayApplicationData2 [ 'APP_UID' ], $arrayApplicationData2 [ 'DEL_INDEX' ]);
// Update the new row
2016-08-01 15:30:30 -04:00
$inbox = new ListInbox ();
2017-02-21 16:36:51 -04:00
$inbox -> newRow ( $arrayApplicationData2 , $arrayApplicationData [ " CURRENT_USER_UID " ], (( $arrayNextDelegationData [ " TAS_ASSIGN_TYPE " ] == " SELF_SERVICE " ) ? true : false ));
2015-09-11 09:27:16 -04:00
}
}
}
} catch ( Exception $e ) {
throw $e ;
}
}
2017-03-03 15:22:25 -04:00
/**
* This function prepare the information before call the derivate function
*
* We can route a case from differents ways from cases_Derivate and derivateCase used in PMFDerivateCase
* before this we need to process the information
*
* @ param array $aDataForPrepareInfo
* @ param array $tasks
* @ param string $rouType
* @ param array $aCurrentDerivation
* @ return array $arrayDerivationResult
*/
function beforeDerivate ( $aDataForPrepareInfo , $tasks , $rouType , $aCurrentDerivation )
{
$aPInformation = $this -> prepareInformation ( $aDataForPrepareInfo );
$oRoute = new \ProcessMaker\Core\RoutingScreen ();
$nextTasks = $oRoute -> mergeDataDerivation ( $tasks , $aPInformation , $rouType );
//Get all route types
2020-08-10 17:11:55 -04:00
$aRouteTypes = [];
2017-03-03 15:22:25 -04:00
foreach ( $aPInformation as $key => $value ) {
$aRouteTypes [ $key ][ 'ROU_NEXT_TASK' ] = $value [ 'ROU_NEXT_TASK' ];
$aRouteTypes [ $key ][ 'ROU_TYPE' ] = $value [ 'ROU_TYPE' ];
}
$aCurrentDerivation [ 'ROUTE_TYPES' ] = $aRouteTypes ;
//Derivate the case
$arrayDerivationResult = $this -> derivate ( $aCurrentDerivation , $nextTasks );
return $arrayDerivationResult ;
}
2019-02-07 15:43:04 -04:00
/**
* Route the case
2017-07-06 16:36:53 -04:00
* If need to create another thread we can execute the doDerivate
2012-10-22 15:45:47 -04:00
*
2015-10-19 14:01:31 -04:00
* @ param array $currentDelegation
* @ param array $nextDelegations
2017-07-06 16:36:53 -04:00
* @ param bool $removeList
2015-10-19 14:01:31 -04:00
*
* @ return void
2019-02-07 15:43:04 -04:00
* @ throws Exception
*
* @ see beforeDerivate ()
* @ see doDerivation ()
* @ see verifyIsCaseChild ()
2012-10-22 15:45:47 -04:00
*/
2015-10-19 14:01:31 -04:00
function derivate ( array $currentDelegation , array $nextDelegations , $removeList = true )
2012-10-09 12:40:24 -04:00
{
2017-10-10 12:33:25 -04:00
$this -> sysSys = ( ! empty ( config ( " system.workspace " ))) ? config ( " system.workspace " ) : " Undefined " ;
2020-08-10 17:11:55 -04:00
$this -> context = Bootstrap :: context ();
$context = $this -> context ;
2017-07-06 16:36:53 -04:00
$this -> removeList = $removeList ;
$arrayDerivationResult = [];
2015-12-09 17:01:20 -04:00
2012-10-09 12:40:24 -04:00
//define this...
2012-10-22 15:45:47 -04:00
if ( ! defined ( 'TASK_FINISH_PROCESS' )) {
2012-10-09 12:40:24 -04:00
define ( 'TASK_FINISH_PROCESS' , - 1 );
2012-10-22 15:45:47 -04:00
}
if ( ! defined ( 'TASK_FINISH_TASK' )) {
2012-10-09 12:40:24 -04:00
define ( 'TASK_FINISH_TASK' , - 2 );
2012-10-22 15:45:47 -04:00
}
2012-10-09 12:40:24 -04:00
2020-05-19 12:15:46 -04:00
$this -> case = new Cases ();
2012-10-09 12:40:24 -04:00
2015-06-25 15:59:34 -04:00
//Get data for this DEL_INDEX current
2012-10-09 12:40:24 -04:00
$appFields = $this -> case -> loadCase ( $currentDelegation [ 'APP_UID' ], $currentDelegation [ 'DEL_INDEX' ] );
2020-08-10 17:11:55 -04:00
$context [ 'appUid' ] = $currentDelegation [ 'APP_UID' ];
$context [ 'delIndex' ] = $currentDelegation [ 'DEL_INDEX' ];
2015-06-25 15:59:34 -04:00
2020-02-17 14:09:54 -04:00
// Remove the fields that will update with the thread creation
2016-08-04 11:36:58 -04:00
unset ( $appFields [ 'APP_ROUTING_DATA' ]);
2020-02-17 14:09:54 -04:00
$this -> appCurrentUser = $appFields [ 'APP_CUR_USER' ];
unset ( $appFields [ 'APP_CUR_USER' ]);
2016-08-04 11:36:58 -04:00
2015-06-25 15:59:34 -04:00
//We close the current derivation, then we'll try to derivate to each defined route
2012-10-09 12:40:24 -04:00
$this -> case -> CloseCurrentDelegation ( $currentDelegation [ 'APP_UID' ], $currentDelegation [ 'DEL_INDEX' ] );
2018-10-17 14:15:07 -04:00
//Set THE APP_STATUS
$appFields [ 'APP_STATUS' ] = $currentDelegation [ 'APP_STATUS' ];
2015-06-30 12:04:53 -04:00
//Get data for current delegation (current Task)
$task = TaskPeer :: retrieveByPK ( $currentDelegation [ " TAS_UID " ]);
2015-09-11 09:27:16 -04:00
$bpmnActivity = BpmnActivityPeer :: retrieveByPK ( $currentDelegation [ " TAS_UID " ]);
$flagTaskIsMultipleInstance = false ;
$flagTaskAssignTypeIsMultipleInstance = false ;
if ( ! is_null ( $task ) && ! is_null ( $bpmnActivity )) {
$flagTaskIsMultipleInstance = $bpmnActivity -> getActType () == " TASK " && preg_match ( " /^(?:EMPTY|USERTASK|MANUALTASK) $ / " , $bpmnActivity -> getActTaskType ()) && $bpmnActivity -> getActLoopType () == " PARALLEL " ;
$flagTaskAssignTypeIsMultipleInstance = preg_match ( " /^(?:MULTIPLE_INSTANCE|MULTIPLE_INSTANCE_VALUE_BASED) $ / " , $task -> getTasAssignType ());
}
2015-06-30 12:04:53 -04:00
$currentDelegation [ " TAS_ASSIGN_TYPE " ] = $task -> getTasAssignType ();
$currentDelegation [ " TAS_MI_COMPLETE_VARIABLE " ] = $task -> getTasMiCompleteVariable ();
$currentDelegation [ " TAS_MI_INSTANCE_VARIABLE " ] = $task -> getTasMiInstanceVariable ();
2020-08-10 17:11:55 -04:00
$arrayNextDerivation = [];
2015-10-23 12:16:54 -04:00
$flagFirstIteration = true ;
2015-06-25 15:59:34 -04:00
2012-10-09 12:40:24 -04:00
foreach ( $nextDelegations as $nextDel ) {
2016-06-09 16:14:50 -04:00
//BpmnEvent - END-MESSAGE-EVENT, END-EMAIL-EVENT, INTERMEDIATE-THROW-EMAIL-EVENT
2015-06-30 12:04:53 -04:00
//Check and get unique id
2015-02-21 15:59:12 -04:00
if ( preg_match ( " /^(. { 32}) \ /( \ -1) $ / " , $nextDel [ " TAS_UID " ], $arrayMatch )) {
$nextDel [ " TAS_UID " ] = $arrayMatch [ 2 ];
$nextDel [ " TAS_UID_DUMMY " ] = $arrayMatch [ 1 ];
}
2017-07-06 16:36:53 -04:00
//Review if is a Subprocesses then we update the $nextDel
if ( ! empty ( $nextDel [ 'TAS_PARENT' ])) {
$subProcessNextDel = $this -> getNextInfoSubProcess ( $nextDel , $appFields [ 'PRO_UID' ]);
if ( count ( $subProcessNextDel ) > 0 ) {
$nextDel = $subProcessNextDel ;
$aSP = $this -> aSP ;
2012-10-09 12:40:24 -04:00
} else {
continue ;
}
}
//get open threads
$openThreads = $this -> case -> GetOpenThreads ( $currentDelegation [ 'APP_UID' ] );
//if we are derivating to finish process but there are no more open thread then we are finishing only the task, we are not finishing the whole process
if (( $nextDel [ 'TAS_UID' ] == TASK_FINISH_PROCESS ) && (( $openThreads + 1 ) > 1 )) {
$nextDel [ 'TAS_UID' ] = TASK_FINISH_TASK ;
}
2015-06-30 12:04:53 -04:00
$taskNextDel = TaskPeer :: retrieveByPK ( $nextDel [ " TAS_UID " ]); //Get data for next delegation (next Task)
2015-09-11 09:27:16 -04:00
$bpmnActivityNextDel = BpmnActivityPeer :: retrieveByPK ( $nextDel [ " TAS_UID " ]);
$flagTaskNextDelIsMultipleInstance = false ;
$flagTaskNextDelAssignTypeIsMultipleInstance = false ;
if ( ! is_null ( $taskNextDel ) && ! is_null ( $bpmnActivityNextDel )) {
$flagTaskNextDelIsMultipleInstance = $bpmnActivityNextDel -> getActType () == " TASK " && preg_match ( " /^(?:EMPTY|USERTASK|MANUALTASK) $ / " , $bpmnActivityNextDel -> getActTaskType ()) && $bpmnActivityNextDel -> getActLoopType () == " PARALLEL " ;
$flagTaskNextDelAssignTypeIsMultipleInstance = preg_match ( " /^(?:MULTIPLE_INSTANCE|MULTIPLE_INSTANCE_VALUE_BASED) $ / " , $taskNextDel -> getTasAssignType ());
}
2017-07-06 16:36:53 -04:00
$this -> flagUpdateList = true ;
2015-06-30 12:04:53 -04:00
2020-08-10 17:11:55 -04:00
$context [ 'tasUid' ] = $nextDel [ 'TAS_UID' ];
2012-10-09 12:40:24 -04:00
switch ( $nextDel [ 'TAS_UID' ]) {
case TASK_FINISH_PROCESS :
2017-07-06 16:36:53 -04:00
$this -> finishProcess (
$currentDelegation ,
$nextDel ,
$appFields ,
$flagFirstIteration ,
2020-08-10 17:11:55 -04:00
$context
2017-07-06 16:36:53 -04:00
);
2012-10-09 12:40:24 -04:00
break ;
case TASK_FINISH_TASK :
2017-07-06 16:36:53 -04:00
$this -> finishTask (
$currentDelegation ,
$nextDel ,
$appFields ,
$flagFirstIteration ,
$flagTaskAssignTypeIsMultipleInstance ,
2020-08-10 17:11:55 -04:00
$context
2017-07-06 16:36:53 -04:00
);
2012-10-09 12:40:24 -04:00
break ;
default :
2015-09-11 09:27:16 -04:00
//Get all siblingThreads
$canDerivate = false ;
2017-01-10 17:51:08 -04:00
$nextDel [ 'TAS_ID' ] = $taskNextDel -> getTasId ();
2015-09-11 09:27:16 -04:00
2012-10-09 12:40:24 -04:00
switch ( $currentDelegation [ 'TAS_ASSIGN_TYPE' ]) {
case 'CANCEL_MI' :
case 'STATIC_MI' :
2017-07-06 16:36:53 -04:00
$canDerivate = $this -> canRouteTasAssignStaticMi ( $currentDelegation );
2012-10-09 12:40:24 -04:00
break ;
default :
2015-09-11 09:27:16 -04:00
$routeType = $currentDelegation [ " ROU_TYPE " ];
$routeType = ( $flagTaskIsMultipleInstance && $flagTaskAssignTypeIsMultipleInstance ) ? " SEC-JOIN " : $routeType ;
switch ( $routeType ) {
case " SEC-JOIN " :
2017-07-06 16:36:53 -04:00
$canDerivate = $this -> canRouteTypeSecJoin (
$flagTaskIsMultipleInstance ,
$flagTaskAssignTypeIsMultipleInstance ,
$currentDelegation ,
$appFields ,
$nextDel
);
$arraySiblings = $this -> arraySiblings ;
2015-09-11 09:27:16 -04:00
break ;
default :
$canDerivate = true ;
2015-11-13 15:05:26 -04:00
//Check if the previous is a SEC-JOIN and check threads
if ( isset ( $nextDel [ " ROU_PREVIOUS_TYPE " ])){
if ( $nextDel [ " ROU_PREVIOUS_TYPE " ] == " SEC-JOIN " ){
2017-07-06 16:36:53 -04:00
$arrayOpenThread = $this -> case -> searchOpenPreviousTasks (
$nextDel [ " ROU_PREVIOUS_TASK " ],
$currentDelegation [ " APP_UID " ]
);
$arraySiblings = $this -> case -> getOpenSiblingThreads (
$nextDel [ " ROU_PREVIOUS_TASK " ],
$currentDelegation [ " APP_UID " ],
$currentDelegation [ " DEL_INDEX " ],
$currentDelegation [ " TAS_UID " ]
);
2016-06-30 09:31:34 -04:00
if ( is_array ( $arrayOpenThread ) && is_array ( $arraySiblings )){
$arrayOpenThread = array_merge ( $arrayOpenThread , $arraySiblings );
}
2015-11-13 15:05:26 -04:00
$canDerivate = empty ( $arrayOpenThread );
}
}
2015-09-11 09:27:16 -04:00
break ;
2012-10-09 12:40:24 -04:00
}
2015-09-11 09:27:16 -04:00
break ;
}
2012-10-09 12:40:24 -04:00
if ( $canDerivate ) {
2017-07-06 16:36:53 -04:00
/**
* CREATE a new index / thread in the AppDelegation
*/
$nextDel [ 'USR_UID' ] = ( ! isset ( $nextDel [ 'USR_UID' ])) ? '' : $nextDel [ 'USR_UID' ];
2015-11-06 18:10:16 -04:00
//Throw Events
2017-07-06 16:36:53 -04:00
$this -> executeEvent (
$nextDel [ " TAS_UID " ],
$appFields ,
true ,
true ,
2019-03-29 10:00:39 -04:00
$currentDelegation [ " TAS_UID " ],
! empty ( $nextDel [ " TAS_ID " ]) ? $nextDel [ " TAS_ID " ] : 0
2017-07-06 16:36:53 -04:00
);
2015-06-30 12:04:53 -04:00
2017-07-06 16:36:53 -04:00
//Route the case
2015-09-11 09:27:16 -04:00
$aSP = ( isset ( $aSP )) ? $aSP : null ;
$taskNextDelAssignType = ( $flagTaskNextDelIsMultipleInstance && $flagTaskNextDelAssignTypeIsMultipleInstance ) ? $taskNextDel -> getTasAssignType () : " " ;
switch ( $taskNextDelAssignType ) {
case " MULTIPLE_INSTANCE " :
case " MULTIPLE_INSTANCE_VALUE_BASED " :
2017-07-06 16:36:53 -04:00
$arrayDerivationResult = $this -> routeMultipleInstance (
$currentDelegation ,
$nextDel ,
$taskNextDel ,
$appFields ,
$aSP ,
$this -> removeList
);
$iNewDelIndex = $this -> iNewDelIndex ;
break ;
2015-09-11 09:27:16 -04:00
default :
$iNewDelIndex = $this -> doDerivation ( $currentDelegation , $nextDel , $appFields , $aSP );
2021-09-28 14:29:18 -04:00
$appUid = $currentDelegation [ 'APP_UID' ];
2020-11-19 17:21:05 -04:00
// Load Case Data again because the information could be change in method "doDerivation"
2021-09-28 14:29:18 -04:00
$lastData = $this -> case -> loadCase ( $appUid );
// Update the thread title related to the last index created
2021-10-05 15:51:43 -04:00
if ( ! is_null ( $iNewDelIndex )) {
$this -> case -> updateThreadTitle ( $appUid , $lastData [ 'APP_NUMBER' ], $iNewDelIndex , $lastData [ 'APP_DATA' ]);
}
2021-09-28 14:29:18 -04:00
$appFields [ 'APP_DATA' ] = $lastData [ 'APP_DATA' ];
// When the users route the case in the same time
if ( $iNewDelIndex !== 0 ) {
2017-07-06 16:36:53 -04:00
$arrayDerivationResult [] = [
'DEL_INDEX' => $iNewDelIndex ,
'TAS_UID' => $nextDel [ 'TAS_UID' ],
'USR_UID' => ( isset ( $nextDel [ 'USR_UID' ])) ? $nextDel [ 'USR_UID' ] : ''
];
2016-04-14 15:51:36 -04:00
}
2015-09-11 09:27:16 -04:00
break ;
}
2016-11-25 13:06:25 -05:00
//Execute Service Task
if ( function_exists ( 'executeServiceTaskByActivityUid' )) {
$appFields [ " APP_DATA " ] = executeServiceTaskByActivityUid ( $nextDel [ " TAS_UID " ], $appFields );
}
2015-06-25 15:59:34 -04:00
//Execute Script-Task
$scriptTask = new \ProcessMaker\BusinessModel\ScriptTask ();
2015-06-29 17:19:59 -04:00
$appFields [ " APP_DATA " ] = $scriptTask -> execScriptByActivityUid ( $nextDel [ " TAS_UID " ], $appFields );
2015-02-21 15:59:12 -04:00
2014-10-27 11:25:17 -04:00
//Create record in table APP_ASSIGN_SELF_SERVICE_VALUE
2016-11-25 13:06:25 -05:00
$regexpTaskTypeToExclude = " SCRIPT-TASK|INTERMEDIATE-THROW-EMAIL-EVENT|SERVICE-TASK " ;
2015-09-11 09:27:16 -04:00
if ( ! is_null ( $taskNextDel ) && ! preg_match ( " /^(?: " . $regexpTaskTypeToExclude . " ) $ / " , $taskNextDel -> getTasType ())) {
2017-07-06 16:36:53 -04:00
$this -> createRecordAppSelfServiceValue (
$taskNextDel ,
$iNewDelIndex ,
$nextDel [ " TAS_UID " ],
2018-07-31 08:45:54 -04:00
$appFields ,
$taskNextDel -> getTasId ()
2017-07-06 16:36:53 -04:00
);
2014-10-27 11:25:17 -04:00
}
2015-06-25 15:59:34 -04:00
2017-07-06 16:36:53 -04:00
//Elements with automatic execution
$aTaskTypeToInclude = array ( 'SCRIPT-TASK' , 'INTERMEDIATE-THROW-EMAIL-EVENT' , 'INTERMEDIATE-THROW-MESSAGE-EVENT' , 'SERVICE-TASK' );
//Prepare information when the current is $aTaskTypeToInclude and the next element does not have user
if ( ! is_null ( $taskNextDel ) && in_array ( $taskNextDel -> getTasType (), $aTaskTypeToInclude )) {
$arrayNextDerivation [] = $this -> routePrepareInformationNextTask (
$currentDelegation ,
$iNewDelIndex ,
$nextDel
);
2015-06-25 15:59:34 -04:00
}
2012-10-22 15:45:47 -04:00
} else {
2017-07-06 16:36:53 -04:00
/**
* NO CREATE a new index / thread in the AppDelegation
*/
$this -> doRouteWithoutThread ( $appFields , $currentDelegation , $nextDel , $arraySiblings , $flagTaskIsMultipleInstance , $flagTaskAssignTypeIsMultipleInstance , $flagFirstIteration );
2015-03-27 14:24:56 -04:00
}
2017-07-06 16:36:53 -04:00
2015-09-11 09:27:16 -04:00
break ;
2015-03-06 18:06:31 -04:00
}
2016-11-23 11:27:07 -05:00
//$flagUpdateList is updated when is parallel
2017-07-06 16:36:53 -04:00
if ( ! is_null ( $taskNextDel ) && $this -> flagUpdateList ){
$this -> updateList (
$currentDelegation ,
$nextDel ,
$taskNextDel ,
$appFields ,
( isset ( $iNewDelIndex )) ? $iNewDelIndex : 0 ,
( isset ( $aSP )) ? $aSP : null ,
$this -> removeList
);
2015-09-11 09:27:16 -04:00
}
2015-06-25 15:59:34 -04:00
2017-07-06 16:36:53 -04:00
$this -> removeList = false ;
2015-10-23 12:16:54 -04:00
$flagFirstIteration = false ;
2015-09-11 09:27:16 -04:00
unset ( $aSP );
}
2012-10-09 12:40:24 -04:00
/* Start Block : Count the open threads of $currentDelegation['APP_UID'] */
$openThreads = $this -> case -> GetOpenThreads ( $currentDelegation [ 'APP_UID' ] );
2017-07-06 11:36:40 -04:00
$flagUpdateCase = false ;
2012-10-09 12:40:24 -04:00
2018-10-17 14:15:07 -04:00
//Check if there is any paused thread
2016-06-07 12:50:45 -04:00
$existThreadPaused = false ;
2016-06-07 12:29:08 -04:00
if ( isset ( $arraySiblings [ 'pause' ])) {
if ( ! empty ( $arraySiblings [ 'pause' ])) {
2016-06-07 12:50:45 -04:00
$existThreadPaused = true ;
2016-06-07 12:29:08 -04:00
}
}
2016-06-07 12:50:45 -04:00
if ( $openThreads == 0 && ! $existThreadPaused ) {
2012-10-09 12:40:24 -04:00
//Close case
$appFields [ " APP_STATUS " ] = " COMPLETED " ;
$appFields [ " APP_FINISH_DATE " ] = " now " ;
2018-08-08 16:46:55 -04:00
if ( SubApplication :: isCaseSubProcess ( $currentDelegation [ " APP_UID " ])) {
$this -> verifyIsCaseChild ( $currentDelegation [ " APP_UID " ], $currentDelegation [ " DEL_INDEX " ]);
}
2017-07-06 11:36:40 -04:00
$flagUpdateCase = true ;
2010-12-02 23:34:41 +00:00
}
2012-10-09 12:40:24 -04:00
2017-07-06 11:36:40 -04:00
//The variable $iNewDelIndex will be true if we created a new index the variable
if ( isset ( $iNewDelIndex )) {
2012-10-09 12:40:24 -04:00
$appFields [ " DEL_INDEX " ] = $iNewDelIndex ;
2017-07-06 11:36:40 -04:00
$excludeTasUid = array ( TASK_FINISH_PROCESS , TASK_FINISH_TASK );
2017-07-20 16:57:23 -04:00
//If the last TAS_UID value is not valid we will check for the valid TAS_UID value
2017-07-06 11:36:40 -04:00
if ( in_array ( $nextDel [ " TAS_UID " ], $excludeTasUid ) && is_array ( $arrayDerivationResult ) && isset ( current ( $arrayDerivationResult )[ " TAS_UID " ])) {
$appFields [ " TAS_UID " ] = current ( $arrayDerivationResult )[ " TAS_UID " ];
2017-07-20 16:57:23 -04:00
} else {
$appFields [ " TAS_UID " ] = $nextDel [ " TAS_UID " ];
2017-07-06 11:36:40 -04:00
}
$flagUpdateCase = true ;
2010-12-02 23:34:41 +00:00
}
2012-10-09 12:40:24 -04:00
2017-07-06 11:36:40 -04:00
if ( $flagUpdateCase ) {
2012-10-09 12:40:24 -04:00
//Start Block : UPDATES APPLICATION
$this -> case -> updateCase ( $currentDelegation [ " APP_UID " ], $appFields );
//End Block : UPDATES APPLICATION
}
2015-10-19 14:01:31 -04:00
//Start the next derivations (Script-Task)
if ( ! empty ( $arrayNextDerivation )) {
foreach ( $arrayNextDerivation as $value ) {
$this -> derivate ( $value [ " currentDelegation " ], $value [ " nextDelegations " ]);
}
}
2015-12-09 17:01:20 -04:00
//Return
return $arrayDerivationResult ;
2012-10-09 12:40:24 -04:00
}
2017-07-06 16:36:53 -04:00
/** We can create a new thread in the appDelegation
* This function is used in derivate
*
* @ param array $currentDelegation
* @ param array $nextDel
* @ param array $appFields
* @ param array $aSP
*
2020-04-30 16:08:24 -04:00
* @ return integer
2017-07-06 16:36:53 -04:00
* @ throws / Exception
*/
2012-10-09 12:40:24 -04:00
function doDerivation ( $currentDelegation , $nextDel , $appFields , $aSP = null )
{
2016-08-04 11:36:58 -04:00
$case = new \ProcessMaker\BusinessModel\Cases ();
$arrayApplicationData = $case -> getApplicationRecordByPk ( $currentDelegation [ 'APP_UID' ], [], false );
2016-08-15 16:54:43 -04:00
$arrayRoutingData = ( ! is_null ( $arrayApplicationData [ 'APP_ROUTING_DATA' ]) && ( string )( $arrayApplicationData [ 'APP_ROUTING_DATA' ]) != '' ) ? unserialize ( $arrayApplicationData [ 'APP_ROUTING_DATA' ]) : [];
2016-08-04 11:36:58 -04:00
2012-10-09 12:40:24 -04:00
$iAppThreadIndex = $appFields [ 'DEL_THREAD' ];
$delType = 'NORMAL' ;
2016-11-21 16:36:30 -04:00
$sendNotifications = false ;
2016-06-27 12:10:04 -04:00
$sendNotificationsMobile = false ;
2012-10-09 12:40:24 -04:00
2016-08-15 16:54:43 -04:00
$appDelegation = new AppDelegation ();
2016-08-04 11:36:58 -04:00
$taskNextDel = TaskPeer :: retrieveByPK ( $nextDel [ " TAS_UID " ]);
2016-08-15 16:54:43 -04:00
$arrayAppDelegationPrevious = $appDelegation -> getPreviousDelegationValidTask ( $currentDelegation [ 'APP_UID' ], $currentDelegation [ 'DEL_INDEX' ], true );
$taskUidOrigin = $arrayAppDelegationPrevious [ 'TAS_UID' ];
2016-08-04 11:36:58 -04:00
$taskUidDest = $taskNextDel -> getTasUid ();
if ( array_key_exists ( $taskUidOrigin . '/' . $taskUidDest , $arrayRoutingData )) {
2016-10-01 15:27:37 -04:00
if ( isset ( $arrayRoutingData [ $taskUidOrigin . '/' . $taskUidDest ][ 'USR_UID' ])){
$nextDel [ 'USR_UID' ] = $arrayRoutingData [ $taskUidOrigin . '/' . $taskUidDest ][ 'USR_UID' ];
}
2016-08-04 11:36:58 -04:00
unset ( $arrayRoutingData [ $taskUidOrigin . '/' . $taskUidDest ]);
}
if ( $taskNextDel -> getTasType () == 'NORMAL' &&
$taskNextDel -> getTasAssignType () != 'SELF_SERVICE' &&
( is_null ( $nextDel [ 'USR_UID' ]) || $nextDel [ 'USR_UID' ] == '' )
) {
throw new Exception ( G :: LoadTranslation ( 'ID_NO_USERS' ));
}
2012-10-09 12:40:24 -04:00
if ( is_numeric ( $nextDel [ 'DEL_PRIORITY' ] )) {
$nextDel [ 'DEL_PRIORITY' ] = ( isset ( $nextDel [ 'DEL_PRIORITY' ] ) ? ( $nextDel [ 'DEL_PRIORITY' ] >= 1 && $nextDel [ 'DEL_PRIORITY' ] <= 5 ? $nextDel [ 'DEL_PRIORITY' ] : '3' ) : '3' );
} else {
$nextDel [ 'DEL_PRIORITY' ] = 3 ;
}
2016-08-04 11:36:58 -04:00
2020-02-17 14:09:54 -04:00
$newDelegationUser = '' ;
2012-10-09 12:40:24 -04:00
switch ( $nextDel [ 'TAS_ASSIGN_TYPE' ]) {
2010-12-02 23:34:41 +00:00
case 'CANCEL_MI' :
case 'STATIC_MI' :
2012-10-09 12:40:24 -04:00
// Create new delegation depending on the no of users in the group
2017-07-06 16:36:53 -04:00
$iNewDelIndex = $this -> doDerivationStaticMi (
$appFields ,
$currentDelegation ,
$nextDel ,
$iAppThreadIndex ,
$delType
);
2012-10-09 12:40:24 -04:00
break ;
case 'BALANCED' :
2017-07-06 16:36:53 -04:00
$this -> setTasLastAssigned ( $nextDel [ 'TAS_UID' ], $nextDel [ 'USR_UID' ]);
2012-10-22 15:45:47 -04:00
//No Break, need no execute the default ones....
2011-10-24 08:48:59 -04:00
default :
2016-04-15 16:46:47 -04:00
$delPrevious = 0 ;
if ( $this -> flagControlMulInstance ){
$criteriaMulti = new Criteria ( " workflow " );
$criteriaMulti -> addSelectColumn ( AppDelegationPeer :: DEL_PREVIOUS );
2020-01-21 09:54:21 -04:00
$criteriaMulti -> add ( AppDelegationPeer :: APP_UID , $currentDelegation [ 'APP_UID' ], Criteria :: EQUAL );
$criteriaMulti -> add ( AppDelegationPeer :: DEL_INDEX , $currentDelegation [ 'DEL_INDEX' ], Criteria :: EQUAL );
2016-04-15 16:46:47 -04:00
$criteriaMulti -> add ( AppDelegationPeer :: TAS_UID , $currentDelegation [ 'TAS_UID' ], Criteria :: EQUAL );
$criteriaMultiR = AppDelegationPeer :: doSelectRS ( $criteriaMulti );
$criteriaMultiR -> setFetchmode ( ResultSet :: FETCHMODE_ASSOC );
$criteriaMultiR -> next ();
$row = $criteriaMultiR -> getRow ();
$delPrevious = $row [ 'DEL_PREVIOUS' ];
}
2020-02-17 14:09:54 -04:00
// Get the user that will create the new case
$newDelegationUser = $this -> verifyCurrentUserInTask ( $nextDel , $aSP );
2012-10-09 12:40:24 -04:00
// Create new delegation
2017-01-10 17:51:08 -04:00
$iNewDelIndex = $this -> case -> newAppDelegation (
$appFields [ 'PRO_UID' ],
$currentDelegation [ 'APP_UID' ],
$nextDel [ 'TAS_UID' ],
2020-02-17 14:09:54 -04:00
$newDelegationUser ,
2017-01-10 17:51:08 -04:00
$currentDelegation [ 'DEL_INDEX' ],
$nextDel [ 'DEL_PRIORITY' ],
$iAppThreadIndex ,
$nextDel ,
$this -> flagControl ,
$this -> flagControlMulInstance ,
$delPrevious ,
$appFields [ 'APP_NUMBER' ],
$appFields [ 'PRO_ID' ],
$nextDel [ 'TAS_ID' ]
);
2012-10-09 12:40:24 -04:00
break ;
}
2012-08-16 11:44:17 -04:00
2016-08-04 11:36:58 -04:00
if ( array_key_exists ( 'NEXT_ROUTING' , $nextDel ) && is_array ( $nextDel [ 'NEXT_ROUTING' ]) && ! empty ( $nextDel [ 'NEXT_ROUTING' ])) {
if ( array_key_exists ( 'TAS_UID' , $nextDel [ 'NEXT_ROUTING' ])) {
$arrayRoutingData [ $currentDelegation [ 'TAS_UID' ] . '/' . $nextDel [ 'NEXT_ROUTING' ][ 'TAS_UID' ]] = $nextDel [ 'NEXT_ROUTING' ];
} else {
foreach ( $nextDel [ 'NEXT_ROUTING' ] as $value ) {
$arrayRoutingData [ $currentDelegation [ 'TAS_UID' ] . '/' . $value [ 'TAS_UID' ]] = $value ;
}
}
}
2020-02-17 14:09:54 -04:00
/** Update the table application */
$applicationFields = [
'APP_ROUTING_DATA' => $arrayRoutingData ,
'APP_CUR_USER' => $newDelegationUser
];
$colUpdated = ModelApplication :: updateColumns ( $currentDelegation [ 'APP_UID' ], $applicationFields );
$appFields [ 'APP_CUR_USER' ] = ! empty ( $colUpdated [ 'APP_CUR_USER' ]) ? $colUpdated [ 'APP_CUR_USER' ] : $this -> appCurrentUser ;
2016-08-04 11:36:58 -04:00
2020-02-17 14:09:54 -04:00
// We updated the information relate to APP_THREAD
2012-10-09 12:40:24 -04:00
$iAppThreadIndex = $appFields [ 'DEL_THREAD' ];
2017-03-06 18:08:16 -04:00
$isUpdatedThread = false ;
2017-03-02 16:30:01 -04:00
if ( isset ( $currentDelegation [ 'ROUTE_TYPES' ]) && sizeof ( $currentDelegation [ 'ROUTE_TYPES' ]) > 1 ) {
//If the next is more than one thread: Parallel or other
foreach ( $currentDelegation [ 'ROUTE_TYPES' ] as $key => $value ) {
if ( $value [ 'ROU_NEXT_TASK' ] === $nextDel [ 'TAS_UID' ]) {
2017-03-06 18:08:16 -04:00
$isUpdatedThread = true ;
2017-03-02 16:30:01 -04:00
$routeType = ( $value [ 'ROU_TYPE' ] === 'EVALUATE' ) ? 'PARALLEL-AND-EXCLUSIVE' : $value [ 'ROU_TYPE' ];
$this -> updateAppThread ( $routeType , $currentDelegation [ 'APP_UID' ], $iAppThreadIndex , $iNewDelIndex );
}
}
2017-03-06 18:08:16 -04:00
}
if ( ! $isUpdatedThread ) {
2017-03-02 16:30:01 -04:00
//If the next is a sequential derivation
$this -> updateAppThread ( $currentDelegation [ 'ROU_TYPE' ], $currentDelegation [ 'APP_UID' ], $iAppThreadIndex , $iNewDelIndex );
}
2017-07-06 16:36:53 -04:00
//if there are SubProcess to create
if ( isset ( $aSP )) {
2020-04-30 16:08:24 -04:00
// Create case in the subprocess
2020-07-09 17:00:11 -04:00
$subProcessFields = $this -> subProcessCreation ( $aSP , $appFields , $currentDelegation , $iNewDelIndex , $iAppThreadIndex );
2016-07-15 14:52:57 -04:00
2020-04-30 16:08:24 -04:00
// If is ASYNCHRONOUS we will to route the case master
2012-10-09 12:40:24 -04:00
if ( $aSP [ 'SP_SYNCHRONOUS' ] == 0 ) {
$this -> case -> setDelInitDate ( $currentDelegation [ 'APP_UID' ], $iNewDelIndex );
2017-03-23 16:13:40 -04:00
$aDeriveTasks = $this -> prepareInformation (
array (
'USER_UID' => - 1 ,
'APP_UID' => $currentDelegation [ 'APP_UID' ],
'DEL_INDEX' => $iNewDelIndex
)
);
2012-10-09 12:40:24 -04:00
2016-06-14 10:46:34 -04:00
if ( isset ( $aDeriveTasks [ 1 ])) {
2012-10-09 12:40:24 -04:00
if ( $aDeriveTasks [ 1 ][ 'ROU_TYPE' ] != 'SELECT' ) {
2020-08-10 17:11:55 -04:00
$nextDelegations2 = [];
2012-10-09 12:40:24 -04:00
foreach ( $aDeriveTasks as $aDeriveTask ) {
2017-03-23 16:13:40 -04:00
$nextDelegations2 [] = array (
'TAS_UID' => $aDeriveTask [ 'NEXT_TASK' ][ 'TAS_UID' ],
'USR_UID' => $aDeriveTask [ 'NEXT_TASK' ][ 'USER_ASSIGNED' ][ 'USR_UID' ],
'TAS_ASSIGN_TYPE' => $aDeriveTask [ 'NEXT_TASK' ][ 'TAS_ASSIGN_TYPE' ],
'TAS_DEF_PROC_CODE' => $aDeriveTask [ 'NEXT_TASK' ][ 'TAS_DEF_PROC_CODE' ],
'DEL_PRIORITY' => 3 ,
'TAS_PARENT' => $aDeriveTask [ 'NEXT_TASK' ][ 'TAS_PARENT' ],
2017-04-12 10:42:25 -04:00
'ROU_PREVIOUS_TYPE' => isset ( $aDeriveTask [ 'NEXT_TASK' ][ 'ROU_PREVIOUS_TYPE' ]) ? $aDeriveTask [ 'NEXT_TASK' ][ 'ROU_PREVIOUS_TYPE' ] : '' ,
'ROU_PREVIOUS_TASK' => isset ( $aDeriveTask [ 'NEXT_TASK' ][ 'ROU_PREVIOUS_TASK' ]) ? $aDeriveTask [ 'NEXT_TASK' ][ 'ROU_PREVIOUS_TASK' ] : ''
2012-10-09 12:40:24 -04:00
);
}
2017-03-23 16:13:40 -04:00
$currentDelegation2 = array (
'APP_UID' => $currentDelegation [ 'APP_UID' ],
'DEL_INDEX' => $iNewDelIndex ,
'APP_STATUS' => 'TO_DO' ,
'TAS_UID' => $currentDelegation [ 'TAS_UID' ],
'ROU_TYPE' => $aDeriveTasks [ 1 ][ 'ROU_TYPE' ],
2012-10-09 12:40:24 -04:00
);
2016-06-14 10:46:34 -04:00
$openThreads = 0 ;
if ( $currentDelegation2 [ 'ROU_TYPE' ] == 'SEC-JOIN' ) {
$openThreads = $this -> case -> GetOpenThreads ( $currentDelegation [ 'APP_UID' ]);
}
if ( $openThreads == 0 ) {
$this -> derivate ( $currentDelegation2 , $nextDelegations2 );
} else {
2020-07-09 17:00:11 -04:00
$subApplication = new SubApplication ();
$subProcessFields [ 'SA_STATUS' ] = 'ACTIVE' ;
$subApplication -> update ( $subProcessFields );
2016-06-14 10:46:34 -04:00
}
2012-10-09 12:40:24 -04:00
}
}
2011-10-24 08:48:59 -04:00
}
2017-07-06 16:36:53 -04:00
}
2016-06-27 12:10:04 -04:00
2016-11-21 16:36:30 -04:00
if ( $iNewDelIndex !== 0 && ! $sendNotificationsMobile ) {
$this -> sendNotificationsMobile ( $appFields , $nextDel , $iNewDelIndex );
}
if ( $iNewDelIndex !== 0 && ! $sendNotifications ) {
$nextTaskData = $taskNextDel -> toArray ( BasePeer :: TYPE_FIELDNAME );
$nextTaskData [ 'USR_UID' ] = $nextDel [ 'USR_UID' ];
$this -> notifyAssignedUser ( $appFields , $nextTaskData , $iNewDelIndex );
2016-06-27 12:10:04 -04:00
}
2012-10-09 12:40:24 -04:00
return $iNewDelIndex ;
}
2011-10-24 08:48:59 -04:00
2020-04-30 16:08:24 -04:00
/**
* Create the sub - process
*
* @ param array $subProcessInfo
* @ param array $appFields
* @ param array $currentDelegation
* @ param int $delIndex
* @ param int $threadIndex
*
2020-07-09 17:00:11 -04:00
* @ return array
2020-04-30 16:08:24 -04:00
*/
protected function subProcessCreation ( array $subProcessInfo , array $appFields , array $currentDelegation , $delIndex , $threadIndex )
{
// Check if is SelfService the task in the SubProcess
2020-05-28 16:16:54 -04:00
$isSelfService = empty ( $subProcessInfo [ 'USR_UID' ]) ? true : false ;
2020-04-30 16:08:24 -04:00
// Create the new case in the sub-process
// Set the initial date to null the time its created
// The DelThreadStatus will create with CLOSED value for avoid to open the case without all the execution
$newCase = $this -> case -> startCase ( $subProcessInfo [ 'TAS_UID' ], $subProcessInfo [ 'USR_UID' ], true , $appFields , $isSelfService );
// Load the TAS_UID related to the SubProcess
2021-09-28 17:56:40 -04:00
$taskNextDel = TaskPeer :: retrieveByPK ( $subProcessInfo [ " TAS_UID " ]);
2020-04-30 16:08:24 -04:00
// Copy case variables to sub-process case
$fields = unserialize ( $subProcessInfo [ 'SP_VARIABLES_OUT' ]);
2021-09-28 17:56:40 -04:00
// Load the information about the new case
$currentFields = $this -> case -> loadCase ( $newCase [ 'APPLICATION' ]);
2020-04-30 16:08:24 -04:00
$newFields = [];
2021-09-28 17:56:40 -04:00
$newFields [ 'INDEX' ] = 1 ;
2020-04-30 16:08:24 -04:00
foreach ( $fields as $originField => $targetField ) {
$originField = trim ( $originField , " @#%? $ =& " );
$targetField = trim ( $targetField , " @#%? $ =& " );
$newFields [ $targetField ] = isset ( $appFields [ 'APP_DATA' ][ $originField ]) ? $appFields [ 'APP_DATA' ][ $originField ] : '' ;
if ( array_key_exists ( $originField . '_label' , $appFields [ 'APP_DATA' ])) {
$newFields [ $targetField . '_label' ] = $appFields [ 'APP_DATA' ][ $originField . '_label' ];
}
}
2021-09-28 17:56:40 -04:00
// We will to update the new case with the variables to define in the sub-process
$currentFields [ 'APP_DATA' ] = array_merge ( $currentFields [ 'APP_DATA' ], $newFields );
$currentFields [ 'DEL_INDEX' ] = 1 ;
$currentFields [ 'APP_STATUS' ] = 'TO_DO' ;
2020-04-30 16:08:24 -04:00
$this -> case -> updateCase (
$newCase [ 'APPLICATION' ],
2021-09-28 17:56:40 -04:00
$currentFields
2020-04-30 16:08:24 -04:00
);
// Create a registry in SUB_APPLICATION table
$attributes = [
'APP_UID' => $newCase [ 'APPLICATION' ],
'APP_PARENT' => $currentDelegation [ 'APP_UID' ],
'DEL_INDEX_PARENT' => $delIndex ,
'DEL_THREAD_PARENT' => $threadIndex ,
'SA_STATUS' => 'ACTIVE' ,
'SA_VALUES_OUT' => serialize ( $newFields ),
'SA_INIT_DATE' => date ( 'Y-m-d H:i:s' )
];
if ( $subProcessInfo [ 'SP_SYNCHRONOUS' ] == 0 ) {
$attributes [ 'SA_STATUS' ] = 'FINISHED' ;
$attributes [ 'SA_FINISH_DATE' ] = $attributes [ 'SA_INIT_DATE' ];
}
$subprocess = ModelSubApplication :: create ( $attributes );
// Update the AppDelegation to execute the update trigger
// Update the DelThreadStatus, the thread is ready for continue
$appDelegation = AppDelegationPeer :: retrieveByPK ( $newCase [ 'APPLICATION' ], $newCase [ 'INDEX' ]);
$appDelegation -> setDelThreadStatus ( 'OPEN' );
2021-07-26 13:13:26 -04:00
$appDelegation -> setDelThreadStatusId ( Delegation :: $thread_status [ 'OPEN' ]);
2020-04-30 16:08:24 -04:00
$appDelegation -> save ();
// Create record in table APP_ASSIGN_SELF_SERVICE_VALUE
$tasGroupVariable = $taskNextDel -> getTasGroupVariable ();
if ( $taskNextDel -> getTasAssignType () == " SELF_SERVICE " && ! empty ( trim ( $tasGroupVariable ))) {
$nextTaskGroupVariable = trim ( $tasGroupVariable , " @# " );
2021-10-04 10:59:17 -04:00
if ( isset ( $currentFields [ " APP_DATA " ][ $nextTaskGroupVariable ])) {
$dataVariable = $currentFields [ " APP_DATA " ][ $nextTaskGroupVariable ];
2020-04-30 16:08:24 -04:00
$dataVariable = ( is_array ( $dataVariable )) ? $dataVariable : trim ( $dataVariable );
if ( ! empty ( $dataVariable )) {
$appAssignSelfServiceValue = new AppAssignSelfServiceValue ();
$appAssignSelfServiceValue -> create (
$newCase [ " APPLICATION " ],
$newCase [ " INDEX " ],
[ " PRO_UID " => $newCase [ " PROCESS " ], " TAS_UID " => $subProcessInfo [ " TAS_UID " ], " GRP_UID " => " " ],
$dataVariable
);
}
}
}
// We will to send the notifications
2021-10-04 10:59:17 -04:00
$sendNotificationsMobile = $this -> sendNotificationsMobile ( $currentFields , $subProcessInfo , $newCase [ 'INDEX' ]);
2020-04-30 16:08:24 -04:00
$nextTaskData = $taskNextDel -> toArray ( BasePeer :: TYPE_FIELDNAME );
$nextTaskData [ 'USR_UID' ] = $subProcessInfo [ 'USR_UID' ];
$sendNotifications = $this -> notifyAssignedUser ( $appFields , $nextTaskData , $newCase [ 'INDEX' ]);
2020-07-09 17:00:11 -04:00
return $attributes ;
2020-04-30 16:08:24 -04:00
}
2017-05-18 09:46:19 -04:00
/**
* This function returns the current user Checking cases where USR_ID exists or checking a subprocess ( SYNCHRONOUS )
* @ param $nextDel
* @ param null $aSP
* @ return string
*/
function verifyCurrentUserInTask ( $nextDel , $aSP = null )
{
if ( isset ( $aSP ) && $aSP [ " SP_SYNCHRONOUS " ] == " 1 " ) {
$currentUser = " " ;
} else {
$currentUser = isset ( $nextDel [ 'USR_UID' ]) ? $nextDel [ 'USR_UID' ] : " " ;
}
return $currentUser ;
}
2017-03-02 16:30:01 -04:00
/**
* This function create , update and closed a new record related to appThread
*
* Related to route type we can change the records in the APP_THREAD table
* @ param string $routeType this variable recibe information about the derivation
* @ return void
*/
function updateAppThread ( $routeType , $appUid , $iAppThreadIndex , $iNewDelIndex ) {
switch ( $routeType ) {
case 'PARALLEL' :
case 'PARALLEL-BY-EVALUATION' :
case 'PARALLEL-AND-EXCLUSIVE' :
$this -> case -> closeAppThread ( $appUid , $iAppThreadIndex );
$iNewThreadIndex = $this -> case -> newAppThread ( $appUid , $iNewDelIndex , $iAppThreadIndex );
$this -> case -> updateAppDelegation ( $appUid , $iNewDelIndex , $iNewThreadIndex );
break ;
default :
$this -> case -> updateAppThread ( $appUid , $iAppThreadIndex , $iNewDelIndex );
break ;
}
}
2017-11-09 16:25:34 -04:00
/**
2017-11-10 09:07:55 -04:00
* Verify if the case is child from another case
2012-10-22 15:45:47 -04:00
*
2017-11-09 16:25:34 -04:00
* @ param string $applicationUid
* @ param int $delIndex
*
* @ return void
2012-10-22 15:45:47 -04:00
*/
2017-11-09 16:25:34 -04:00
function verifyIsCaseChild ( $applicationUid , $delIndex = 0 )
2012-10-09 12:40:24 -04:00
{
//Obtain the related row in the table SUB_APPLICATION
2018-08-08 16:46:55 -04:00
$subApplication = SubApplication :: getSubProcessInfo ( $applicationUid );
if ( ! empty ( $subApplication )) {
2012-10-09 12:40:24 -04:00
//Obtain the related row in the table SUB_PROCESS
2017-11-09 16:25:34 -04:00
$case = new Cases ();
$parentCase = $case -> loadCase ( $subApplication [ 'APP_PARENT' ], $subApplication [ 'DEL_INDEX_PARENT' ]);
2018-08-08 16:46:55 -04:00
$subProcessParent = SubProcess :: getSubProcessConfiguration ( $parentCase [ 'PRO_UID' ], $parentCase [ 'TAS_UID' ]);
if ( $subProcessParent [ 'SP_SYNCHRONOUS' ] == 1 || $subApplication [ 'SA_STATUS' ] == 'ACTIVE' ) {
2017-11-09 16:25:34 -04:00
$appFields = $case -> loadCase ( $applicationUid , $delIndex );
2012-10-09 12:40:24 -04:00
//Copy case variables to parent case
2018-08-08 16:46:55 -04:00
$fields = unserialize ( $subProcessParent [ 'SP_VARIABLES_IN' ]);
$newFields = $this -> getSubProcessVariables ( $fields , $appFields [ 'APP_DATA' ], $parentCase [ 'APP_DATA' ]);
2017-11-09 16:25:34 -04:00
$parentCase [ 'APP_DATA' ] = array_merge ( $parentCase [ 'APP_DATA' ], $newFields );
$case -> updateCase ( $subApplication [ 'APP_PARENT' ], $parentCase );
2015-02-27 16:27:11 -04:00
$inbox = new ListInbox ();
2017-11-09 16:25:34 -04:00
$inbox -> update ( $parentCase );
2015-06-25 15:59:34 -04:00
2012-10-09 12:40:24 -04:00
//Update table SUB_APPLICATION
2017-11-09 16:25:34 -04:00
$newSubApplication = new SubApplication ();
$newSubApplication -> update ([
'APP_UID' => $applicationUid ,
'APP_PARENT' => $subApplication [ 'APP_PARENT' ],
'DEL_INDEX_PARENT' => $subApplication [ 'DEL_INDEX_PARENT' ],
'DEL_THREAD_PARENT' => $subApplication [ 'DEL_THREAD_PARENT' ],
'SA_STATUS' => 'FINISHED' , 'SA_VALUES_IN' => serialize ( $newFields ),
'SA_FINISH_DATE' => date ( 'Y-m-d H:i:s' )
]);
2015-06-25 15:59:34 -04:00
2012-10-09 12:40:24 -04:00
//Derive the parent case
2017-11-09 16:25:34 -04:00
$deriveTasks = $this -> prepareInformation ([
'USER_UID' => - 1 ,
'APP_UID' => $subApplication [ 'APP_PARENT' ],
'DEL_INDEX' => $subApplication [ 'DEL_INDEX_PARENT' ]
]);
if ( isset ( $deriveTasks [ 1 ])) {
if ( $deriveTasks [ 1 ][ 'ROU_TYPE' ] !== 'SELECT' ) {
$nextDelegations2 = [];
foreach ( $deriveTasks as $deriveTask ) {
if ( ! isset ( $deriveTask [ 'NEXT_TASK' ][ 'USER_ASSIGNED' ][ 'USR_UID' ])) {
$selectedUser = $deriveTask [ 'NEXT_TASK' ][ 'USER_ASSIGNED' ][ 0 ];
unset ( $deriveTask [ 'NEXT_TASK' ][ 'USER_ASSIGNED' ]);
$deriveTask [ 'NEXT_TASK' ][ 'USER_ASSIGNED' ] = $selectedUser ;
$myLabels = [
$deriveTask [ 'NEXT_TASK' ][ 'TAS_TITLE' ],
$parentCase [ 'APP_NUMBER' ],
$selectedUser [ 'USR_USERNAME' ],
$selectedUser [ 'USR_FIRSTNAME' ],
$selectedUser [ 'USR_LASTNAME' ]
];
if ( $deriveTask [ 'NEXT_TASK' ][ 'TAS_ASSIGN_TYPE' ] === 'MANUAL' ) {
2016-06-14 10:46:34 -04:00
G :: SendTemporalMessage ( 'ID_TASK_WAS_ASSIGNED_TO_USER' , 'warning' , 'labels' , 10 , null , $myLabels );
2015-12-21 12:40:13 -04:00
}
2012-10-09 12:40:24 -04:00
}
2017-11-09 16:25:34 -04:00
$nextDelegations2 [] = [
'TAS_UID' => $deriveTask [ 'NEXT_TASK' ][ 'TAS_UID' ],
'USR_UID' => $deriveTask [ 'NEXT_TASK' ][ 'USER_ASSIGNED' ][ 'USR_UID' ],
'TAS_ASSIGN_TYPE' => $deriveTask [ 'NEXT_TASK' ][ 'TAS_ASSIGN_TYPE' ],
'TAS_DEF_PROC_CODE' => $deriveTask [ 'NEXT_TASK' ][ 'TAS_DEF_PROC_CODE' ],
2017-03-29 11:09:06 -04:00
'DEL_PRIORITY' => 3 ,
2017-11-09 16:25:34 -04:00
'TAS_PARENT' => $deriveTask [ 'NEXT_TASK' ][ 'TAS_PARENT' ],
'ROU_PREVIOUS_TASK' => isset ( $deriveTask [ 'NEXT_TASK' ][ 'ROU_PREVIOUS_TASK' ]) ? $deriveTask [ 'NEXT_TASK' ][ 'ROU_PREVIOUS_TASK' ] : '' ,
'ROU_PREVIOUS_TYPE' => isset ( $deriveTask [ 'NEXT_TASK' ][ 'ROU_PREVIOUS_TYPE' ]) ? $deriveTask [ 'NEXT_TASK' ][ 'ROU_PREVIOUS_TYPE' ] : ''
];
2012-10-09 12:40:24 -04:00
}
2017-11-09 16:25:34 -04:00
$currentDelegation2 = [
'APP_UID' => $subApplication [ 'APP_PARENT' ],
'DEL_INDEX' => $subApplication [ 'DEL_INDEX_PARENT' ],
'APP_STATUS' => 'TO_DO' ,
'TAS_UID' => $parentCase [ 'TAS_UID' ],
'ROU_TYPE' => $deriveTasks [ 1 ][ 'ROU_TYPE' ]
];
2017-11-09 15:49:37 -04:00
$g = new G ();
$g -> sessionVarSave ();
2017-11-09 16:25:34 -04:00
$_SESSION [ 'PROCESS' ] = $parentCase [ 'PRO_UID' ];
2016-06-14 10:46:34 -04:00
$this -> derivate ( $currentDelegation2 , $nextDelegations2 );
2017-11-09 15:49:37 -04:00
$g -> sessionVarRestore ();
2014-07-03 12:42:37 -04:00
2016-06-14 10:46:34 -04:00
if ( $delIndex > 0 ) {
2016-07-04 10:34:02 -04:00
$flagNotification = false ;
2017-11-09 16:25:34 -04:00
if ( $appFields [ 'CURRENT_USER_UID' ] == '' ) {
$criteriaTaskDummy = new Criteria ( 'workflow' );
$criteriaTaskDummy -> add ( TaskPeer :: PRO_UID , $appFields [ 'PRO_UID' ]);
$criteriaTaskDummy -> add ( TaskPeer :: TAS_UID , $appFields [ 'TAS_UID' ]);
$criteriaTaskDummy -> add (
$criteriaTaskDummy -> getNewCriterion ( TaskPeer :: TAS_TYPE , 'SCRIPT-TASK' , Criteria :: EQUAL ) -> addOr (
$criteriaTaskDummy -> getNewCriterion ( TaskPeer :: TAS_TYPE , 'INTERMEDIATE-THROW-EMAIL-EVENT' , Criteria :: EQUAL ))
2016-07-04 10:34:02 -04:00
);
2017-11-09 16:25:34 -04:00
$criteriaTaskDummy -> setLimit ( 1 );
$dataSet = AppDelegationPeer :: doSelectRS ( $criteriaTaskDummy );
$dataSet -> setFetchmode ( \ResultSet :: FETCHMODE_ASSOC );
$dataSet -> next ();
if ( $row = $dataSet -> getRow ()) {
2016-07-04 10:34:02 -04:00
$flagNotification = true ;
}
}
if ( ! $flagNotification ) {
// Send notifications - Start
2017-11-09 16:25:34 -04:00
$user = new Users ();
$informationUser = $user -> load ( $appFields [ 'CURRENT_USER_UID' ]);
2016-07-04 10:34:02 -04:00
2017-11-09 16:25:34 -04:00
$sFromName = $informationUser [ 'USR_FIRSTNAME' ] . ' ' . $informationUser [ 'USR_LASTNAME' ] . ( $informationUser [ 'USR_EMAIL' ] != '' ? ' <' . $informationUser [ 'USR_EMAIL' ] . '>' : '' );
2016-07-04 10:34:02 -04:00
try {
2017-11-09 16:25:34 -04:00
$case -> sendNotifications (
$appFields [ 'TAS_UID' ],
2016-07-04 10:34:02 -04:00
$nextDelegations2 ,
2017-11-09 16:25:34 -04:00
$appFields [ 'APP_DATA' ],
$applicationUid ,
2016-07-04 10:34:02 -04:00
$delIndex ,
$sFromName );
} catch ( Exception $e ) {
2017-11-09 16:25:34 -04:00
G :: SendTemporalMessage ( G :: loadTranslation ( 'ID_NOTIFICATION_ERROR' ) . ' - ' . $e -> getMessage (), 'warning' , 'string' , null , '100%' );
2016-07-04 10:34:02 -04:00
}
// Send notifications - End
2014-07-03 15:42:28 -04:00
}
2014-07-03 12:42:37 -04:00
}
2012-10-09 12:40:24 -04:00
}
}
2010-12-02 23:34:41 +00:00
}
}
}
2018-08-08 16:46:55 -04:00
/**
* Will be get sub process variables
* Get variables - in and variables - out
*
* @ param array $fields
* @ param array $childCaseData
* @ param array $parentCaseData
*
* @ return array
*/
public function getSubProcessVariables ( $fields , $childCaseData , $parentCaseData )
{
$newFields = [];
foreach ( $fields as $originField => $targetField ) {
$originField = str_replace ( '@' , '' , $originField );
$originField = str_replace ( '#' , '' , $originField );
$originField = str_replace ( '%' , '' , $originField );
$originField = str_replace ( '?' , '' , $originField );
$originField = str_replace ( '$' , '' , $originField );
$originField = str_replace ( '=' , '' , $originField );
2019-11-05 11:32:47 -04:00
$originField = str_replace ( '&' , '' , $originField );
2018-08-08 16:46:55 -04:00
$targetField = str_replace ( '@' , '' , $targetField );
$targetField = str_replace ( '#' , '' , $targetField );
$targetField = str_replace ( '%' , '' , $targetField );
$targetField = str_replace ( '?' , '' , $targetField );
$targetField = str_replace ( '$' , '' , $targetField );
$targetField = str_replace ( '=' , '' , $targetField );
2019-11-05 11:32:47 -04:00
$targetField = str_replace ( '&' , '' , $targetField );
2018-08-08 16:46:55 -04:00
$newFields [ $targetField ] = isset ( $childCaseData [ $originField ]) ? $childCaseData [ $originField ] : '' ;
if ( array_key_exists ( $originField . '_label' , $childCaseData )) {
$newFields [ $targetField . '_label' ] = $childCaseData [ $originField . '_label' ];
} elseif ( array_key_exists ( $targetField . '_label' , $parentCaseData )) {
$newFields [ $targetField . '_label' ] = '' ;
}
}
return $newFields ;
}
/** getDerivatedCases
2012-10-22 15:45:47 -04:00
* get all derivated cases and subcases from any task ,
* this function is useful to know who users have been assigned and what task they do .
*
* @ param string $sParentUid
* @ param string $sDelIndexParent
* @ return array $derivation
*
*/
2012-10-09 12:40:24 -04:00
function getDerivatedCases ( $sParentUid , $sDelIndexParent )
{
$oCriteria = new Criteria ( 'workflow' );
$cases = array ();
$derivation = array ();
//get the child delegations , of parent delIndex
$children = array ();
$oCriteria -> clearSelectColumns ();
$oCriteria -> addSelectColumn ( AppDelegationPeer :: DEL_INDEX );
$oCriteria -> add ( AppDelegationPeer :: APP_UID , $sParentUid );
$oCriteria -> add ( AppDelegationPeer :: DEL_PREVIOUS , $sDelIndexParent );
$oDataset = AppDelegationPeer :: doSelectRS ( $oCriteria );
$oDataset -> setFetchmode ( ResultSet :: FETCHMODE_ASSOC );
2010-12-02 23:34:41 +00:00
$oDataset -> next ();
$aRow = $oDataset -> getRow ();
2012-10-09 12:40:24 -04:00
while ( is_array ( $aRow )) {
$children [] = $aRow [ 'DEL_INDEX' ];
$oDataset -> next ();
$aRow = $oDataset -> getRow ();
}
//foreach child , get the info of their derivations and subprocesses
foreach ( $children as $keyChild => $child ) {
$oCriteria = new Criteria ( 'workflow' );
$oCriteria -> clearSelectColumns ();
$oCriteria -> addSelectColumn ( SubApplicationPeer :: APP_UID );
$oCriteria -> addSelectColumn ( AppDelegationPeer :: APP_UID );
$oCriteria -> addSelectColumn ( AppDelegationPeer :: DEL_INDEX );
$oCriteria -> addSelectColumn ( AppDelegationPeer :: PRO_UID );
$oCriteria -> addSelectColumn ( AppDelegationPeer :: TAS_UID );
$oCriteria -> addSelectColumn ( AppDelegationPeer :: USR_UID );
$oCriteria -> addSelectColumn ( UsersPeer :: USR_USERNAME );
$oCriteria -> addSelectColumn ( UsersPeer :: USR_FIRSTNAME );
$oCriteria -> addSelectColumn ( UsersPeer :: USR_LASTNAME );
$oCriteria -> add ( SubApplicationPeer :: APP_PARENT , $sParentUid );
$oCriteria -> add ( SubApplicationPeer :: DEL_INDEX_PARENT , $child );
$oCriteria -> addJoin ( SubApplicationPeer :: APP_UID , AppDelegationPeer :: APP_UID );
$oCriteria -> addJoin ( AppDelegationPeer :: USR_UID , UsersPeer :: USR_UID );
$oDataset = SubApplicationPeer :: doSelectRS ( $oCriteria );
$oDataset -> setFetchmode ( ResultSet :: FETCHMODE_ASSOC );
$oDataset -> next ();
$aRow = $oDataset -> getRow ();
while ( is_array ( $aRow )) {
$oProcess = new Process ();
$proFields = $oProcess -> load ( $aRow [ 'PRO_UID' ] );
$oCase = new Application ();
$appFields = $oCase -> load ( $aRow [ 'APP_UID' ] );
$oTask = new Task ();
$tasFields = $oTask -> load ( $aRow [ 'TAS_UID' ] );
$derivation [] = array ( 'processId' => $aRow [ 'PRO_UID' ], 'processTitle' => $proFields [ 'PRO_TITLE' ], 'caseId' => $aRow [ 'APP_UID' ], 'caseNumber' => $appFields [ 'APP_NUMBER' ], 'taskId' => $aRow [ 'TAS_UID' ], 'taskTitle' => $tasFields [ 'TAS_TITLE' ], 'userId' => $aRow [ 'USR_UID' ], 'userName' => $aRow [ 'USR_USERNAME' ], 'userFullname' => $aRow [ 'USR_FIRSTNAME' ] . ' ' . $aRow [ 'USR_LASTNAME' ]
);
2010-12-02 23:34:41 +00:00
2012-10-09 12:40:24 -04:00
$oDataset -> next ();
$aRow = $oDataset -> getRow ();
}
}
return $derivation ;
}
2010-12-02 23:34:41 +00:00
2012-10-09 12:40:24 -04:00
function getGrpUser ( $aData )
{
$oTasks = new Tasks ();
$oGroups = new Groups ();
$oContent = new Content ();
$aGroup = array ();
$aUsers = array ();
$aGroup = $oTasks -> getGroupsOfTask ( $aData [ 'ROU_NEXT_TASK' ], 1 );
$aGrpUid = $aGroup [ 0 ][ 'GRP_UID' ];
$sGrpName = $oContent -> load ( 'GRP_TITLE' , '' , $aGrpUid , 'en' );
$aGrp [ 'GRP_NAME' ] = $sGrpName ;
$aGrp [ 'GRP_UID' ] = $aGrpUid ;
$aUsers = $oGroups -> getUsersOfGroup ( $aGroup [ 0 ][ 'GRP_UID' ] );
foreach ( $aUsers as $aKey => $userid ) {
2010-12-02 23:34:41 +00:00
$aData [ $aKey ] = $userid ;
2012-10-09 12:40:24 -04:00
}
return $aGrp ;
}
2018-05-10 12:17:34 -04:00
/**
* Review the replaced by configuration
*
* @ param string $user
*
* @ return string
* @ throws Exception
*/
function checkReplacedByUser ( $user )
2012-10-09 12:40:24 -04:00
{
2018-05-10 12:17:34 -04:00
if ( is_string ( $user )) {
$userInstance = UsersPeer :: retrieveByPK ( $user );
2012-10-09 12:40:24 -04:00
} else {
$userInstance = $user ;
}
2018-05-11 12:40:50 -04:00
if ( ! is_object ( $userInstance )) {
if ( ! is_string ( $user )) {
$user = gettype ( $user );
}
throw new Exception ( " The user with the UID ' " . $user . " ' doesn't exist. " );
2012-10-09 12:40:24 -04:00
}
if ( $userInstance -> getUsrStatus () == 'ACTIVE' ) {
return $userInstance -> getUsrUid ();
} else {
2018-05-10 12:17:34 -04:00
$userReplace = trim ( $userInstance -> getUsrReplacedBy ());
2012-10-09 12:40:24 -04:00
if ( $userReplace != '' ) {
2018-05-10 12:17:34 -04:00
return $this -> checkReplacedByUser ( UsersPeer :: retrieveByPK ( $userReplace ));
2012-10-09 12:40:24 -04:00
} else {
return '' ;
}
}
}
2016-06-27 12:10:04 -04:00
/**
* @ param $appFields
* @ param $nextDel
* @ param $iNewDelIndex
* @ return bool
*/
private function sendNotificationsMobile ( $appFields , $nextDel , $iNewDelIndex )
{
try {
$notificationMobile = new \ProcessMaker\BusinessModel\Light\NotificationDevice ();
if ( $notificationMobile -> checkMobileNotifications ()) {
$notificationMobile -> routeCaseNotificationDevice ( $appFields , $nextDel , $iNewDelIndex );
}
return true ;
} catch ( Exception $e ) {
\G :: log ( G :: loadTranslation ( 'ID_NOTIFICATION_ERROR' ) . '|' . $e -> getMessage (), PATH_DATA , " mobile.log " );
}
}
2016-11-21 16:36:30 -04:00
/**
* @ param $appFields
* @ param $nextDel
* @ param $iNewDelIndex
* @ return bool
*/
public function notifyAssignedUser ( $appFields , $nextDel , $iNewDelIndex )
{
try {
if ( $nextDel [ 'TAS_RECEIVE_LAST_EMAIL' ] == 'TRUE' ) {
2020-08-10 17:11:55 -04:00
$taskData = [];
2016-11-21 16:36:30 -04:00
$userLogged = $this -> userLogged -> load ( $appFields [ 'APP_DATA' ][ 'USER_LOGGED' ]);
$fromName = $userLogged [ 'USR_FIRSTNAME' ] . ' ' . $userLogged [ 'USR_LASTNAME' ];
$sFromData = $fromName . ( $userLogged [ 'USR_EMAIL' ] != '' ? ' <' . $userLogged [ 'USR_EMAIL' ] . '>' : '' );
$dataEmail = $this -> case -> loadDataSendEmail ( $nextDel , $appFields [ 'APP_DATA' ], $sFromData , 'RECEIVE' );
$dataEmail [ 'applicationUid' ] = $appFields [ 'APP_UID' ];
$dataEmail [ 'delIndex' ] = $iNewDelIndex ;
array_push ( $taskData , $nextDel );
2017-10-30 14:32:32 -04:00
//Load the TAS_ID
if ( isset ( $nextDel [ 'TAS_ID' ])) {
$appFields [ 'APP_DATA' ][ 'TAS_ID' ] = $nextDel [ 'TAS_ID' ];
}
2018-04-04 09:21:59 -04:00
//Load the PRO_ID
if ( isset ( $nextDel [ 'PRO_ID' ])) {
$appFields [ 'APP_DATA' ][ 'PRO_ID' ] = $nextDel [ 'PRO_ID' ];
}
2016-11-21 16:36:30 -04:00
$this -> case -> sendMessage ( $dataEmail , $appFields [ 'APP_DATA' ], $taskData );
}
return true ;
} catch ( Exception $e ) {
\G :: log ( G :: loadTranslation ( 'ID_NOTIFICATION_ERROR' ) . '|' . $e -> getMessage ());
}
}
2017-07-06 16:36:53 -04:00
2017-07-06 11:36:40 -04:00
/**
* @ param array $currentDelegation
* @ param array $nextDel
* @ param array $appFields
* @ param boolean $flagFirstIteration
* @ param boolean $flagTaskAssignTypeIsMultipleInstance
2020-08-10 17:11:55 -04:00
* @ param array $context
2017-07-06 11:36:40 -04:00
* @ return void
*/
2020-08-10 17:11:55 -04:00
public function finishTask ( $currentDelegation , $nextDel , $appFields , $flagFirstIteration = true , $flagTaskAssignTypeIsMultipleInstance = false , $context = []) {
2017-07-06 11:36:40 -04:00
$iAppThreadIndex = $appFields [ 'DEL_THREAD' ];
$this -> case -> closeAppThread ( $currentDelegation [ 'APP_UID' ], $iAppThreadIndex );
if ( isset ( $nextDel [ " TAS_UID_DUMMY " ])) {
$criteria = new Criteria ( " workflow " );
$criteria -> addSelectColumn ( RoutePeer :: TAS_UID );
$criteria -> addJoin ( RoutePeer :: TAS_UID , AppDelegationPeer :: TAS_UID );
$criteria -> add ( RoutePeer :: PRO_UID , $appFields [ 'PRO_UID' ]);
$criteria -> add ( RoutePeer :: ROU_NEXT_TASK , isset ( $nextDel [ 'ROU_PREVIOUS_TASK' ]) ? $nextDel [ 'ROU_PREVIOUS_TASK' ] : '' );
$criteria -> add ( RoutePeer :: ROU_TYPE , isset ( $nextDel [ 'ROU_PREVIOUS_TYPE' ]) ? $nextDel [ 'ROU_PREVIOUS_TYPE' ] : '' );
$criteria -> add ( AppDelegationPeer :: DEL_THREAD_STATUS , 'OPEN' );
$rsCriteria = RoutePeer :: doSelectRS ( $criteria );
$rsCriteria -> setFetchmode ( ResultSet :: FETCHMODE_ASSOC );
$executeEvent = ( $rsCriteria -> next ()) ? false : true ;
$multiInstanceCompleted = true ;
if ( $flagTaskAssignTypeIsMultipleInstance ) {
$multiInstanceCompleted = $this -> case -> multiInstanceIsCompleted (
$appFields [ 'APP_UID' ],
$appFields [ 'TAS_UID' ],
$appFields [ 'DEL_PREVIOUS' ]);
}
$taskDummy = TaskPeer :: retrieveByPK ( $nextDel [ " TAS_UID_DUMMY " ]);
if ( preg_match ( " /^(?:END-MESSAGE-EVENT|END-EMAIL-EVENT) $ / " , $taskDummy -> getTasType ())
&& $multiInstanceCompleted && $executeEvent
) {
2019-03-29 10:00:39 -04:00
$nextDel [ " TAS_ID " ] = $taskDummy -> getTasId ();
$this -> executeEvent (
$nextDel [ " TAS_UID_DUMMY " ],
$appFields ,
$flagFirstIteration ,
true ,
'' ,
! empty ( $nextDel [ " TAS_ID " ]) ? $nextDel [ " TAS_ID " ] : 0
);
2017-07-06 11:36:40 -04:00
}
}
2020-08-10 17:11:55 -04:00
$context [ 'action' ] = 'finish-task' ;
2017-07-06 11:36:40 -04:00
//Logger
2020-08-10 17:11:55 -04:00
$message = 'Case Derivation' ;
Log :: channel ( ':CaseDerivation' ) -> info ( $message , Bootstrap :: context ( $context ));
2017-07-06 11:36:40 -04:00
}
2017-07-06 16:36:53 -04:00
/**
* Finish the process
* Close the threads and update the status to COMPLETED
* @ param array $currentDelegation
* @ param array $nextDel
* @ param array $appFields
* @ param boolean $flagFirstIteration
2020-08-10 17:11:55 -04:00
* @ param array $context
2017-07-06 16:36:53 -04:00
* @ return void
*/
2020-08-10 17:11:55 -04:00
public function finishProcess ( $currentDelegation , $nextDel , $appFields , $flagFirstIteration = true , $context = []){
2017-07-06 16:36:53 -04:00
/*Close all delegations of $currentDelegation['APP_UID'] */
$this -> case -> closeAllDelegations ( $currentDelegation [ 'APP_UID' ] );
$this -> case -> closeAllThreads ( $currentDelegation [ 'APP_UID' ] );
//I think we need to change the APP_STATUS to completed,
if ( ! isset ( $nextDel [ 'ROU_CONDITION' ])) {
$nextDel [ 'ROU_CONDITION' ] = '' ;
}
//Execute the Intermediate Event After the End of Process
2019-03-29 10:00:39 -04:00
$this -> executeEvent (
$nextDel [ " TAS_UID " ],
$appFields ,
true ,
true ,
'' ,
! empty ( $nextDel [ " TAS_ID " ]) ? $nextDel [ " TAS_ID " ] : 0
);
2017-07-06 16:36:53 -04:00
if ( isset ( $nextDel [ " TAS_UID_DUMMY " ]) ) {
$taskDummy = TaskPeer :: retrieveByPK ( $nextDel [ " TAS_UID_DUMMY " ]);
if ( preg_match ( " /^(?:END-MESSAGE-EVENT|END-EMAIL-EVENT) $ / " , $taskDummy -> getTasType ())) {
2019-03-29 10:00:39 -04:00
$nextDel [ " TAS_ID " ] = $taskDummy -> getTasId ();
2017-07-06 16:36:53 -04:00
//Throw Events
2019-03-29 10:00:39 -04:00
$this -> executeEvent (
$nextDel [ " TAS_UID_DUMMY " ],
$appFields ,
$flagFirstIteration ,
true ,
'' ,
! empty ( $nextDel [ " TAS_ID " ]) ? $nextDel [ " TAS_ID " ] : 0
);
2017-07-06 16:36:53 -04:00
}
}
2020-08-10 17:11:55 -04:00
$context [ 'action' ] = 'end-process' ;
2017-07-06 16:36:53 -04:00
//Logger
2020-08-10 17:11:55 -04:00
$message = 'Case Derivation' ;
Log :: channel ( ':CaseDerivation' ) -> info ( $message , Bootstrap :: context ( $context ));
2017-07-06 16:36:53 -04:00
}
/**
* Get the next route information when is a subProcess
* This function changes the following important variables :
* $aSP ( array ) with the subProcess information
* $newNextDel ( array ) the next delegation related to the subProcess
* @ param array $nextDel
* @ param array $proUid
* @ return array $newNextDel
*/
public function getNextInfoSubProcess ( $nextDel , $proUid )
{
2020-08-10 17:11:55 -04:00
$newNextDel = [];
2017-07-06 16:36:53 -04:00
$oCriteria = new Criteria ( 'workflow' );
$oCriteria -> add ( SubProcessPeer :: PRO_PARENT , $proUid );
$oCriteria -> add ( SubProcessPeer :: TAS_PARENT , $nextDel [ 'TAS_PARENT' ]);
$oDataset = SubProcessPeer :: doSelectRS ( $oCriteria );
$oDataset -> setFetchmode ( ResultSet :: FETCHMODE_ASSOC );
$oDataset -> next ();
$aSP = $oDataset -> getRow ();
if ( is_array ( $aSP )) {
$this -> aSP = $aSP ;
$oTask = new Task ();
$aTaskNext = $oTask -> load ( $nextDel [ 'TAS_UID' ]);
//When is MULTIPLE_INSTANCE catch the first user
if ( $aTaskNext [ " TAS_ASSIGN_TYPE " ] == " MULTIPLE_INSTANCE " ){
$spUserUid = $this -> getAllUsersFromAnyTask ( $nextDel [ " TAS_UID " ]);
foreach ( $spUserUid as $row ){
$firstUserUid = $row ;
continue ;
}
$this -> aSP [ 'USR_UID' ] = $firstUserUid ;
} else {
$this -> aSP [ 'USR_UID' ] = $nextDel [ 'USR_UID' ];
}
$aTask = $oTask -> load ( $nextDel [ 'TAS_PARENT' ]);
$newNextDel = array (
'TAS_UID' => $aTask [ 'TAS_UID' ],
'USR_UID' => $this -> aSP [ 'USR_UID' ],
'TAS_ASSIGN_TYPE' => $aTask [ 'TAS_ASSIGN_TYPE' ],
'TAS_DEF_PROC_CODE' => $aTask [ 'TAS_DEF_PROC_CODE' ],
'DEL_PRIORITY' => 3 ,
'TAS_PARENT' => '' ,
'ROU_PREVIOUS_TYPE' => isset ( $nextDel [ 'ROU_PREVIOUS_TYPE' ]) ? $nextDel [ 'ROU_PREVIOUS_TYPE' ] : '' ,
'ROU_PREVIOUS_TASK' => isset ( $nextDel [ 'ROU_PREVIOUS_TASK' ]) ? $nextDel [ 'ROU_PREVIOUS_TASK' ] : ''
);
}
return $newNextDel ;
}
/**
* @ deprecated
* Review if can route a case with the assign task STATIC_MI
* @ param array $currentDelegation
* @ return boolean $canRoute
*/
public function canRouteTasAssignStaticMi ( $currentDelegation ){
$arrayOpenThread = $this -> case -> GetAllOpenDelegation ( $currentDelegation );
$aData = $this -> case -> loadCase ( $currentDelegation [ 'APP_UID' ] );
if ( isset ( $aData [ 'APP_DATA' ][ str_replace ( '@@' , '' , $currentDelegation [ 'TAS_MI_INSTANCE_VARIABLE' ] )] )) {
$sMIinstanceVar = $aData [ 'APP_DATA' ][ str_replace ( '@@' , '' , $currentDelegation [ 'TAS_MI_INSTANCE_VARIABLE' ] )];
} else {
$sMIinstanceVar = $aData [ 'APP_DATA' ][ 'TAS_MI_INSTANCE_VARIABLE' ];
}
if ( isset ( $aData [ 'APP_DATA' ][ str_replace ( '@@' , '' , $currentDelegation [ 'TAS_MI_COMPLETE_VARIABLE' ] )] )) {
$sMIcompleteVar = $aData [ 'APP_DATA' ][ str_replace ( '@@' , '' , $currentDelegation [ 'TAS_MI_COMPLETE_VARIABLE' ] )];
} else {
$sMIcompleteVar = $aData [ 'APP_DATA' ][ 'TAS_MI_COMPLETE_VARIABLE' ];
}
$discriminateThread = $sMIinstanceVar - $sMIcompleteVar ;
// -1 because One App Delegation is closed by above Code
if ( $discriminateThread == count ( $arrayOpenThread )) {
$canRoute = true ;
} else {
$canRoute = false ;
}
return $canRoute ;
}
/**
* Review if can route a case with Join we will check if review the siblings are open
* @ param boolean $flagMultipleInstance
* @ param boolean $flagTypeMultipleInstance
* @ param array $currentDelegation
* @ param array $appFields
* @ param array $nextDel
* @ return boolean $canRoute
*/
public function canRouteTypeSecJoin ( $flagMultipleInstance , $flagTypeMultipleInstance , $currentDelegation , $appFields , $nextDel )
{
2020-08-10 17:11:55 -04:00
$arrayOpenThread = ( $flagMultipleInstance && $flagTypeMultipleInstance ) ? $this -> case -> searchOpenPreviousTasks ( $currentDelegation [ " TAS_UID " ], $currentDelegation [ " APP_UID " ]) : [];
2017-07-06 16:36:53 -04:00
if (
$flagMultipleInstance
&& $flagTypeMultipleInstance
&& isset ( $nextDel [ " ROU_PREVIOUS_TYPE " ])
&& $nextDel [ " ROU_PREVIOUS_TYPE " ] == 'SEC-JOIN'
) {
$appDelegation = new AppDelegation ();
$arraySiblings = $appDelegation -> getAllTasksBeforeSecJoin (
$nextDel [ " ROU_PREVIOUS_TASK " ],
$currentDelegation [ " APP_UID " ],
$appFields [ 'DEL_PREVIOUS' ],
'OPEN'
);
} else {
$arraySiblings = $this -> case -> getOpenSiblingThreads (
$nextDel [ " TAS_UID " ],
$currentDelegation [ " APP_UID " ],
$currentDelegation [ " DEL_INDEX " ],
$currentDelegation [ " TAS_UID " ]
);
}
$this -> arraySiblings = $arraySiblings ;
if ( is_array ( $arrayOpenThread ) && is_array ( $arraySiblings )){
$arrayOpenThread = array_merge ( $arrayOpenThread , $arraySiblings );
}
$canRoute = empty ( $arrayOpenThread );
if ( $canRoute ){
if ( $flagMultipleInstance && $flagTypeMultipleInstance ){
$this -> flagControlMulInstance = true ;
} else {
$this -> flagControl = true ;
}
}
return $canRoute ;
}
/**
* Route a case with Multiple Instance
* This function changes the following important variables :
* flagUpdateList ( boolean ) if we will update the list tables
* removeList ( boolean ) if will be remove the row in the list tables
* iNewDelIndex ( integer ) new index created in the table appDelegation
* $arrayDerivationResult ( array ) information related to the new index created in the table appDelegation
* @ param array $currentDelegation
* @ param array $nextDel
* @ param string $taskNextDel
* @ param array $appFields
* @ param array $aSP
* @ param boolean $removeList
* @ return array $arrayDerivationResult
* @ throws \Exception
*/
public function routeMultipleInstance ( $currentDelegation , $nextDel , $taskNextDel , $appFields , $aSP , $removeList )
{
$arrayDerivationResult = [];
$arrayUser = $this -> getNextAssignedUser (
array (
" APP_UID " => $currentDelegation [ " APP_UID " ],
" NEXT_TASK " => $taskNextDel -> toArray ( BasePeer :: TYPE_FIELDNAME )
)
);
if ( empty ( $arrayUser )) {
throw new Exception ( G :: LoadTranslation ( " ID_NO_USERS " ));
}
foreach ( $arrayUser as $value2 ) {
$currentDelegationAux = array_merge ( $currentDelegation , array ( " ROU_TYPE " => " PARALLEL " ));
$nextDelAux = array_merge ( $nextDel , array ( " USR_UID " => $value2 [ " USR_UID " ]));
$iNewDelIndex = $this -> doDerivation ( $currentDelegationAux , $nextDelAux , $appFields , $aSP );
$this -> updateList ( $currentDelegationAux , $nextDelAux , $taskNextDel , $appFields , $iNewDelIndex , $aSP , $removeList );
$this -> iNewDelIndex = $iNewDelIndex ;
$this -> flagUpdateList = false ;
$this -> removeList = false ;
$arrayDerivationResult [] = [
'DEL_INDEX' => $iNewDelIndex ,
'TAS_UID' => $nextDelAux [ 'TAS_UID' ],
'USR_UID' => ( isset ( $nextDelAux [ 'USR_UID' ])) ? $nextDelAux [ 'USR_UID' ] : ''
];
}
return $arrayDerivationResult ;
}
/**
* When we route a case we will to create a record in the table APP_ASSIGN_SELF_SERVICE_VALUE if the task is SELF_SERVICE
2018-07-31 08:45:54 -04:00
*
2017-07-06 16:36:53 -04:00
* @ param object $taskNextDel
* @ param integer $iNewDelIndex
* @ param string $nextTasUid
* @ param array $appFields
2018-07-31 08:45:54 -04:00
* @ param integer $nextTasId
*
2017-07-06 16:36:53 -04:00
* @ return void
*/
2018-07-31 08:45:54 -04:00
public function createRecordAppSelfServiceValue ( $taskNextDel , $iNewDelIndex , $nextTasUid , $appFields , $nextTasId = 0 )
2017-07-06 16:36:53 -04:00
{
if ( $taskNextDel -> getTasAssignType () == " SELF_SERVICE " && trim ( $taskNextDel -> getTasGroupVariable ()) != " " ) {
$nextTaskGroupVariable = trim ( $taskNextDel -> getTasGroupVariable (), " @# " );
if ( isset ( $appFields [ " APP_DATA " ][ $nextTaskGroupVariable ])) {
$dataVariable = $appFields [ " APP_DATA " ][ $nextTaskGroupVariable ];
$dataVariable = ( is_array ( $dataVariable )) ? $dataVariable : trim ( $dataVariable );
if ( ! empty ( $dataVariable )) {
$appAssignSelfServiceValue = new AppAssignSelfServiceValue ();
$appAssignSelfServiceValue -> create (
$appFields [ " APP_UID " ],
$iNewDelIndex ,
2018-07-31 08:45:54 -04:00
[
2017-07-06 16:36:53 -04:00
" PRO_UID " => $appFields [ " PRO_UID " ],
" TAS_UID " => $nextTasUid ,
2018-07-31 08:45:54 -04:00
" GRP_UID " => " " ,
" APP_NUMBER " => ! empty ( $appFields [ " APP_NUMBER " ]) ? $appFields [ " APP_NUMBER " ] : 0 ,
" TAS_ID " => $nextTasId
],
2017-07-06 16:36:53 -04:00
$dataVariable
);
}
}
}
}
/**
* When we route a case we will to get the information about the next task
* This function changes the following important variables :
* $arrayNextDerivation ( array ) information related to the new index created in the table appDelegation
* @ param array $currentDelegation
* @ param integer $iNewDelIndex
* @ param array $nextDel
* @ return array $arrayDerivationResult
* @ throws \Exception
*/
public function routePrepareInformationNextTask ( $currentDelegation , $iNewDelIndex , $nextDel )
{
2020-08-10 17:11:55 -04:00
$nextDelegationsAux = [];
2017-07-06 16:36:53 -04:00
$taskNextDelNextDelRouType = " " ;
$i = 0 ;
//Get for $nextDel["TAS_UID"] your next Task
$currentDelegationAux = array_merge (
$currentDelegation ,
array (
" DEL_INDEX " => $iNewDelIndex ,
" TAS_UID " => $nextDel [ " TAS_UID " ]
)
);
$arrayTaskNextDelNextDelegations = $this -> prepareInformation (
array (
" USER_UID " => $_SESSION [ " USER_LOGGED " ],
" APP_UID " => $currentDelegation [ " APP_UID " ],
" DEL_INDEX " => $iNewDelIndex
)
);
foreach ( $arrayTaskNextDelNextDelegations as $key => $value ) {
$arrayTaskNextDelNextDel = $value ;
switch ( $arrayTaskNextDelNextDel [ 'NEXT_TASK' ][ 'TAS_ASSIGN_TYPE' ]) {
case 'MANUAL' :
$arrayTaskNextDelNextDel [ 'NEXT_TASK' ][ 'USER_ASSIGNED' ][ 'USR_UID' ] = '' ;
break ;
case 'MULTIPLE_INSTANCE' :
if ( ! isset ( $arrayTaskNextDelNextDel [ 'NEXT_TASK' ][ 'USER_ASSIGNED' ][ '0' ][ 'USR_UID' ])) {
throw new Exception ( G :: LoadTranslation ( 'ID_NO_USERS' ));
}
$arrayTaskNextDelNextDel [ 'NEXT_TASK' ][ 'USER_ASSIGNED' ][ 'USR_UID' ] = '' ;
break ;
case 'MULTIPLE_INSTANCE_VALUE_BASED' :
$arrayTaskNextDelNextDel [ 'NEXT_TASK' ][ 'USER_ASSIGNED' ][ 'USR_UID' ] = '' ;
break ;
default :
if ( ! isset ( $arrayTaskNextDelNextDel [ 'NEXT_TASK' ][ 'USER_ASSIGNED' ][ 'USR_UID' ])) {
throw new Exception ( G :: LoadTranslation ( 'ID_NO_USERS' ));
}
break ;
}
$taskNextDelNextDelRouType = $arrayTaskNextDelNextDel [ " ROU_TYPE " ];
$nextDelegationsAux [ ++ $i ] = array (
" TAS_UID " => $arrayTaskNextDelNextDel [ " NEXT_TASK " ][ " TAS_UID " ],
" USR_UID " => $arrayTaskNextDelNextDel [ " NEXT_TASK " ][ " USER_ASSIGNED " ][ " USR_UID " ],
" TAS_ASSIGN_TYPE " => $arrayTaskNextDelNextDel [ " NEXT_TASK " ][ " TAS_ASSIGN_TYPE " ],
" TAS_DEF_PROC_CODE " => $arrayTaskNextDelNextDel [ " NEXT_TASK " ][ " TAS_DEF_PROC_CODE " ],
" DEL_PRIORITY " => " " ,
" TAS_PARENT " => $arrayTaskNextDelNextDel [ " NEXT_TASK " ][ " TAS_PARENT " ],
" ROU_PREVIOUS_TYPE " => isset ( $arrayTaskNextDelNextDel [ " NEXT_TASK " ][ " ROU_PREVIOUS_TYPE " ]) ? $arrayTaskNextDelNextDel [ " NEXT_TASK " ][ " ROU_PREVIOUS_TYPE " ] : '' ,
" ROU_PREVIOUS_TASK " => isset ( $arrayTaskNextDelNextDel [ " NEXT_TASK " ][ " ROU_PREVIOUS_TASK " ]) ? $arrayTaskNextDelNextDel [ " NEXT_TASK " ][ " ROU_PREVIOUS_TASK " ] : ''
);
}
$currentDelegationAux [ " ROU_TYPE " ] = $taskNextDelNextDelRouType ;
$arrayNextDerivation = array (
" currentDelegation " => $currentDelegationAux ,
" nextDelegations " => $nextDelegationsAux
);
return $arrayNextDerivation ;
}
/**
* When we route a case but we will not create a index / thread in the AppDelegation
* We will to execute Events
* We will to close thread when is a Gateway to Gateway
* @ param array $appFields
* @ param array $currentDelegation
* @ param array $nextDel
* @ param array $arraySiblings
* @ param boolean $flagMultipleInstance
* @ param boolean $flagTypeMultipleInstance
* @ param boolean $flagFirstIteration
* @ return void
*/
2020-08-10 17:11:55 -04:00
public function doRouteWithoutThread ( $appFields , $currentDelegation , $nextDel , $arraySiblings = [], $flagMultipleInstance = false , $flagTypeMultipleInstance = false , $flagFirstIteration = false )
2017-07-06 16:36:53 -04:00
{
$iAppThreadIndex = $appFields [ 'DEL_THREAD' ];
$routeType = $currentDelegation [ " ROU_TYPE " ];
$routeType = ( $flagMultipleInstance && $flagTypeMultipleInstance ) ? " SEC-JOIN " : $routeType ;
switch ( $routeType ) {
case 'SEC-JOIN' :
//If the all Siblings are done execute the events
if ( sizeof ( $arraySiblings ) === 0 && ! $flagTypeMultipleInstance ) {
//Throw Events
2019-03-29 10:00:39 -04:00
$this -> executeEvent (
$nextDel [ " TAS_UID " ],
$appFields ,
$flagFirstIteration ,
false ,
'' ,
! empty ( $nextDel [ " TAS_ID " ]) ? $nextDel [ " TAS_ID " ] : 0
);
2017-07-06 16:36:53 -04:00
}
//Close thread
$this -> case -> closeAppThread ( $currentDelegation [ 'APP_UID' ], $iAppThreadIndex );
break ;
default :
if ( $nextDel [ 'ROU_PREVIOUS_TYPE' ] == 'SEC-JOIN' ) {
$criteria = new Criteria ( 'workflow' );
$criteria -> clearSelectColumns ();
$criteria -> addSelectColumn ( AppThreadPeer :: APP_THREAD_PARENT );
$criteria -> add ( AppThreadPeer :: APP_UID , $appFields [ 'APP_UID' ]);
$criteria -> add ( AppThreadPeer :: APP_THREAD_STATUS , 'OPEN' );
$criteria -> add ( AppThreadPeer :: APP_THREAD_INDEX , $iAppThreadIndex );
$rsCriteria = AppThreadPeer :: doSelectRS ( $criteria );
$rsCriteria -> setFetchmode ( ResultSet :: FETCHMODE_ASSOC );
if ( $rsCriteria -> next ()) {
$this -> case -> closeAppThread ( $currentDelegation [ 'APP_UID' ], $iAppThreadIndex );
}
}
if ( $currentDelegation [ 'TAS_ASSIGN_TYPE' ] == 'STATIC_MI' || $currentDelegation [ 'TAS_ASSIGN_TYPE' ] == 'CANCEL_MI' ) {
$this -> case -> closeAppThread ( $currentDelegation [ 'APP_UID' ], $iAppThreadIndex );
}
break ;
}
}
/**
* @ deprecated
* We create a new index in the tables with the assign task STATIC_MI
* @ param array $appFields
* @ param array $currentDelegation
* @ param array $nextDel
* @ param integer $iAppThreadIndex
* @ param string $delType
* @ return integer $iNewDelIndex , the index created
*/
public function doDerivationStaticMi ( $appFields , $currentDelegation , $nextDel , $iAppThreadIndex , $delType = 'NORMAL' )
{
$iNewAppThreadIndex = $appFields [ 'DEL_THREAD' ];
$this -> case -> closeAppThread ( $currentDelegation [ 'APP_UID' ], $iAppThreadIndex );
foreach ( $nextDel [ 'NEXT_TASK' ][ 'USER_ASSIGNED' ] as $key => $aValue ) {
//Incrementing the Del_thread First so that new delegation has new del_thread
$iNewAppThreadIndex += 1 ;
//Creating new delegation according to users in group
$iMIDelIndex = $this -> case -> newAppDelegation (
$appFields [ 'PRO_UID' ],
$currentDelegation [ 'APP_UID' ],
$nextDel [ 'TAS_UID' ],
( isset ( $aValue [ 'USR_UID' ] ) ? $aValue [ 'USR_UID' ] : '' ),
$currentDelegation [ 'DEL_INDEX' ],
$nextDel [ 'DEL_PRIORITY' ],
$iNewAppThreadIndex ,
$nextDel ,
$appFields [ 'APP_NUMBER' ],
$appFields [ 'PRO_ID' ],
$nextDel [ 'TAS_ID' ]
);
$iNewThreadIndex = $this -> case -> newAppThread (
$currentDelegation [ 'APP_UID' ],
$iMIDelIndex ,
$iAppThreadIndex
);
//Setting the del Index for Updating the AppThread delIndex
if ( $key == 0 ) {
$iNewDelIndex = $iMIDelIndex - 1 ;
}
}
return $iNewDelIndex ;
}
2017-07-12 16:38:29 -04:00
2012-10-22 15:45:47 -04:00
}