Ejemplo n.º 1
0
    function derivate($currentDelegation = array(), $nextDelegations = array(), $removeList = true)

    {

        //define this...

        if (! defined( 'TASK_FINISH_PROCESS' )) {

            define( 'TASK_FINISH_PROCESS', - 1 );

        }

        if (! defined( 'TASK_FINISH_TASK' )) {

            define( 'TASK_FINISH_TASK', - 2 );

        }



        $this->case = new cases();



        //Get data for this DEL_INDEX current

        $appFields = $this->case->loadCase( $currentDelegation['APP_UID'], $currentDelegation['DEL_INDEX'] );



        //We close the current derivation, then we'll try to derivate to each defined route

        $this->case->CloseCurrentDelegation( $currentDelegation['APP_UID'], $currentDelegation['DEL_INDEX'] );



        //Get data for current delegation (current Task)

        $task = TaskPeer::retrieveByPK($currentDelegation["TAS_UID"]);



        $currentDelegation["TAS_ASSIGN_TYPE"] = $task->getTasAssignType();

        $currentDelegation["TAS_MI_COMPLETE_VARIABLE"] = $task->getTasMiCompleteVariable();

        $currentDelegation["TAS_MI_INSTANCE_VARIABLE"] = $task->getTasMiInstanceVariable();



        //Count how many tasks should be derivated.

        //$countNextTask = count($nextDelegations);

        //$removeList = true;



        foreach ($nextDelegations as $nextDel) {

            //BpmnEvent - END-MESSAGE-EVENT, END-EMAIL-EVENT

            //Check and get unique id

            if (preg_match("/^(.{32})\/(\-1)$/", $nextDel["TAS_UID"], $arrayMatch)) {

                $nextDel["TAS_UID"] = $arrayMatch[2];

                $nextDel["TAS_UID_DUMMY"] = $arrayMatch[1];

            }



            //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();

                    $aSP['USR_UID'] = $nextDel['USR_UID'];

                    $oTask = new Task();

                    $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;

            }



            $taskNextDel = TaskPeer::retrieveByPK($nextDel["TAS_UID"]); //Get data for next delegation (next Task)



            switch ($nextDel['TAS_UID']) {

                case TASK_FINISH_PROCESS:

                    /*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,



                    //BpmnEvent - END-MESSAGE-EVENT, END-EMAIL-EVENT

                    if (isset($nextDel["TAS_UID_DUMMY"])) {

                        $taskDummy = TaskPeer::retrieveByPK($nextDel["TAS_UID_DUMMY"]);



                        switch ($taskDummy->getTasType()) {

                            case "END-MESSAGE-EVENT":

                                //Throw Message-Events - BpmnEvent - END-MESSAGE-EVENT

                                $case = new \ProcessMaker\BusinessModel\Cases();



                                $case->throwMessageEventBetweenElementOriginAndElementDest($currentDelegation["TAS_UID"], $nextDel["TAS_UID_DUMMY"], $appFields);

                                break;

                            case "END-EMAIL-EVENT":

                                //Email Event

                                $emailEvent = new \ProcessMaker\BusinessModel\EmailEvent();



                                $emailEvent->emailEventBetweenElementOriginAndElementDest($currentDelegation["TAS_UID"], $nextDel["TAS_UID_DUMMY"], $appFields);

                                break;

                        }

                    }

                    break;

                case TASK_FINISH_TASK:

                    $iAppThreadIndex = $appFields['DEL_THREAD'];

                    $this->case->closeAppThread( $currentDelegation['APP_UID'], $iAppThreadIndex );

                    break;

                default:

                    // get all siblingThreads

                    //if($currentDelegation['TAS_ASSIGN_TYPE'] == 'STATIC_MI')

                    switch ($currentDelegation['TAS_ASSIGN_TYPE']) {

                        case 'CANCEL_MI':

                        case 'STATIC_MI':

                            $siblingThreads = $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( $siblingThreads )) {

                                $canDerivate = true;

                            } else {

                                $canDerivate = false;

                            }

                            break;

                        default:

                            if ($currentDelegation["ROU_TYPE"] == "SEC-JOIN") {

                                $siblingThreads = $this->case->getOpenSiblingThreads($nextDel["TAS_UID"], $currentDelegation["APP_UID"], $currentDelegation["DEL_INDEX"], $currentDelegation["TAS_UID"]);



                                $canDerivate = empty($siblingThreads);

                            } else {

                                $canDerivate = true;

                            }

                    } //end switch



                    if ($canDerivate) {

                        //Throw Message-Events

                        $case = new \ProcessMaker\BusinessModel\Cases();



                        $case->throwMessageEventBetweenElementOriginAndElementDest($currentDelegation["TAS_UID"], $nextDel["TAS_UID"], $appFields);



                        //Throw Email-Events

                        $emailEvent = new \ProcessMaker\BusinessModel\EmailEvent();



                        $emailEvent->emailEventBetweenElementOriginAndElementDest($currentDelegation["TAS_UID"], $nextDel["TAS_UID"], $appFields);



                        //Derivate

                        $aSP = isset( $aSP ) ? $aSP : null;



                        $iNewDelIndex = $this->doDerivation( $currentDelegation, $nextDel, $appFields, $aSP );



                        //Execute Script-Task

                        $scriptTask = new \ProcessMaker\BusinessModel\ScriptTask();



                        $appFields["APP_DATA"] = $scriptTask->execScriptByActivityUid($nextDel["TAS_UID"], $appFields);



                        //Create record in table APP_ASSIGN_SELF_SERVICE_VALUE

                        $arrayTaskTypeToExclude = array("SCRIPT-TASK");



                        if (!in_array($taskNextDel->getTasType(), $arrayTaskTypeToExclude)) {

                            if ($taskNextDel->getTasAssignType() == "SELF_SERVICE" && trim($taskNextDel->getTasGroupVariable()) != "") {

                                $nextTaskGroupVariable = trim($taskNextDel->getTasGroupVariable(), " @#");



                                if (isset($appFields["APP_DATA"][$nextTaskGroupVariable]) && trim($appFields["APP_DATA"][$nextTaskGroupVariable]) != "") {

                                    $appAssignSelfServiceValue = new AppAssignSelfServiceValue();



                                    $appAssignSelfServiceValue->create($appFields["APP_UID"], $iNewDelIndex, array("PRO_UID" => $appFields["PRO_UID"], "TAS_UID" => $nextDel["TAS_UID"], "GRP_UID" => trim($appFields["APP_DATA"][$nextTaskGroupVariable])));

                                }

                            }

                        }



                        //Check if $taskNextDel is Script-Task

                        if ($taskNextDel->getTasType() == "SCRIPT-TASK") {

                            $this->case->CloseCurrentDelegation($currentDelegation["APP_UID"], $iNewDelIndex);



                            //Get for $nextDel["TAS_UID"] your next Task

                            $taskNextDelNextDelegations = $this->prepareInformation(array(

                                "USER_UID"  => $_SESSION["USER_LOGGED"],

                                "APP_UID"   => $_SESSION["APPLICATION"],

                                "DEL_INDEX" => $iNewDelIndex

                            ));



                            //New next delegation

                            $newNextDelegation = array();



                            $newNextDelegation[1] = array(

                                "TAS_UID"           => $taskNextDelNextDelegations[1]["NEXT_TASK"]["TAS_UID"],

                                "USR_UID"           => $taskNextDelNextDelegations[1]["NEXT_TASK"]["USER_ASSIGNED"]["USR_UID"],

                                "TAS_ASSIGN_TYPE"   => $taskNextDelNextDelegations[1]["NEXT_TASK"]["TAS_ASSIGN_TYPE"],

                                "TAS_DEF_PROC_CODE" => "",

                                "DEL_PRIORITY"      => "",

                                "TAS_PARENT"        => ""

                            );



                            $this->derivate($currentDelegation, $newNextDelegation, $removeList);

                        }

                    } else {

                        //when the task doesnt generate a new AppDelegation

                        $iAppThreadIndex = $appFields['DEL_THREAD'];

                        switch ($currentDelegation['ROU_TYPE']) {

                            case 'SEC-JOIN':

                                $this->case->closeAppThread( $currentDelegation['APP_UID'], $iAppThreadIndex );

                                break;

                            default:

                                if ($currentDelegation['TAS_ASSIGN_TYPE'] == 'STATIC_MI' || $currentDelegation['TAS_ASSIGN_TYPE'] == 'CANCEL_MI') {

                                    $this->case->closeAppThread( $currentDelegation['APP_UID'], $iAppThreadIndex );

                                }

                                break;

                        } //switch

                    }

            }



            //SETS THE APP_PROC_CODE

            //if (isset($nextDel['TAS_DEF_PROC_CODE']))

            //$appFields['APP_PROC_CODE'] = $nextDel['TAS_DEF_PROC_CODE'];

            /*----------------------------------********---------------------------------*/



            unset( $aSP );



            $removeList = false;

        } //end foreach



        /* 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'] );



        ///////

        $sw = 0;



        if ($openThreads == 0) {

            //Close case

            $appFields["APP_STATUS"] = "COMPLETED";

            $appFields["APP_FINISH_DATE"] = "now";

            $this->verifyIsCaseChild($currentDelegation["APP_UID"], $currentDelegation["DEL_INDEX"]);



            $sw = 1;

        }



        if (isset( $iNewDelIndex )) {

            $appFields["DEL_INDEX"] = $iNewDelIndex;

            $appFields["TAS_UID"] = $nextDel["TAS_UID"];



            $sw = 1;

        }



        if ($sw == 1) {

            //Start Block : UPDATES APPLICATION

            $this->case->updateCase( $currentDelegation["APP_UID"], $appFields );

            //End Block : UPDATES APPLICATION

        }

    }
Ejemplo n.º 2
0
    function derivate($currentDelegation = array(), $nextDelegations = array(), $removeList = true)

    {

        //define this...

        if (! defined( 'TASK_FINISH_PROCESS' )) {

            define( 'TASK_FINISH_PROCESS', - 1 );

        }

        if (! defined( 'TASK_FINISH_TASK' )) {

            define( 'TASK_FINISH_TASK', - 2 );

        }



        $this->case = new cases();



        //Get data for this DEL_INDEX current

        $appFields = $this->case->loadCase( $currentDelegation['APP_UID'], $currentDelegation['DEL_INDEX'] );



        //We close the current derivation, then we'll try to derivate to each defined route

        $this->case->CloseCurrentDelegation( $currentDelegation['APP_UID'], $currentDelegation['DEL_INDEX'] );



        //Get data for current delegation (current Task)

        $task = TaskPeer::retrieveByPK($currentDelegation["TAS_UID"]);

        $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());

        }



        $currentDelegation["TAS_ASSIGN_TYPE"] = $task->getTasAssignType();

        $currentDelegation["TAS_MI_COMPLETE_VARIABLE"] = $task->getTasMiCompleteVariable();

        $currentDelegation["TAS_MI_INSTANCE_VARIABLE"] = $task->getTasMiInstanceVariable();



        //Count how many tasks should be derivated.

        //$countNextTask = count($nextDelegations);

        //$removeList = true;



        foreach ($nextDelegations as $nextDel) {

            //BpmnEvent - END-MESSAGE-EVENT, END-EMAIL-EVENT

            //Check and get unique id

            if (preg_match("/^(.{32})\/(\-1)$/", $nextDel["TAS_UID"], $arrayMatch)) {

                $nextDel["TAS_UID"] = $arrayMatch[2];

                $nextDel["TAS_UID_DUMMY"] = $arrayMatch[1];

            }



            //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();

                    $aSP['USR_UID'] = $nextDel['USR_UID'];

                    $oTask = new Task();

                    $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;

            }



            $taskNextDel = TaskPeer::retrieveByPK($nextDel["TAS_UID"]); //Get data for next delegation (next Task)

            $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;



            switch ($nextDel['TAS_UID']) {

                case TASK_FINISH_PROCESS:

                    /*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,



                    //BpmnEvent - END-MESSAGE-EVENT, END-EMAIL-EVENT

                    if (isset($nextDel["TAS_UID_DUMMY"])) {

                        $taskDummy = TaskPeer::retrieveByPK($nextDel["TAS_UID_DUMMY"]);



                        switch ($taskDummy->getTasType()) {

                            case "END-MESSAGE-EVENT":

                                //Throw Message-Events - BpmnEvent - END-MESSAGE-EVENT

                                $case = new \ProcessMaker\BusinessModel\Cases();



                                $case->throwMessageEventBetweenElementOriginAndElementDest($currentDelegation["TAS_UID"], $nextDel["TAS_UID_DUMMY"], $appFields);

                                break;

                            case "END-EMAIL-EVENT":

                                //Email Event

                                $emailEvent = new \ProcessMaker\BusinessModel\EmailEvent();



                                $emailEvent->emailEventBetweenElementOriginAndElementDest($currentDelegation["TAS_UID"], $nextDel["TAS_UID_DUMMY"], $appFields);

                                break;

                        }

                    }

                    break;

                case TASK_FINISH_TASK:

                    $iAppThreadIndex = $appFields['DEL_THREAD'];

                    $this->case->closeAppThread( $currentDelegation['APP_UID'], $iAppThreadIndex );

                    break;

                default:

                    //Get all siblingThreads

                    $canDerivate = false;



                    switch ($currentDelegation['TAS_ASSIGN_TYPE']) {

                        case 'CANCEL_MI':

                        case 'STATIC_MI':

                            $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)) {

                                $canDerivate = true;

                            } else {

                                $canDerivate = false;

                            }

                            break;

                        default:

                            $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();

                                    $arrayOpenThread = array_merge($arrayOpenThread, $this->case->getOpenSiblingThreads($nextDel["TAS_UID"], $currentDelegation["APP_UID"], $currentDelegation["DEL_INDEX"], $currentDelegation["TAS_UID"]));



                                    $canDerivate = empty($arrayOpenThread);

                                    break;

                                default:

                                    $canDerivate = true;

                                    break;

                            }

                            break;

                    }



                    if ($canDerivate) {

                        //Throw Message-Events

                        $case = new \ProcessMaker\BusinessModel\Cases();



                        $case->throwMessageEventBetweenElementOriginAndElementDest($currentDelegation["TAS_UID"], $nextDel["TAS_UID"], $appFields);



                        //Throw Email-Events

                        $emailEvent = new \ProcessMaker\BusinessModel\EmailEvent();



                        $emailEvent->emailEventBetweenElementOriginAndElementDest($currentDelegation["TAS_UID"], $nextDel["TAS_UID"], $appFields);



                        //Derivate

                        $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"));

                                }



                                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;

                                }

                                break;

                            default:

                                $iNewDelIndex = $this->doDerivation($currentDelegation, $nextDel, $appFields, $aSP);

                                break;

                        }



                        //Execute Script-Task

                        $scriptTask = new \ProcessMaker\BusinessModel\ScriptTask();



                        $appFields["APP_DATA"] = $scriptTask->execScriptByActivityUid($nextDel["TAS_UID"], $appFields);



                        //Create record in table APP_ASSIGN_SELF_SERVICE_VALUE

                        $regexpTaskTypeToExclude = "SCRIPT-TASK";



                        if (!is_null($taskNextDel) && !preg_match("/^(?:" . $regexpTaskTypeToExclude . ")$/", $taskNextDel->getTasType())) {

                            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, array("PRO_UID" => $appFields["PRO_UID"], "TAS_UID" => $nextDel["TAS_UID"], "GRP_UID" => serialize($dataVariable)));

                                    }

                                }

                            }

                        }



                        //Check if $taskNextDel is Script-Task

                        if (!is_null($taskNextDel) && $taskNextDel->getTasType() == "SCRIPT-TASK") {

                            $this->case->CloseCurrentDelegation($currentDelegation["APP_UID"], $iNewDelIndex);



                            //Get for $nextDel["TAS_UID"] your next Task

                            $taskNextDelNextDelegations = $this->prepareInformation(array(

                                "USER_UID"  => $_SESSION["USER_LOGGED"],

                                "APP_UID"   => $_SESSION["APPLICATION"],

                                "DEL_INDEX" => $iNewDelIndex

                            ));



                            //New next delegation

                            $newNextDelegation = array();



                            $newNextDelegation[1] = array(

                                "TAS_UID"           => $taskNextDelNextDelegations[1]["NEXT_TASK"]["TAS_UID"],

                                "USR_UID"           => $taskNextDelNextDelegations[1]["NEXT_TASK"]["USER_ASSIGNED"]["USR_UID"],

                                "TAS_ASSIGN_TYPE"   => $taskNextDelNextDelegations[1]["NEXT_TASK"]["TAS_ASSIGN_TYPE"],

                                "TAS_DEF_PROC_CODE" => "",

                                "DEL_PRIORITY"      => "",

                                "TAS_PARENT"        => ""

                            );



                            $this->derivate($currentDelegation, $newNextDelegation, $removeList);

                        }

                    } else {

                        //when the task doesnt generate a new AppDelegation

                        $iAppThreadIndex = $appFields['DEL_THREAD'];



                        $routeType = $currentDelegation["ROU_TYPE"];

                        $routeType = ($flagTaskIsMultipleInstance && $flagTaskAssignTypeIsMultipleInstance)? "SEC-JOIN" : $routeType;



                        switch ($routeType) {

                            case 'SEC-JOIN':

                                $this->case->closeAppThread( $currentDelegation['APP_UID'], $iAppThreadIndex );

                                break;

                            default:

                                if ($currentDelegation['TAS_ASSIGN_TYPE'] == 'STATIC_MI' || $currentDelegation['TAS_ASSIGN_TYPE'] == 'CANCEL_MI') {

                                    $this->case->closeAppThread( $currentDelegation['APP_UID'], $iAppThreadIndex );

                                }

                                break;

                        }

                    }

                    break;

            }



            if ($flagUpdateCounters) {

                $this->derivateUpdateCounters($currentDelegation, $nextDel, $taskNextDel, $appFields, (isset($iNewDelIndex))? $iNewDelIndex : 0, (isset($aSP))? $aSP : null, $removeList);

            }



            $removeList = false;



            unset($aSP);

        }



        /* 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'] );



        ///////

        $flag = false;



        if ($openThreads == 0) {

            //Close case

            $appFields["APP_STATUS"] = "COMPLETED";

            $appFields["APP_FINISH_DATE"] = "now";

            $this->verifyIsCaseChild($currentDelegation["APP_UID"], $currentDelegation["DEL_INDEX"]);



            $flag = true;

        }



        if (isset( $iNewDelIndex )) {

            $appFields["DEL_INDEX"] = $iNewDelIndex;

            $appFields["TAS_UID"] = $nextDel["TAS_UID"];



            $flag = true;

        }



        if ($flag) {

            //Start Block : UPDATES APPLICATION

            $this->case->updateCase( $currentDelegation["APP_UID"], $appFields );

            //End Block : UPDATES APPLICATION

        }

    }