/**
  * Create record
  *
  * @param string $applicationUid Unique id of Case
  * @param int    $delIndex       Delegation index
  * @param array  $arrayData      Data
  *
  * return void
  */
 public function create($applicationUid, $delIndex, array $arrayData)
 {
     try {
         $cnn = Propel::getConnection(AppAssignSelfServiceValuePeer::DATABASE_NAME);
         try {
             $appAssignSelfServiceValue = new AppAssignSelfServiceValue();
             $appAssignSelfServiceValue->fromArray($arrayData, BasePeer::TYPE_FIELDNAME);
             $appAssignSelfServiceValue->setAppUid($applicationUid);
             $appAssignSelfServiceValue->setDelIndex($delIndex);
             if ($appAssignSelfServiceValue->validate()) {
                 $cnn->begin();
                 $result = $appAssignSelfServiceValue->save();
                 $cnn->commit();
             } else {
                 $msg = "";
                 foreach ($appAssignSelfServiceValue->getValidationFailures() as $validationFailure) {
                     $msg .= ($msg != "" ? "\n" : "") . $validationFailure->getMessage();
                 }
                 throw new Exception(G::LoadTranslation("ID_RECORD_CANNOT_BE_CREATED") . ($msg != "" ? "\n" . $msg : ""));
             }
         } catch (Exception $e) {
             $cnn->rollback();
             throw $e;
         }
     } catch (Exception $e) {
         throw $e;
     }
 }
Пример #2
0
    function doDerivation ($currentDelegation, $nextDel, $appFields, $aSP = null)

    {

        $iAppThreadIndex = $appFields['DEL_THREAD'];

        $delType = 'NORMAL';



        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;

        }

        switch ($nextDel['TAS_ASSIGN_TYPE']) {

            case 'CANCEL_MI':

            case 'STATIC_MI':

                // Create new delegation depending on the no of users in the group

                $iNewAppThreadIndex = $appFields['DEL_THREAD'];

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



                foreach ($nextDel['NEXT_TASK']['USER_ASSIGNED'] as $key => $aValue) {

                    //Incrementing the Del_thread First so that new delegation has new del_thread

                    $iNewAppThreadIndex += 1;

                    //Creating new delegation according to users in group

                    $iMIDelIndex = $this->case->newAppDelegation( $appFields['PRO_UID'], $currentDelegation['APP_UID'], $nextDel['TAS_UID'], (isset( $aValue['USR_UID'] ) ? $aValue['USR_UID'] : ''), $currentDelegation['DEL_INDEX'], $nextDel['DEL_PRIORITY'], $delType, $iNewAppThreadIndex, $nextDel );



                    $iNewThreadIndex = $this->case->newAppThread( $currentDelegation['APP_UID'], $iMIDelIndex, $iAppThreadIndex );



                    //Setting the del Index for Updating the AppThread delIndex

                    if ($key == 0) {

                        $iNewDelIndex = $iMIDelIndex - 1;

                    }

                } //end foreach

                break;

            case 'BALANCED':

                $this->setTasLastAssigned( $nextDel['TAS_UID'], $nextDel['USR_UID'] );

                //No Break, need no execute the default ones....

            default:

                // Create new delegation

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

                break;

        }



        $iAppThreadIndex = $appFields['DEL_THREAD'];



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

                break;

        } //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

            $aNewCase = $this->case->startCase( $aSP['TAS_UID'], $aSP['USR_UID'], true, $appFields);



            $taskNextDel = TaskPeer::retrieveByPK($aSP["TAS_UID"]); //Sub-Process



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

                $sOriginField = trim($sOriginField, " @#%?$=");

                $sTargetField = trim($sTargetField, " @#%?$=");



                $aNewFields[$sTargetField] = isset( $appFields['APP_DATA'][$sOriginField] ) ? $appFields['APP_DATA'][$sOriginField] : '';

            }



            $aOldFields['APP_DATA'] = array_merge( $aOldFields['APP_DATA'], $aNewFields );

            $aOldFields['APP_STATUS'] = 'TO_DO';



            $this->case->updateCase( $aNewCase['APPLICATION'], $aOldFields );



            //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' )

            );



            if ($aSP['SP_SYNCHRONOUS'] == 0) {

                $aSubApplication['SA_STATUS'] = 'FINISHED';

                $aSubApplication['SA_FINISH_DATE'] = $aSubApplication['SA_INIT_DATE'];

            }



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



            //Create record in table APP_ASSIGN_SELF_SERVICE_VALUE

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

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



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

                    $appAssignSelfServiceValue = new AppAssignSelfServiceValue();



                    $appAssignSelfServiceValue->create($aNewCase["APPLICATION"], $aNewCase["INDEX"], array("PRO_UID" => $aNewCase["PROCESS"], "TAS_UID" => $aSP["TAS_UID"], "GRP_UID" => trim($aOldFields["APP_DATA"][$nextTaskGroupVariable])));

                }

            }



            //If not is SYNCHRONOUS derivate one more time

            if ($aSP['SP_SYNCHRONOUS'] == 0) {

                $this->case->setDelInitDate( $currentDelegation['APP_UID'], $iNewDelIndex );

                $aDeriveTasks = $this->prepareInformation( array ('USER_UID' => -1,'APP_UID' => $currentDelegation['APP_UID'],'DEL_INDEX' => $iNewDelIndex

                ) );



                if (isset( $aDeriveTasks[1] )) {

                    if ($aDeriveTasks[1]['ROU_TYPE'] != 'SELECT') {

                        $nextDelegations2 = array ();

                        foreach ($aDeriveTasks as $aDeriveTask) {

                            $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']

                            );

                        }

                        $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']

                        );

                        $this->derivate( $currentDelegation2, $nextDelegations2 );

                    }

                }

            }

        } //end switch

        return $iNewDelIndex;

    }
Пример #3
0
    public function setCatchUser($sAppUid, $iDelIndex, $usrId)

    {

        try {

            $oAppDel = AppDelegationPeer::retrieveByPk($sAppUid, $iDelIndex);

            $oAppDel->setDelInitDate("now");

            $oAppDel->setUsrUid($usrId);

            $oAppDel->save();



            //update searchindex

            if ($this->appSolr != null) {

                $this->appSolr->updateApplicationSearchIndex($sAppUid);

            }



            //Delete record of the table APP_ASSIGN_SELF_SERVICE_VALUE

            $appAssignSelfServiceValue = new AppAssignSelfServiceValue();



            $appAssignSelfServiceValue->remove($sAppUid, $iDelIndex);

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

        } catch (exception $e) {

            throw ($e);

        }

    }
Пример #4
0
    /**

     * Generate data for table APP_ASSIGN_SELF_SERVICE_VALUE

     *

     * return void

     */

    public function appAssignSelfServiceValueTableGenerateData()

    {

        try {

            $this->initPropel(true);



            $appAssignSelfServiceValue = new AppAssignSelfServiceValue();

            $appAssignSelfServiceValue->generateData();

        } catch (Exception $e) {

            throw $e;

        }

    }
Пример #5
0
    function derivate ($currentDelegation = array(), $nextDelegations = array())

    {

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



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

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

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



        //Count how many tasks should be derivated.

        //$countNextTask = count($nextDelegations);

        $removeList = true;

        foreach ($nextDelegations as $nextDel) {

            //BpmnEvent - END-MESSAGE-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 TAS_ASSIGN_TYPE for current Delegation

            $oTask = new Task();

            $aTask = $oTask->load( $currentDelegation['TAS_UID'] );

            $currentDelegation['TAS_ASSIGN_TYPE'] = $aTask['TAS_ASSIGN_TYPE'];

            $currentDelegation['TAS_MI_COMPLETE_VARIABLE'] = $aTask['TAS_MI_COMPLETE_VARIABLE'];

            $currentDelegation['TAS_MI_INSTANCE_VARIABLE'] = $aTask['TAS_MI_INSTANCE_VARIABLE'];



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

            }

            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,



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

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

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



                        $case->throwMessageEventBetweenElementOriginAndElementDest(

                            $currentDelegation["TAS_UID"],

                            $nextDel["TAS_UID_DUMMY"],

                            $appFields

                        );

                    }

                    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'], $currentDelegation['ROU_TYPE'] );

                                $canDerivate = count( $siblingThreads ) == 0;

                            } elseif ($currentDelegation['ROU_TYPE'] == 'DISCRIMINATOR') {

                                //First get the total threads of Next Task where route type='Discriminator'

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

                                $siblingThreadsCount = count( $siblingThreads );

                                $discriminateThread = $currentDelegation['ROU_CONDITION'];

                                //$checkThread = count($totalThreads) - $cond;

                                if ($discriminateThread == $siblingThreadsCount) {

                                    $canDerivate = true;

                                } else {

                                    $canDerivate = false;

                                }

                            } else {

                                $canDerivate = true;

                            }

                    } //end switch



                    if ($canDerivate) {

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

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



                        //Throw Message-Events

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



                        $case->throwMessageEventBetweenElementOriginAndElementDest(

                            $currentDelegation["TAS_UID"],

                            $nextDel["TAS_UID"],

                            $appFields

                        );



                        //Create record in table APP_ASSIGN_SELF_SERVICE_VALUE

                        $task = new Task();

                        $arrayNextTaskData = $task->load($nextDel["TAS_UID"]);



                        if ($arrayNextTaskData["TAS_ASSIGN_TYPE"] == "SELF_SERVICE" && trim($arrayNextTaskData["TAS_GROUP_VARIABLE"]) != "") {

                            $nextTaskGroupVariable = trim($arrayNextTaskData["TAS_GROUP_VARIABLE"], " @#");



                            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])));

                            }

                        }

                    } else {

                        //when the task doesnt generate a new AppDelegation

                        $iAppThreadIndex = $appFields['DEL_THREAD'];

                        switch ($currentDelegation['ROU_TYPE']) {

                            case 'DISCRIMINATOR':

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

                                }

                        } //switch

                    }

            }



            //SETS THE APP_PROC_CODE

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

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

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

            unset( $aSP );

        } //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

        }

    }