2010-12-02 23:34:41 +00:00
< ? php
/**
* class . derivation . php
2012-10-09 12:40:24 -04:00
*
2011-02-01 12:49:40 +00:00
* @ package workflow . engine . ProcessMaker
2010-12-02 23:34:41 +00:00
*
* ProcessMaker Open Source Edition
2011-02-01 12:49:40 +00:00
* Copyright ( C ) 2004 - 2011 Colosa Inc .
2010-12-02 23:34:41 +00:00
*
* This program is free software : you can redistribute it and / or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation , either version 3 of the
* License , or ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
2012-10-09 12:40:24 -04:00
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
2010-12-02 23:34:41 +00:00
* GNU Affero General Public License for more details .
*
* You should have received a copy of the GNU Affero General Public License
2012-10-09 12:40:24 -04:00
* along with this program . If not , see < http :// www . gnu . org / licenses />.
2010-12-02 23:34:41 +00:00
*
* For more information , contact Colosa Inc , 2566 Le Jeune Rd . ,
* Coral Gables , FL , 33134 , USA , or email info @ colosa . com .
*
*/
2012-10-09 12:40:24 -04:00
require_once ( " classes/model/Task.php " );
require_once ( " classes/model/Process.php " );
require_once ( " classes/model/Step.php " );
require_once ( " classes/model/Application.php " );
require_once ( 'classes/model/Groupwf.php' );
require_once ( " classes/model/GroupUser.php " );
require_once ( " classes/model/AppDelegation.php " );
require_once ( " classes/model/Route.php " );
require_once ( 'classes/model/SubApplication.php' );
require_once ( 'classes/model/SubProcess.php' );
require_once ( " classes/model/Users.php " );
G :: LoadClass ( " plugin " );
2010-12-02 23:34:41 +00:00
/**
* derivation - derivation class
2012-10-09 12:40:24 -04:00
*
2011-02-01 12:49:40 +00:00
* @ package workflow . engine . ProcessMaker
2010-12-02 23:34:41 +00:00
*
*/
class Derivation
{
2012-10-09 12:40:24 -04:00
var $case ;
2016-04-14 15:51:36 -04:00
protected $flagControl ;
2016-04-15 16:46:47 -04:00
protected $flagControlMulInstance ;
2016-08-01 16:42:58 -04:00
private $regexpTaskTypeToInclude ;
public function __construct ()
{
$this -> setRegexpTaskTypeToInclude ( " GATEWAYTOGATEWAY|END-MESSAGE-EVENT|END-EMAIL-EVENT " );
}
/**
* @ 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
2014-11-26 10:19:07 -04:00
*/
2016-08-04 15:30:29 -04:00
private 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-06-09 16:14:50 -04:00
$regexpTaskTypeToExclude = " GATEWAYTOGATEWAY|END-MESSAGE-EVENT|SCRIPT-TASK|INTERMEDIATE-CATCH-TIMER-EVENT|END-EMAIL-EVENT|INTERMEDIATE-THROW-EMAIL-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 ;
}
}
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
*
2015-10-19 14:01:31 -04:00
* @ return array Return array
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 {
if ( ! class_exists ( " Cases " )) {
G :: LoadClass ( " case " );
}
2010-12-02 23:34:41 +00:00
2014-12-04 11:40:52 -04:00
$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 " ]);
2014-12-04 11:40:52 -04:00
$arrayNextTask = array ();
$arrayNextTaskDefault = array ();
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 ;
2015-11-13 15:05:26 -04:00
$aSecJoin = array ();
$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
G :: LoadClass ( " pmScript " );
2012-10-09 12:40:24 -04:00
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 " ]);
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
2015-02-21 15:59:12 -04:00
$arrayNextTaskBackup = $arrayNextTask ;
2014-12-04 11:40:52 -04:00
$arrayNextTask = array ();
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 ;
2015-02-21 15:59:12 -04:00
if ( $arrayNextTaskData [ " NEXT_TASK " ][ " TAS_UID " ] != " -1 " &&
2016-08-01 16:42:58 -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 " ]);
foreach ( $arrayAux as $value2 ) {
2016-08-01 16:42:58 -04:00
$key = ++ $i ;
$arrayNextTask [ $key ] = $value2 ;
$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-01 16:42:58 -04:00
$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' :
//look for USR_REPORTS_TO to this user
$userFields [ 'USR_UID' ] = '' ;
$userFields [ 'USR_FULLNAME' ] = '<b>' . G :: LoadTranslation ( 'ID_UNASSIGNED' ) . '</b>' ;
$userFields [ 'USR_USERNAME' ] = '<b>' . G :: LoadTranslation ( 'ID_UNASSIGNED' ) . '</b>' ;
$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 " ], " @# " );
if ( $nextTaskAssignVariable != " " &&
isset ( $arrayApplicationData [ " APP_DATA " ][ $nextTaskAssignVariable ]) && ! empty ( $arrayApplicationData [ " APP_DATA " ][ $nextTaskAssignVariable ]) && is_array ( $arrayApplicationData [ " APP_DATA " ][ $nextTaskAssignVariable ])
) {
$userFields = $this -> getUsersFullNameFromArray ( $arrayApplicationData [ " APP_DATA " ][ $nextTaskAssignVariable ]);
} else {
throw new Exception ( G :: LoadTranslation ( " ID_ACTIVITY_INVALID_USER_DATA_VARIABLE_FOR_MULTIPLE_INSTANCE_ACTIVITY " , array ( strtolower ( " ACT_UID " ), $nextAssignedTask [ " TAS_UID " ], $nextTaskAssignVariable )));
}
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
*
2016-06-09 16:14:50 -04:00
* @ param string $dummyTaskUid Unique id of Element Origin ( unique id of Task ) This is the nextTask
* @ param array $applicationData Case data
2015-11-06 18:10:16 -04:00
* @ param bool $flagEventExecuteBeforeGateway Execute event before gateway
* @ param bool $flagEventExecuteAfterGateway Execute event after gateway
*
* @ return void
*/
2016-06-09 16:14:50 -04:00
private function executeEvent ( $dummyTaskUid , array $applicationData , $flagEventExecuteBeforeGateway = true , $flagEventExecuteAfterGateway = true , $elementOriUid = '' )
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
2016-06-09 16:14:50 -04:00
$arrayElement = array ();
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 )){
$arrayOtherElement = array ();
$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 " ;
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 );
}
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
$result = $emailEvent -> sendEmail ( $applicationData [ " APP_UID " ], $applicationData [ " PRO_UID " ], $value [ 'uid' ], $applicationData );
}
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
2015-09-11 09:27:16 -04:00
*/
private function derivateUpdateCounters ( array $arrayCurrentDelegationData , array $arrayNextDelegationData , $taskNextDelegation , array $arrayApplicationData , $delIndexNew , $aSp , $removeList )
{
/*----------------------------------********---------------------------------*/
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 ;
$inbox = new ListInbox ();
$inbox -> newRow ( $arrayApplicationData2 , $arrayApplicationData [ " CURRENT_USER_UID " ], false , array (), (( $arrayNextDelegationData [ " TAS_ASSIGN_TYPE " ] == " SELF_SERVICE " ) ? true : false ));
2015-09-11 09:27:16 -04:00
}
}
}
} catch ( Exception $e ) {
throw $e ;
}
/*----------------------------------********---------------------------------*/
}
2016-08-04 11:36:58 -04:00
/**
* Get valid origin Task
*
* @ param string $applicationUid Unique id of Case
* @ param int $delIndex Delegation index
*
* @ return string Returns valid origin Task
*/
private function __getTaskUidOrigin ( $applicationUid , $delIndex )
{
$taskUidOrigin = '' ;
do {
$criteria = new Criteria ( 'workflow' );
$criteria -> addSelectColumn ( AppDelegationPeer :: DEL_PREVIOUS );
$criteria -> addSelectColumn ( TaskPeer :: TAS_UID );
$criteria -> addSelectColumn ( TaskPeer :: TAS_TYPE );
$criteria -> addJoin ( AppDelegationPeer :: TAS_UID , TaskPeer :: TAS_UID , Criteria :: INNER_JOIN );
$criteria -> add ( AppDelegationPeer :: APP_UID , $applicationUid , Criteria :: EQUAL );
$criteria -> add ( AppDelegationPeer :: DEL_INDEX , $delIndex , Criteria :: EQUAL );
$rsCriteria = AppDelegationPeer :: doSelectRS ( $criteria );
$rsCriteria -> setFetchmode ( ResultSet :: FETCHMODE_ASSOC );
if ( $rsCriteria -> next ()) {
$record = $rsCriteria -> getRow ();
if ( preg_match ( '/^(?:' . 'NORMAL|SCRIPT\-TASK|WEBENTRYEVENT|START\-MESSAGE\-EVENT|START\-TIMER\-EVENT' . ')$/' , $record [ 'TAS_TYPE' ])) {
$taskUidOrigin = $record [ 'TAS_UID' ];
}
$delIndex = $record [ 'DEL_PREVIOUS' ];
}
} while ( $taskUidOrigin == '' );
//Return
return $taskUidOrigin ;
}
2015-10-19 14:01:31 -04:00
/** Derivate
2012-10-22 15:45:47 -04:00
*
2015-10-19 14:01:31 -04:00
* @ param array $currentDelegation
* @ param array $nextDelegations
* @ param bool $removeList
*
* @ return void
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
{
2015-12-09 17:01:20 -04:00
$arrayDerivationResult = [];
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
$this -> case = new cases ();
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' ] );
2015-06-25 15:59:34 -04:00
2016-08-04 11:36:58 -04:00
unset ( $appFields [ 'APP_ROUTING_DATA' ]);
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' ] );
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 ();
2015-10-19 14:01:31 -04:00
$arrayNextDerivation = array ();
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 ];
}
2012-10-09 12:40:24 -04:00
//subprocesses??
if ( $nextDel [ 'TAS_PARENT' ] != '' ) {
$oCriteria = new Criteria ( 'workflow' );
$oCriteria -> add ( SubProcessPeer :: PRO_PARENT , $appFields [ 'PRO_UID' ] );
$oCriteria -> add ( SubProcessPeer :: TAS_PARENT , $nextDel [ 'TAS_PARENT' ] );
if ( SubProcessPeer :: doCount ( $oCriteria ) > 0 ) {
$oDataset = SubProcessPeer :: doSelectRS ( $oCriteria );
$oDataset -> setFetchmode ( ResultSet :: FETCHMODE_ASSOC );
$oDataset -> next ();
$aSP = $oDataset -> getRow ();
$oTask = new Task ();
2015-12-07 17:08:28 -04:00
$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 ;
}
$aSP [ 'USR_UID' ] = $firstUserUid ;
} else {
$aSP [ 'USR_UID' ] = $nextDel [ 'USR_UID' ];
}
2012-10-09 12:40:24 -04:00
$aTask = $oTask -> load ( $nextDel [ 'TAS_PARENT' ] );
$nextDel = array ( 'TAS_UID' => $aTask [ 'TAS_UID' ], 'USR_UID' => $aSP [ 'USR_UID' ], 'TAS_ASSIGN_TYPE' => $aTask [ 'TAS_ASSIGN_TYPE' ], 'TAS_DEF_PROC_CODE' => $aTask [ 'TAS_DEF_PROC_CODE' ], 'DEL_PRIORITY' => 3 , 'TAS_PARENT' => ''
);
} 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 ());
}
$flagUpdateCounters = true ;
2015-06-30 12:04:53 -04:00
2012-10-09 12:40:24 -04:00
switch ( $nextDel [ 'TAS_UID' ]) {
case TASK_FINISH_PROCESS :
2012-10-22 15:45:47 -04:00
/*Close all delegations of $currentDelegation['APP_UID'] */
$this -> case -> closeAllDelegations ( $currentDelegation [ 'APP_UID' ] );
2012-10-09 12:40:24 -04:00
$this -> case -> closeAllThreads ( $currentDelegation [ 'APP_UID' ] );
//I think we need to change the APP_STATUS to completed,
2015-12-04 11:31:44 -04:00
if ( ! isset ( $nextDel [ 'ROU_CONDITION' ])) {
$nextDel [ 'ROU_CONDITION' ] = '' ;
}
2016-06-09 16:14:50 -04:00
//Execute the Intermediate Event After the End of Process
$this -> executeEvent ( $nextDel [ " TAS_UID " ], $appFields , true , true );
2015-11-24 11:54:28 -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 ())) {
//Throw Events
2016-06-09 16:14:50 -04:00
$this -> executeEvent ( $nextDel [ " TAS_UID_DUMMY " ], $appFields , $flagFirstIteration , true );
2015-11-24 11:54:28 -04:00
}
}
2012-10-09 12:40:24 -04:00
break ;
case TASK_FINISH_TASK :
$iAppThreadIndex = $appFields [ 'DEL_THREAD' ];
$this -> case -> closeAppThread ( $currentDelegation [ 'APP_UID' ], $iAppThreadIndex );
break ;
default :
2015-09-11 09:27:16 -04:00
//Get all siblingThreads
$canDerivate = false ;
2012-10-09 12:40:24 -04:00
switch ( $currentDelegation [ 'TAS_ASSIGN_TYPE' ]) {
case 'CANCEL_MI' :
case 'STATIC_MI' :
2015-09-11 09:27:16 -04:00
$arrayOpenThread = $this -> case -> GetAllOpenDelegation ( $currentDelegation );
2012-10-09 12:40:24 -04:00
$aData = $this -> case -> loadCase ( $currentDelegation [ 'APP_UID' ] );
2012-10-22 15:45:47 -04:00
if ( isset ( $aData [ 'APP_DATA' ][ str_replace ( '@@' , '' , $currentDelegation [ 'TAS_MI_INSTANCE_VARIABLE' ] )] )) {
2012-10-09 12:40:24 -04:00
$sMIinstanceVar = $aData [ 'APP_DATA' ][ str_replace ( '@@' , '' , $currentDelegation [ 'TAS_MI_INSTANCE_VARIABLE' ] )];
2012-10-22 15:45:47 -04:00
} else {
2012-10-09 12:40:24 -04:00
$sMIinstanceVar = $aData [ 'APP_DATA' ][ 'TAS_MI_INSTANCE_VARIABLE' ];
2012-10-22 15:45:47 -04:00
}
2012-10-09 12:40:24 -04:00
2012-10-22 15:45:47 -04:00
if ( isset ( $aData [ 'APP_DATA' ][ str_replace ( '@@' , '' , $currentDelegation [ 'TAS_MI_COMPLETE_VARIABLE' ] )] )) {
2012-10-09 12:40:24 -04:00
$sMIcompleteVar = $aData [ 'APP_DATA' ][ str_replace ( '@@' , '' , $currentDelegation [ 'TAS_MI_COMPLETE_VARIABLE' ] )];
2012-10-22 15:45:47 -04:00
} else {
2012-10-09 12:40:24 -04:00
$sMIcompleteVar = $aData [ 'APP_DATA' ][ 'TAS_MI_COMPLETE_VARIABLE' ];
2012-10-22 15:45:47 -04:00
}
2012-10-09 12:40:24 -04:00
$discriminateThread = $sMIinstanceVar - $sMIcompleteVar ;
// -1 because One App Delegation is closed by above Code
2015-09-11 09:27:16 -04:00
if ( $discriminateThread == count ( $arrayOpenThread )) {
2012-10-09 12:40:24 -04:00
$canDerivate = true ;
2012-10-22 15:45:47 -04:00
} else {
2012-10-09 12:40:24 -04:00
$canDerivate = false ;
2012-10-22 15:45:47 -04:00
}
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 " :
$arrayOpenThread = ( $flagTaskIsMultipleInstance && $flagTaskAssignTypeIsMultipleInstance ) ? $this -> case -> searchOpenPreviousTasks ( $currentDelegation [ " TAS_UID " ], $currentDelegation [ " APP_UID " ]) : array ();
2016-03-30 16:27:27 -04:00
$arraySiblings = $this -> case -> getOpenSiblingThreads ( $nextDel [ " TAS_UID " ], $currentDelegation [ " APP_UID " ], $currentDelegation [ " DEL_INDEX " ], $currentDelegation [ " TAS_UID " ]);
if ( is_array ( $arrayOpenThread ) && is_array ( $arraySiblings )){
$arrayOpenThread = array_merge ( $arrayOpenThread , $arraySiblings );
}
2015-09-11 09:27:16 -04:00
$canDerivate = empty ( $arrayOpenThread );
2016-04-14 15:51:36 -04:00
if ( $canDerivate ){
2016-04-15 16:46:47 -04:00
if ( $flagTaskIsMultipleInstance && $flagTaskAssignTypeIsMultipleInstance ){
$this -> flagControlMulInstance = true ;
} else {
$this -> flagControl = true ;
}
2016-04-14 15:51:36 -04:00
}
2016-03-30 16:27:27 -04:00
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 " ){
$arrayOpenThread = $this -> case -> searchOpenPreviousTasks ( $nextDel [ " ROU_PREVIOUS_TASK " ], $currentDelegation [ " APP_UID " ]);
2016-06-30 09:31:34 -04:00
$arraySiblings = $this -> case -> getOpenSiblingThreads ( $nextDel [ " ROU_PREVIOUS_TASK " ], $currentDelegation [ " APP_UID " ], $currentDelegation [ " DEL_INDEX " ], $currentDelegation [ " TAS_UID " ]);
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 ) {
2016-05-04 10:29:18 -04:00
$rouCondition = '' ;
if ( isset ( $nextDel [ 'ROU_CONDITION' ])){
$rouCondition = $nextDel [ 'ROU_CONDITION' ];
}
2016-06-09 16:14:50 -04:00
if ( ! isset ( $nextDel [ 'USR_UID' ])){
$nextDel [ 'USR_UID' ] = '' ;
}
2015-11-06 18:10:16 -04:00
//Throw Events
2016-06-09 16:14:50 -04:00
$this -> executeEvent ( $nextDel [ " TAS_UID " ], $appFields , true , true , $currentDelegation [ " TAS_UID " ]);
2015-06-30 12:04:53 -04:00
2015-06-25 15:59:34 -04:00
//Derivate
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 " :
$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 " ));
}
2015-06-25 15:59:34 -04:00
2015-09-11 09:27:16 -04:00
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 -> derivateUpdateCounters ( $currentDelegationAux , $nextDelAux , $taskNextDel , $appFields , $iNewDelIndex , $aSP , $removeList );
$flagUpdateCounters = false ;
$removeList = false ;
2015-12-09 17:01:20 -04:00
$arrayDerivationResult [] = [ 'DEL_INDEX' => $iNewDelIndex , 'TAS_UID' => $nextDelAux [ 'TAS_UID' ], 'USR_UID' => ( isset ( $nextDelAux [ 'USR_UID' ])) ? $nextDelAux [ 'USR_UID' ] : '' ];
2015-09-11 09:27:16 -04:00
}
break ;
default :
$iNewDelIndex = $this -> doDerivation ( $currentDelegation , $nextDel , $appFields , $aSP );
2016-08-04 11:36:58 -04:00
2016-04-14 15:51:36 -04:00
if ( $iNewDelIndex !== 0 ){
$arrayDerivationResult [] = [ 'DEL_INDEX' => $iNewDelIndex , 'TAS_UID' => $nextDel [ 'TAS_UID' ], 'USR_UID' => ( isset ( $nextDel [ 'USR_UID' ])) ? $nextDel [ 'USR_UID' ] : '' ];
}
2015-09-11 09:27:16 -04:00
break ;
}
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-06-09 16:14:50 -04:00
$regexpTaskTypeToExclude = " SCRIPT-TASK|INTERMEDIATE-THROW-EMAIL-EVENT " ;
2014-10-27 11:25:17 -04:00
2015-09-11 09:27:16 -04:00
if ( ! is_null ( $taskNextDel ) && ! preg_match ( " /^(?: " . $regexpTaskTypeToExclude . " ) $ / " , $taskNextDel -> getTasType ())) {
2015-06-30 12:04:53 -04:00
if ( $taskNextDel -> getTasAssignType () == " SELF_SERVICE " && trim ( $taskNextDel -> getTasGroupVariable ()) != " " ) {
$nextTaskGroupVariable = trim ( $taskNextDel -> getTasGroupVariable (), " @# " );
2014-10-27 11:25:17 -04:00
2015-09-01 14:57:25 -04:00
if ( isset ( $appFields [ " APP_DATA " ][ $nextTaskGroupVariable ])) {
$dataVariable = $appFields [ " APP_DATA " ][ $nextTaskGroupVariable ];
$dataVariable = ( is_array ( $dataVariable )) ? $dataVariable : trim ( $dataVariable );
2014-10-27 11:25:17 -04:00
2015-09-01 14:57:25 -04:00
if ( ! empty ( $dataVariable )) {
$appAssignSelfServiceValue = new AppAssignSelfServiceValue ();
$appAssignSelfServiceValue -> create ( $appFields [ " APP_UID " ], $iNewDelIndex , array ( " PRO_UID " => $appFields [ " PRO_UID " ], " TAS_UID " => $nextDel [ " TAS_UID " ], " GRP_UID " => serialize ( $dataVariable )));
}
2015-06-25 15:59:34 -04:00
}
2014-10-27 11:25:17 -04:00
}
}
2015-06-25 15:59:34 -04:00
2015-06-30 12:04:53 -04:00
//Check if $taskNextDel is Script-Task
2016-06-09 16:14:50 -04:00
if ( ! is_null ( $taskNextDel ) && ( $taskNextDel -> getTasType () === " SCRIPT-TASK " || $taskNextDel -> getTasType () === " INTERMEDIATE-THROW-EMAIL-EVENT " )) {
2015-06-25 15:59:34 -04:00
//Get for $nextDel["TAS_UID"] your next Task
2015-10-19 14:01:31 -04:00
$currentDelegationAux = array_merge ( $currentDelegation , array ( " DEL_INDEX " => $iNewDelIndex , " TAS_UID " => $nextDel [ " TAS_UID " ]));
$nextDelegationsAux = array ();
$taskNextDelNextDelRouType = " " ;
$i = 0 ;
$arrayTaskNextDelNextDelegations = $this -> prepareInformation ( array (
2015-06-25 15:59:34 -04:00
" USER_UID " => $_SESSION [ " USER_LOGGED " ],
2015-10-19 14:01:31 -04:00
" APP_UID " => $currentDelegation [ " APP_UID " ],
2015-06-25 15:59:34 -04:00
" DEL_INDEX " => $iNewDelIndex
));
2015-10-19 14:01:31 -04:00
foreach ( $arrayTaskNextDelNextDelegations as $key2 => $value2 ) {
$arrayTaskNextDelNextDel = $value2 ;
2015-06-25 15:59:34 -04:00
2016-08-04 11:36:58 -04:00
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 ;
default :
if ( ! isset ( $arrayTaskNextDelNextDel [ 'NEXT_TASK' ][ 'USER_ASSIGNED' ][ 'USR_UID' ])) {
throw new Exception ( G :: LoadTranslation ( 'ID_NO_USERS' ));
}
break ;
2015-10-19 14:01:31 -04:00
}
2015-11-17 11:46:07 -04:00
$rouPreType = " " ;
$rouPreTask = " " ;
2015-10-19 14:01:31 -04:00
$taskNextDelNextDelRouType = $arrayTaskNextDelNextDel [ " ROU_TYPE " ];
2015-11-17 11:46:07 -04:00
if ( isset ( $arrayTaskNextDelNextDel [ " NEXT_TASK " ][ " ROU_PREVIOUS_TYPE " ]) && isset ( $arrayTaskNextDelNextDel [ " NEXT_TASK " ][ " ROU_PREVIOUS_TASK " ])){
$rouPreType = $arrayTaskNextDelNextDel [ " NEXT_TASK " ][ " ROU_PREVIOUS_TYPE " ];
$rouPreTask = $arrayTaskNextDelNextDel [ " NEXT_TASK " ][ " ROU_PREVIOUS_TASK " ];
}
2016-08-04 11:36:58 -04:00
2015-10-19 14:01:31 -04:00
$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 " => " " ,
2015-11-13 15:05:26 -04:00
" TAS_PARENT " => $arrayTaskNextDelNextDel [ " NEXT_TASK " ][ " TAS_PARENT " ],
2015-11-17 11:46:07 -04:00
" ROU_PREVIOUS_TYPE " => $rouPreType ,
" ROU_PREVIOUS_TASK " => $rouPreTask
2015-10-19 14:01:31 -04:00
);
}
2015-06-25 15:59:34 -04:00
2015-10-19 14:01:31 -04:00
$currentDelegationAux [ " ROU_TYPE " ] = $taskNextDelNextDelRouType ;
$arrayNextDerivation [] = array ( " currentDelegation " => $currentDelegationAux , " nextDelegations " => $nextDelegationsAux );
2015-06-25 15:59:34 -04:00
}
2012-10-22 15:45:47 -04:00
} else {
//when the task doesnt generate a new AppDelegation
2012-10-09 12:40:24 -04:00
$iAppThreadIndex = $appFields [ 'DEL_THREAD' ];
2015-09-11 09:27:16 -04:00
$routeType = $currentDelegation [ " ROU_TYPE " ];
$routeType = ( $flagTaskIsMultipleInstance && $flagTaskAssignTypeIsMultipleInstance ) ? " SEC-JOIN " : $routeType ;
switch ( $routeType ) {
2012-10-09 12:40:24 -04:00
case 'SEC-JOIN' :
2016-06-09 16:14:50 -04:00
//If the all Siblings are done execute the events
if ( sizeof ( $arraySiblings ) === 0 ){
//Throw Events
$this -> executeEvent ( $nextDel [ " TAS_UID " ], $appFields , $flagFirstIteration , false );
}
2015-10-23 12:16:54 -04:00
//Close thread
2012-10-09 12:40:24 -04:00
$this -> case -> closeAppThread ( $currentDelegation [ 'APP_UID' ], $iAppThreadIndex );
break ;
default :
2012-10-22 15:45:47 -04:00
if ( $currentDelegation [ 'TAS_ASSIGN_TYPE' ] == 'STATIC_MI' || $currentDelegation [ 'TAS_ASSIGN_TYPE' ] == 'CANCEL_MI' ) {
2012-10-09 12:40:24 -04:00
$this -> case -> closeAppThread ( $currentDelegation [ 'APP_UID' ], $iAppThreadIndex );
2012-10-22 15:45:47 -04:00
}
2015-07-28 10:29:41 -04:00
break ;
2015-03-27 14:24:56 -04:00
}
}
2015-09-11 09:27:16 -04:00
break ;
2015-03-06 18:06:31 -04:00
}
2015-06-30 12:04:53 -04:00
2015-09-11 09:27:16 -04:00
if ( $flagUpdateCounters ) {
$this -> derivateUpdateCounters ( $currentDelegation , $nextDel , $taskNextDel , $appFields , ( isset ( $iNewDelIndex )) ? $iNewDelIndex : 0 , ( isset ( $aSP )) ? $aSP : null , $removeList );
}
2015-06-25 15:59:34 -04:00
$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 : UPDATES APPLICATION */
//Set THE APP_STATUS
$appFields [ 'APP_STATUS' ] = $currentDelegation [ 'APP_STATUS' ];
/* Start Block : Count the open threads of $currentDelegation['APP_UID'] */
$openThreads = $this -> case -> GetOpenThreads ( $currentDelegation [ 'APP_UID' ] );
2015-09-11 09:27:16 -04:00
$flag = false ;
2012-10-09 12:40:24 -04:00
2016-06-07 12:29:08 -04:00
//check if there is any paused thread
2016-06-08 12:19:39 -04:00
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 " ;
2014-07-03 12:42:37 -04:00
$this -> verifyIsCaseChild ( $currentDelegation [ " APP_UID " ], $currentDelegation [ " DEL_INDEX " ]);
2015-09-11 09:27:16 -04:00
$flag = true ;
2016-06-14 10:46:34 -04:00
2010-12-02 23:34:41 +00:00
}
2012-10-09 12:40:24 -04:00
if ( isset ( $iNewDelIndex )) {
$appFields [ " DEL_INDEX " ] = $iNewDelIndex ;
$appFields [ " TAS_UID " ] = $nextDel [ " TAS_UID " ];
2015-09-11 09:27:16 -04:00
$flag = true ;
2010-12-02 23:34:41 +00:00
}
2012-10-09 12:40:24 -04:00
2015-09-11 09:27:16 -04:00
if ( $flag ) {
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
}
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 );
$arrayRoutingData = ( ! is_null ( $arrayApplicationData [ 'APP_ROUTING_DATA' ]) && $arrayApplicationData [ 'APP_ROUTING_DATA' ] != '' ) ? unserialize ( $arrayApplicationData [ 'APP_ROUTING_DATA' ]) : [];
2012-10-09 12:40:24 -04:00
$iAppThreadIndex = $appFields [ 'DEL_THREAD' ];
$delType = 'NORMAL' ;
2016-06-27 12:10:04 -04:00
$sendNotificationsMobile = false ;
2012-10-09 12:40:24 -04:00
2016-08-04 11:36:58 -04:00
$taskNextDel = TaskPeer :: retrieveByPK ( $nextDel [ " TAS_UID " ]);
$taskUidOrigin = $this -> __getTaskUidOrigin ( $currentDelegation [ 'APP_UID' ], $currentDelegation [ 'DEL_INDEX' ]);
$taskUidDest = $taskNextDel -> getTasUid ();
if ( array_key_exists ( $taskUidOrigin . '/' . $taskUidDest , $arrayRoutingData )) {
$nextDel [ 'USR_UID' ] = $arrayRoutingData [ $taskUidOrigin . '/' . $taskUidDest ][ 'USR_UID' ];
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
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
$iNewAppThreadIndex = $appFields [ 'DEL_THREAD' ];
$this -> case -> closeAppThread ( $currentDelegation [ 'APP_UID' ], $iAppThreadIndex );
2011-10-24 08:48:59 -04:00
2012-10-09 12:40:24 -04:00
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' ], $delType , $iNewAppThreadIndex , $nextDel );
2011-10-24 08:48:59 -04:00
2012-10-09 12:40:24 -04:00
$iNewThreadIndex = $this -> case -> newAppThread ( $currentDelegation [ 'APP_UID' ], $iMIDelIndex , $iAppThreadIndex );
2012-08-16 11:44:17 -04:00
2012-10-09 12:40:24 -04:00
//Setting the del Index for Updating the AppThread delIndex
2012-10-22 15:45:47 -04:00
if ( $key == 0 ) {
2012-10-09 12:40:24 -04:00
$iNewDelIndex = $iMIDelIndex - 1 ;
2012-10-22 15:45:47 -04:00
}
2012-10-09 12:40:24 -04:00
} //end foreach
break ;
case 'BALANCED' :
$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 );
$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' ];
}
2012-10-09 12:40:24 -04:00
// Create new delegation
2016-04-15 16:46:47 -04:00
$iNewDelIndex = $this -> case -> newAppDelegation ( $appFields [ 'PRO_UID' ], $currentDelegation [ 'APP_UID' ], $nextDel [ 'TAS_UID' ], ( isset ( $nextDel [ 'USR_UID' ] ) ? $nextDel [ 'USR_UID' ] : '' ), $currentDelegation [ 'DEL_INDEX' ], $nextDel [ 'DEL_PRIORITY' ], $delType , $iAppThreadIndex , $nextDel , $this -> flagControl , $this -> flagControlMulInstance , $delPrevious );
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 ;
}
}
}
$application = new Application ();
$result = $application -> update ([ 'APP_UID' => $currentDelegation [ 'APP_UID' ], 'APP_ROUTING_DATA' => serialize ( $arrayRoutingData )]);
//APP_THREAD
2012-10-09 12:40:24 -04:00
$iAppThreadIndex = $appFields [ 'DEL_THREAD' ];
2012-08-16 11:44:17 -04:00
2012-10-09 12:40:24 -04:00
switch ( $currentDelegation [ 'ROU_TYPE' ]) {
case 'PARALLEL' :
case 'PARALLEL-BY-EVALUATION' :
$this -> case -> closeAppThread ( $currentDelegation [ 'APP_UID' ], $iAppThreadIndex );
$iNewThreadIndex = $this -> case -> newAppThread ( $currentDelegation [ 'APP_UID' ], $iNewDelIndex , $iAppThreadIndex );
$this -> case -> updateAppDelegation ( $currentDelegation [ 'APP_UID' ], $iNewDelIndex , $iNewThreadIndex );
break ;
default :
$this -> case -> updateAppThread ( $currentDelegation [ 'APP_UID' ], $iAppThreadIndex , $iNewDelIndex );
2015-07-28 10:29:41 -04:00
break ;
2012-10-09 12:40:24 -04:00
} //en switch
//if there are subprocess to create
if ( isset ( $aSP )) {
//Create the new case in the sub-process
// set the initial date to null the time its created
2015-03-09 15:23:38 -04:00
$aNewCase = $this -> case -> startCase ( $aSP [ 'TAS_UID' ], $aSP [ 'USR_UID' ], true , $appFields );
2015-06-25 15:59:34 -04:00
2015-06-30 12:04:53 -04:00
$taskNextDel = TaskPeer :: retrieveByPK ( $aSP [ " TAS_UID " ]); //Sub-Process
2012-10-09 12:40:24 -04:00
//Copy case variables to sub-process case
$aFields = unserialize ( $aSP [ 'SP_VARIABLES_OUT' ] );
$aNewFields = array ();
$aOldFields = $this -> case -> loadCase ( $aNewCase [ 'APPLICATION' ] );
foreach ( $aFields as $sOriginField => $sTargetField ) {
2015-07-28 10:29:41 -04:00
$sOriginField = trim ( $sOriginField , " @#%? $ = " );
$sTargetField = trim ( $sTargetField , " @#%? $ = " );
2012-10-09 12:40:24 -04:00
$aNewFields [ $sTargetField ] = isset ( $appFields [ 'APP_DATA' ][ $sOriginField ] ) ? $appFields [ 'APP_DATA' ][ $sOriginField ] : '' ;
2016-07-15 14:52:57 -04:00
if ( array_key_exists ( $sOriginField . '_label' , $appFields [ 'APP_DATA' ])) {
$aNewFields [ $sTargetField . '_label' ] = $appFields [ 'APP_DATA' ][ $sOriginField . '_label' ];
}
2012-10-09 12:40:24 -04:00
}
2012-08-16 11:44:17 -04:00
2012-10-09 12:40:24 -04:00
$aOldFields [ 'APP_DATA' ] = array_merge ( $aOldFields [ 'APP_DATA' ], $aNewFields );
$aOldFields [ 'APP_STATUS' ] = 'TO_DO' ;
2011-10-24 08:48:59 -04:00
2012-10-09 12:40:24 -04:00
$this -> case -> updateCase ( $aNewCase [ 'APPLICATION' ], $aOldFields );
2015-07-28 10:29:41 -04:00
2012-10-09 12:40:24 -04:00
//Create a registry in SUB_APPLICATION table
$aSubApplication = array ( 'APP_UID' => $aNewCase [ 'APPLICATION' ], 'APP_PARENT' => $currentDelegation [ 'APP_UID' ], 'DEL_INDEX_PARENT' => $iNewDelIndex , 'DEL_THREAD_PARENT' => $iAppThreadIndex , 'SA_STATUS' => 'ACTIVE' , 'SA_VALUES_OUT' => serialize ( $aNewFields ), 'SA_INIT_DATE' => date ( 'Y-m-d H:i:s' )
);
2011-10-24 08:48:59 -04:00
2012-10-09 12:40:24 -04:00
if ( $aSP [ 'SP_SYNCHRONOUS' ] == 0 ) {
$aSubApplication [ 'SA_STATUS' ] = 'FINISHED' ;
$aSubApplication [ 'SA_FINISH_DATE' ] = $aSubApplication [ 'SA_INIT_DATE' ];
}
2011-10-24 08:48:59 -04:00
2012-10-09 12:40:24 -04:00
$oSubApplication = new SubApplication ();
$oSubApplication -> create ( $aSubApplication );
//Update the AppDelegation to execute the update trigger
$AppDelegation = AppDelegationPeer :: retrieveByPK ( $aNewCase [ 'APPLICATION' ], $aNewCase [ 'INDEX' ] );
// note added by krlos pacha carlos[at]colosa[dot]com
// the following line of code was commented because it is related to the 6878 bug
//$AppDelegation->setDelInitDate("+1 second");
$AppDelegation -> save ();
2015-07-28 10:29:41 -04:00
//Create record in table APP_ASSIGN_SELF_SERVICE_VALUE
if ( $taskNextDel -> getTasAssignType () == " SELF_SERVICE " && trim ( $taskNextDel -> getTasGroupVariable ()) != " " ) {
$nextTaskGroupVariable = trim ( $taskNextDel -> getTasGroupVariable (), " @# " );
2012-10-09 12:40:24 -04:00
2015-09-01 14:57:25 -04:00
if ( isset ( $aOldFields [ " APP_DATA " ][ $nextTaskGroupVariable ])) {
$dataVariable = $aOldFields [ " APP_DATA " ][ $nextTaskGroupVariable ];
$dataVariable = ( is_array ( $dataVariable )) ? $dataVariable : trim ( $dataVariable );
if ( ! empty ( $dataVariable )) {
$appAssignSelfServiceValue = new AppAssignSelfServiceValue ();
2015-07-28 10:29:41 -04:00
2015-09-01 14:57:25 -04:00
$appAssignSelfServiceValue -> create ( $aNewCase [ " APPLICATION " ], $aNewCase [ " INDEX " ], array ( " PRO_UID " => $aNewCase [ " PROCESS " ], " TAS_UID " => $aSP [ " TAS_UID " ], " GRP_UID " => serialize ( $dataVariable )));
}
2015-07-28 10:29:41 -04:00
}
}
2016-06-27 12:10:04 -04:00
$sendNotificationsMobile = $this -> sendNotificationsMobile ( $aOldFields , $aSP , $aNewCase [ 'INDEX' ]);
2015-07-28 10:29:41 -04:00
//If not is SYNCHRONOUS derivate one more time
2012-10-09 12:40:24 -04:00
if ( $aSP [ 'SP_SYNCHRONOUS' ] == 0 ) {
$this -> case -> setDelInitDate ( $currentDelegation [ 'APP_UID' ], $iNewDelIndex );
2013-01-24 12:54:12 -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' ) {
2016-06-14 10:46:34 -04:00
$nextDelegations2 = array ();
2012-10-09 12:40:24 -04:00
foreach ( $aDeriveTasks as $aDeriveTask ) {
2016-06-14 10:46:34 -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' ]
2012-10-09 12:40:24 -04:00
);
}
2016-06-14 10:46:34 -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 {
$oSubApplication = new SubApplication ();
$aSubApplication [ 'SA_STATUS' ] = 'ACTIVE' ;
$oSubApplication -> update ( $aSubApplication );
}
2012-10-09 12:40:24 -04:00
}
}
2011-10-24 08:48:59 -04:00
}
2012-10-09 12:40:24 -04:00
} //end switch
2016-06-27 12:10:04 -04:00
if ( $iNewDelIndex !== 0 && ! $sendNotificationsMobile ){
2016-07-26 15:34:52 -04:00
$sendNotificationsMobile = $this -> sendNotificationsMobile ( $appFields , $nextDel , $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
2012-10-09 12:40:24 -04:00
/* verifyIsCaseChild
2012-10-22 15:45:47 -04:00
*
* @ param string $sApplicationUID
* @ return void
*/
2014-07-03 12:42:37 -04:00
function verifyIsCaseChild ( $sApplicationUID , $delIndex = 0 )
2012-10-09 12:40:24 -04:00
{
//Obtain the related row in the table SUB_APPLICATION
$oCriteria = new Criteria ( 'workflow' );
$oCriteria -> add ( SubApplicationPeer :: APP_UID , $sApplicationUID );
$oDataset = SubApplicationPeer :: doSelectRS ( $oCriteria );
$oDataset -> setFetchmode ( ResultSet :: FETCHMODE_ASSOC );
$oDataset -> next ();
$aSA = $oDataset -> getRow ();
if ( $aSA ) {
//Obtain the related row in the table SUB_PROCESS
$oCase = new Cases ();
$aParentCase = $oCase -> loadCase ( $aSA [ 'APP_PARENT' ], $aSA [ 'DEL_INDEX_PARENT' ] );
$oCriteria = new Criteria ( 'workflow' );
$oCriteria -> add ( SubProcessPeer :: PRO_PARENT , $aParentCase [ 'PRO_UID' ] );
$oCriteria -> add ( SubProcessPeer :: TAS_PARENT , $aParentCase [ 'TAS_UID' ] );
$oDataset = SubProcessPeer :: doSelectRS ( $oCriteria );
$oDataset -> setFetchmode ( ResultSet :: FETCHMODE_ASSOC );
$oDataset -> next ();
$aSP = $oDataset -> getRow ();
2016-06-14 10:46:34 -04:00
if ( $aSP [ 'SP_SYNCHRONOUS' ] == 1 || $aSA [ 'SA_STATUS' ] == " ACTIVE " ) {
2014-07-03 12:42:37 -04:00
$appFields = $oCase -> loadCase ( $sApplicationUID , $delIndex );
2012-10-09 12:40:24 -04:00
//Copy case variables to parent case
2016-06-14 10:46:34 -04:00
$aFields = unserialize ( $aSP [ 'SP_VARIABLES_IN' ]);
$aNewFields = array ();
2012-10-09 12:40:24 -04:00
foreach ( $aFields as $sOriginField => $sTargetField ) {
2016-06-14 10:46:34 -04:00
$sOriginField = str_replace ( '@' , '' , $sOriginField );
$sOriginField = str_replace ( '#' , '' , $sOriginField );
$sOriginField = str_replace ( '%' , '' , $sOriginField );
$sOriginField = str_replace ( '?' , '' , $sOriginField );
$sOriginField = str_replace ( '$' , '' , $sOriginField );
$sOriginField = str_replace ( '=' , '' , $sOriginField );
$sTargetField = str_replace ( '@' , '' , $sTargetField );
$sTargetField = str_replace ( '#' , '' , $sTargetField );
$sTargetField = str_replace ( '%' , '' , $sTargetField );
$sTargetField = str_replace ( '?' , '' , $sTargetField );
$sTargetField = str_replace ( '$' , '' , $sTargetField );
$sTargetField = str_replace ( '=' , '' , $sTargetField );
$aNewFields [ $sTargetField ] = isset ( $appFields [ 'APP_DATA' ][ $sOriginField ]) ? $appFields [ 'APP_DATA' ][ $sOriginField ] : '' ;
2016-07-15 14:52:57 -04:00
if ( array_key_exists ( $sOriginField . '_label' , $appFields [ 'APP_DATA' ])) {
$aNewFields [ $sTargetField . '_label' ] = $appFields [ 'APP_DATA' ][ $sOriginField . '_label' ];
} else {
if ( array_key_exists ( $sTargetField . '_label' , $aParentCase [ 'APP_DATA' ])) {
$aNewFields [ $sTargetField . '_label' ] = '' ;
}
2015-04-29 16:49:52 -04:00
}
2012-10-09 12:40:24 -04:00
}
2016-06-14 10:46:34 -04:00
$aParentCase [ 'APP_DATA' ] = array_merge ( $aParentCase [ 'APP_DATA' ], $aNewFields );
$oCase -> updateCase ( $aSA [ 'APP_PARENT' ], $aParentCase );
2015-02-27 16:27:11 -04:00
/*----------------------------------********---------------------------------*/
$inbox = new ListInbox ();
2015-06-25 15:59:34 -04:00
$inbox -> update ( $aParentCase );
2015-02-27 16:27:11 -04:00
/*----------------------------------********---------------------------------*/
2015-06-25 15:59:34 -04:00
2012-10-09 12:40:24 -04:00
//Update table SUB_APPLICATION
$oSubApplication = new SubApplication ();
2016-06-14 10:46:34 -04:00
$oSubApplication -> update ( array ( 'APP_UID' => $sApplicationUID , 'APP_PARENT' => $aSA [ 'APP_PARENT' ], 'DEL_INDEX_PARENT' => $aSA [ 'DEL_INDEX_PARENT' ], 'DEL_THREAD_PARENT' => $aSA [ 'DEL_THREAD_PARENT' ], 'SA_STATUS' => 'FINISHED' , 'SA_VALUES_IN' => serialize ( $aNewFields ), '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
2016-06-14 10:46:34 -04:00
$aDeriveTasks = $this -> prepareInformation ( array ( 'USER_UID' => - 1 , 'APP_UID' => $aSA [ 'APP_PARENT' ], 'DEL_INDEX' => $aSA [ 'DEL_INDEX_PARENT' ]
));
if ( isset ( $aDeriveTasks [ 1 ])) {
2012-10-09 12:40:24 -04:00
if ( $aDeriveTasks [ 1 ][ 'ROU_TYPE' ] != 'SELECT' ) {
2016-06-14 10:46:34 -04:00
$nextDelegations2 = array ();
2012-10-09 12:40:24 -04:00
foreach ( $aDeriveTasks as $aDeriveTask ) {
2016-06-14 10:46:34 -04:00
if ( ! isset ( $aDeriveTask [ 'NEXT_TASK' ][ 'USER_ASSIGNED' ][ 'USR_UID' ])) {
2012-10-09 12:40:24 -04:00
$selectedUser = $aDeriveTask [ 'NEXT_TASK' ][ 'USER_ASSIGNED' ][ 0 ];
2016-06-14 10:46:34 -04:00
unset ( $aDeriveTask [ 'NEXT_TASK' ][ 'USER_ASSIGNED' ]);
2012-10-09 12:40:24 -04:00
$aDeriveTask [ 'NEXT_TASK' ][ 'USER_ASSIGNED' ] = $selectedUser ;
2016-06-14 10:46:34 -04:00
$myLabels = array ( $aDeriveTask [ 'NEXT_TASK' ][ 'TAS_TITLE' ], $aParentCase [ 'APP_NUMBER' ], $selectedUser [ 'USR_USERNAME' ], $selectedUser [ 'USR_FIRSTNAME' ], $selectedUser [ 'USR_LASTNAME' ]
2012-10-09 12:40:24 -04:00
);
2016-06-14 10:46:34 -04:00
if ( $aDeriveTask [ 'NEXT_TASK' ][ 'TAS_ASSIGN_TYPE' ] == " MANUAL " ) {
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
}
2016-06-14 10:46:34 -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' ]
2012-10-09 12:40:24 -04:00
);
}
2016-06-14 10:46:34 -04:00
$currentDelegation2 = array ( 'APP_UID' => $aSA [ 'APP_PARENT' ], 'DEL_INDEX' => $aSA [ 'DEL_INDEX_PARENT' ], 'APP_STATUS' => 'TO_DO' , 'TAS_UID' => $aParentCase [ 'TAS_UID' ], 'ROU_TYPE' => $aDeriveTasks [ 1 ][ 'ROU_TYPE' ]
2012-10-09 12:40:24 -04:00
);
2016-06-14 10:46:34 -04:00
$this -> derivate ( $currentDelegation2 , $nextDelegations2 );
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 ;
if ( $appFields [ " CURRENT_USER_UID " ] == '' ) {
$oCriteriaTaskDummy = new Criteria ( 'workflow' );
$oCriteriaTaskDummy -> add ( TaskPeer :: PRO_UID , $appFields [ 'PRO_UID' ]);
$oCriteriaTaskDummy -> add ( TaskPeer :: TAS_UID , $appFields [ 'TAS_UID' ]);
$oCriteriaTaskDummy -> add (
$oCriteriaTaskDummy -> getNewCriterion ( TaskPeer :: TAS_TYPE , 'SCRIPT-TASK' , Criteria :: EQUAL ) -> addOr (
$oCriteriaTaskDummy -> getNewCriterion ( TaskPeer :: TAS_TYPE , 'INTERMEDIATE-THROW-EMAIL-EVENT' , Criteria :: EQUAL ))
);
$oCriteriaTaskDummy -> setLimit ( 1 );
$oDataset = AppDelegationPeer :: doSelectRS ( $oCriteriaTaskDummy );
$oDataset -> setFetchmode ( \ResultSet :: FETCHMODE_ASSOC );
$oDataset -> next ();
if ( $row = $oDataset -> getRow ()) {
$flagNotification = true ;
}
}
if ( ! $flagNotification ) {
// Send notifications - Start
$oUser = new Users ();
$aUser = $oUser -> load ( $appFields [ " CURRENT_USER_UID " ]);
$sFromName = $aUser [ " USR_FIRSTNAME " ] . " " . $aUser [ " USR_LASTNAME " ] . ( $aUser [ " USR_EMAIL " ] != " " ? " < " . $aUser [ " USR_EMAIL " ] . " > " : " " );
try {
$oCase -> sendNotifications ( $appFields [ " TAS_UID " ],
$nextDelegations2 ,
$appFields [ " APP_DATA " ],
$sApplicationUID ,
$delIndex ,
$sFromName );
} catch ( Exception $e ) {
G :: SendTemporalMessage ( G :: loadTranslation ( " ID_NOTIFICATION_ERROR " ) . " - " . $e -> getMessage (), " warning " , " string " , null , " 100% " );
}
// 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
}
}
}
2012-10-09 12:40:24 -04:00
/* 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 )
{
G :: LoadClass ( 'groups' );
G :: LoadClass ( 'tasks' );
require_once 'classes/model/Content.php' ;
$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 ;
}
function checkReplacedByUser ( $user )
{
if ( is_string ( $user )) {
$userInstance = UsersPeer :: retrieveByPK ( $user );
} else {
$userInstance = $user ;
}
if ( ! is_object ( $userInstance )) {
throw new Exception ( " The user with the UID ' $user ' doesn't exist. " );
}
if ( $userInstance -> getUsrStatus () == 'ACTIVE' ) {
return $userInstance -> getUsrUid ();
} else {
$userReplace = trim ( $userInstance -> getUsrReplacedBy () );
if ( $userReplace != '' ) {
return $this -> checkReplacedByUser ( UsersPeer :: retrieveByPK ( $userReplace ) );
} 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 " );
}
}
2012-10-22 15:45:47 -04:00
}