diff --git a/workflow/engine/classes/Cases.php b/workflow/engine/classes/Cases.php index 114d178fb..071959fb7 100644 --- a/workflow/engine/classes/Cases.php +++ b/workflow/engine/classes/Cases.php @@ -2105,199 +2105,201 @@ class Cases * This function start a case using the task for the user $sUsrUid * With this function we can Start a case * - * @name startCase - * @param string $sTasUid - * @param string $sUsrUid - * @return Fields + * @param string $taskUid + * @param string $userUid + * @param bool $isSubProcess + * @param array $dataPreviousApplication + * @param bool $isSelfService + * @param string $sequenceType + * @return array + * @throws Exception */ - public function startCase($sTasUid, $sUsrUid, $isSubprocess = false, $dataPreviusApplication = array(), $isSelfService = false) + public function startCase($taskUid, $userUid, $isSubProcess = false, $dataPreviousApplication = [], $isSelfService = false, $sequenceType = AppSequence::APP_TYPE_NORMAL) { - if ($sTasUid != '') { + if ($taskUid != '') { try { - $task = TaskPeer::retrieveByPK($sTasUid); - $user = UsersPeer::retrieveByPK($sUsrUid); + $task = TaskPeer::retrieveByPK($taskUid); + $user = UsersPeer::retrieveByPK($userUid); if (is_null($task)) { - throw new Exception(G::LoadTranslation("ID_TASK_NOT_EXIST", array("TAS_UID", $sTasUid))); + throw new Exception(G::LoadTranslation("ID_TASK_NOT_EXIST", ["TAS_UID", $taskUid])); } - //To allow Self Service as the first task - $arrayTaskTypeToExclude = array("START-TIMER-EVENT"); + // To allow Self Service as the first task + $arrayTaskTypeToExclude = ["START-TIMER-EVENT"]; - if (!is_null($task) && !in_array($task->getTasType(), $arrayTaskTypeToExclude) && $task->getTasAssignType() != "SELF_SERVICE" && $sUsrUid == "") { + if (!is_null($task) && !in_array($task->getTasType(), $arrayTaskTypeToExclude) && $task->getTasAssignType() != "SELF_SERVICE" && $userUid == "") { throw (new Exception('You tried to start a new case without send the USER UID!')); } - //Process - $sProUid = $task->getProUid(); + // Process + $processUid = $task->getProUid(); $this->Process = new Process; - $proFields = $this->Process->Load($sProUid); + $proFields = $this->Process->Load($processUid); - //application - $Application = new Application; - $sAppUid = $Application->create($sProUid, $sUsrUid); + // Application + $application = new Application; + $appUid = $application->create($processUid, $userUid, $sequenceType); - //appDelegation - $AppDelegation = new AppDelegation; - $iAppThreadIndex = 1; // Start Thread - $iAppDelPrio = 3; // Priority - $iDelIndex = $AppDelegation->createAppDelegation( - $sProUid, - $sAppUid, - $sTasUid, - $sUsrUid, - $iAppThreadIndex, - $iAppDelPrio, - $isSubprocess, + // AppDelegation + $appDelegation = new AppDelegation; + $appThreadIndex = 1; // Start Thread + $appDelPriority = 3; // Priority + $delIndex = $appDelegation->createAppDelegation( + $processUid, + $appUid, + $taskUid, + $userUid, + $appThreadIndex, + $appDelPriority, + $isSubProcess, -1, null, false, false, 0, - $Application->getAppNumber(), + $application->getAppNumber(), $task->getTasId(), (empty($user)) ? 0 : $user->getUsrId(), $this->Process->getProId() ); - //appThread - $AppThread = new AppThread; - $iAppThreadIndex = $AppThread->createAppThread($sAppUid, $iDelIndex, 0); + // AppThread + $appThread = new AppThread; + $appThreadIndex = $appThread->createAppThread($appUid, $delIndex, 0); - $oDerivation = new Derivation(); + $derivation = new Derivation(); - //Multiple Instance - $aUserFields = array(); + // Multiple Instance + $usersFields = []; $taskAssignType = $task->getTasAssignType(); $nextTaskAssignVariable = $task->getTasAssignVariable(); if ($taskAssignType == "MULTIPLE_INSTANCE" || $taskAssignType == "MULTIPLE_INSTANCE_VALUE_BASED") { switch ($taskAssignType) { case 'MULTIPLE_INSTANCE': - $userFields = $oDerivation->getUsersFullNameFromArray($oDerivation->getAllUsersFromAnyTask($sTasUid)); + $userFields = $derivation->getUsersFullNameFromArray($derivation->getAllUsersFromAnyTask($taskUid)); break; default: throw (new Exception('Invalid Task Assignment method')); break; } - $userFields = $oDerivation->getUsersFullNameFromArray($oDerivation->getAllUsersFromAnyTask($sTasUid)); + $userFields = $derivation->getUsersFullNameFromArray($derivation->getAllUsersFromAnyTask($taskUid)); $count = 0; foreach ($userFields as $rowUser) { - if ($rowUser["USR_UID"] != $sUsrUid) { - //appDelegation - $AppDelegation = new AppDelegation; - $iAppThreadIndex ++; // Start Thread - $iAppDelPrio = 3; // Priority + if ($rowUser["USR_UID"] != $userUid) { + // AppDelegation + $appDelegation = new AppDelegation; + $appThreadIndex ++; // Start Thread + $appDelPriority = 3; // Priority $user = UsersPeer::retrieveByPK($rowUser["USR_UID"]); - $iDelIndex1 = $AppDelegation->createAppDelegation( - $sProUid, - $sAppUid, - $sTasUid, + $delIndex1 = $appDelegation->createAppDelegation( + $processUid, + $appUid, + $taskUid, $rowUser["USR_UID"], - $iAppThreadIndex, - $iAppDelPrio, - $isSubprocess, + $appThreadIndex, + $appDelPriority, + $isSubProcess, -1, null, false, false, 0, - $Application->getAppNumber(), + $application->getAppNumber(), $task->getTasId(), (empty($user)) ? 0 : $user->getUsrId(), $this->Process->getProId() ); - //appThread - $AppThread = new AppThread; - $iAppThreadIndex = $AppThread->createAppThread($sAppUid, $iDelIndex1, 0); - //Save Information - $aUserFields[$count] = $rowUser; - $aUserFields[$count]["DEL_INDEX"] = $iDelIndex1; + // AppThread + $appThread = new AppThread; + $appThreadIndex = $appThread->createAppThread($appUid, $delIndex1, 0); + // Save Information + $usersFields[$count] = $rowUser; + $usersFields[$count]["DEL_INDEX"] = $delIndex1; $count++; } } } - //DONE: Al ya existir un delegation, se puede "calcular" el caseTitle. - $Fields = $Application->toArray(BasePeer::TYPE_FIELDNAME); - $aApplicationFields = $Fields['APP_DATA']; - $Fields['DEL_INDEX'] = $iDelIndex; - $newValues = $this->newRefreshCaseTitleAndDescription($sAppUid, $Fields, $aApplicationFields); + $fields = $application->toArray(BasePeer::TYPE_FIELDNAME); + $applicationFields = $fields['APP_DATA']; + $fields['DEL_INDEX'] = $delIndex; + $newValues = $this->newRefreshCaseTitleAndDescription($appUid, $fields, $applicationFields); if (!isset($newValues['APP_TITLE'])) { $newValues['APP_TITLE'] = ''; } - $caseNumber = $Fields['APP_NUMBER']; - $Application->update($Fields); + $caseNumber = $fields['APP_NUMBER']; + $application->update($fields); - //Update the task last assigned (for web entry and web services) - $oDerivation->setTasLastAssigned($sTasUid, $sUsrUid); + // Update the task last assigned (for web entry and web services) + $derivation->setTasLastAssigned($taskUid, $userUid); // Execute Events - require_once 'classes/model/Event.php'; $event = new Event(); - $event->createAppEvents($sProUid, $sAppUid, $iDelIndex, $sTasUid); + $event->createAppEvents($processUid, $appUid, $delIndex, $taskUid); - //update searchindex + // Update search index if ($this->appSolr != null) { - $this->appSolr->updateApplicationSearchIndex($sAppUid); + $this->appSolr->updateApplicationSearchIndex($appUid); } /*----------------------------------********---------------------------------*/ - $Fields['TAS_UID'] = $sTasUid; - $Fields['USR_UID'] = $sUsrUid; - $Fields['DEL_INDEX'] = $iDelIndex; - $Fields['APP_STATUS'] = 'TO_DO'; - $Fields['DEL_DELEGATE_DATE'] = $Fields['APP_INIT_DATE']; - if (!$isSubprocess) { - $Fields['APP_STATUS'] = 'DRAFT'; + $fields['TAS_UID'] = $taskUid; + $fields['USR_UID'] = $userUid; + $fields['DEL_INDEX'] = $delIndex; + $fields['APP_STATUS'] = 'TO_DO'; + $fields['DEL_DELEGATE_DATE'] = $fields['APP_INIT_DATE']; + if (!$isSubProcess) { + $fields['APP_STATUS'] = 'DRAFT'; } else { - $Fields['APP_INIT_DATE'] = null; + $fields['APP_INIT_DATE'] = null; } $inbox = new ListInbox(); - $inbox->newRow($Fields, $sUsrUid, $isSelfService); + $inbox->newRow($fields, $userUid, $isSelfService); - //Multiple Instance - foreach ($aUserFields as $rowUser) { - $Fields["USR_UID"] = $rowUser["USR_UID"]; - $Fields["DEL_INDEX"] = $rowUser["DEL_INDEX"]; + // Multiple Instance + foreach ($usersFields as $rowUser) { + $fields["USR_UID"] = $rowUser["USR_UID"]; + $fields["DEL_INDEX"] = $rowUser["DEL_INDEX"]; $inbox = new ListInbox(); - $inbox->newRow($Fields, $sUsrUid, $isSelfService); + $inbox->newRow($fields, $userUid, $isSelfService); } /*----------------------------------********---------------------------------*/ - } catch (exception $e) { + } catch (Exception $e) { throw ($e); } } else { throw (new Exception('You tried to start a new case without send the USER UID or TASK UID!')); } - //Log + // Log $message = 'Create case'; $context = $data = [ - "appUid" => $sAppUid, - "usrUid" => $sUsrUid, - "tasUid" => $sTasUid, - "isSubprocess" => $isSubprocess, + "appUid" => $appUid, + "usrUid" => $userUid, + "tasUid" => $taskUid, + "isSubProcess" => $isSubProcess, "appNumber" => $caseNumber, - "delIndex" => $iDelIndex, - "appInitDate" => $Fields['APP_INIT_DATE'] + "delIndex" => $delIndex, + "appInitDate" => $fields['APP_INIT_DATE'] ]; Log::channel(':CreateCase')->info($message, Bootstrap::context($context)); - //call plugin + // Call plugin if (class_exists('folderData')) { - $folderData = new folderData($sProUid, $proFields['PRO_TITLE'], $sAppUid, $newValues['APP_TITLE'], $sUsrUid); - $oPluginRegistry = PluginRegistry::loadSingleton(); - $oPluginRegistry->executeTriggers(PM_CREATE_CASE, $folderData); + $folderData = new folderData($processUid, $proFields['PRO_TITLE'], $appUid, $newValues['APP_TITLE'], $userUid); + $pluginRegistry = PluginRegistry::loadSingleton(); + $pluginRegistry->executeTriggers(PM_CREATE_CASE, $folderData); } - $this->getExecuteTriggerProcess($sAppUid, 'CREATE'); - //end plugin - return array( - 'APPLICATION' => $sAppUid, - 'INDEX' => $iDelIndex, - 'PROCESS' => $sProUid, + $this->getExecuteTriggerProcess($appUid, 'CREATE'); + // End plugin + return [ + 'APPLICATION' => $appUid, + 'INDEX' => $delIndex, + 'PROCESS' => $processUid, 'CASE_NUMBER' => $caseNumber - ); + ]; } /** diff --git a/workflow/engine/classes/model/AppSequence.php b/workflow/engine/classes/model/AppSequence.php index a2fb99bdb..4d062260c 100644 --- a/workflow/engine/classes/model/AppSequence.php +++ b/workflow/engine/classes/model/AppSequence.php @@ -16,27 +16,34 @@ require_once 'classes/model/om/BaseAppSequence.php'; */ class AppSequence extends BaseAppSequence { + const APP_TYPE_NORMAL = 'NORMAL'; + const APP_TYPE_WEB_ENTRY = 'WEB_ENTRY'; + /** * Get an Set new sequence number * + * @param string $sequenceType * @return mixed * @throws Exception */ - public function sequenceNumber() + public function sequenceNumber($sequenceType) { try { $con = Propel::getConnection('workflow'); $stmt = $con->createStatement(); - //UPDATE SEQUENCES SET SEQ_VALUE = LAST_INSERT_ID(SEQ_VALUE + 1); - $sql = "UPDATE APP_SEQUENCE SET ID=LAST_INSERT_ID(ID+1)"; + $sql = "UPDATE APP_SEQUENCE SET ID=LAST_INSERT_ID(ID+1) WHERE APP_TYPE = '{$sequenceType}'"; $stmt->executeQuery($sql, ResultSet::FETCHMODE_ASSOC); - //SELECT LAST_INSERT_ID() $sql = "SELECT LAST_INSERT_ID()"; $rs = $stmt->executeQuery($sql, ResultSet::FETCHMODE_ASSOC); $rs->next(); $row = $rs->getRow(); $result = $row['LAST_INSERT_ID()']; - } catch (\Exception $e) { + + // If the type is WEB_ENTRY, we need to change to negative + if ($sequenceType === 'WEB_ENTRY') { + $result *= -1; + } + } catch (Exception $e) { throw ($e); } return $result; diff --git a/workflow/engine/classes/model/Application.php b/workflow/engine/classes/model/Application.php index 6357f1c94..9486d6b2e 100644 --- a/workflow/engine/classes/model/Application.php +++ b/workflow/engine/classes/model/Application.php @@ -207,30 +207,31 @@ class Application extends BaseApplication } /** - * Creates the Application + * Creates an Application * - * @param - * $sProUid the process id - * $sUsrUid the userid - * @return void + * @param string $processUid + * @param string $userUid + * @param string $sequenceType + * @throws PropelException + * @throws Exception + * @return string */ - public function create($sProUid, $sUsrUid) + public function create($processUid, $userUid, $sequenceType) { - require_once ("classes/model/AppSequence.php"); $con = Propel::getConnection('workflow'); try { - //fill the default values for new application row + // Fill the default values for new application row $this->setAppUid(G::generateUniqueID()); $this->setAppParent(''); $this->setAppStatus('DRAFT'); $this->setAppStatusId(1); - $this->setProUid($sProUid); + $this->setProUid($processUid); $this->setAppProcStatus(''); $this->setAppProcCode(''); $this->setAppParallel('N'); - $this->setAppInitUser($sUsrUid); - $this->setAppCurUser($sUsrUid); + $this->setAppInitUser($userUid); + $this->setAppCurUser($userUid); $this->setAppCreateDate('now'); $this->setAppInitDate('now'); $this->setAppUpdateDate('now'); @@ -241,8 +242,8 @@ class Application extends BaseApplication $c = new Criteria(); $c->clearSelectColumns(); - $oAppSequence = new AppSequence(); - $maxNumber = $oAppSequence->sequenceNumber(); + $appSequence = new AppSequence(); + $maxNumber = $appSequence->sequenceNumber($sequenceType); $this->setAppNumber($maxNumber); $this->setAppData(serialize(['APP_NUMBER' => $maxNumber, 'PIN' => $pin])); @@ -253,9 +254,7 @@ class Application extends BaseApplication $con->begin(); $this->setAppTitleContent('#' . $maxNumber); $this->setAppDescriptionContent(''); - //to do: ID_CASE in translation $this->setAppTitle(G::LoadTranslation('ID_CASE') . $maxNumber); - //Content::insertContent('APP_PROC_CODE', '', $this->getAppUid(), $lang, ''); - $res = $this->save(); + $this->save(); $con->commit(); return $this->getAppUid(); diff --git a/workflow/engine/config/schema.xml b/workflow/engine/config/schema.xml index 7731a9880..1ea687e6f 100755 --- a/workflow/engine/config/schema.xml +++ b/workflow/engine/config/schema.xml @@ -117,7 +117,7 @@