/** * Delete User * * @param string $usrUid Unique id of User * * return void */ public function delete($usrUid) { try { //Verify data $this->throwExceptionIfNotExistsUser($usrUid, $this->arrayFieldNameForException["usrUid"]); \G::LoadClass('case'); $oProcessMap = new \Cases(); $USR_UID = $usrUid; $total = 0; $history = 0; $c = $oProcessMap->getCriteriaUsersCases('TO_DO', $USR_UID); $total += \ApplicationPeer::doCount($c); $c = $oProcessMap->getCriteriaUsersCases('DRAFT', $USR_UID); $total += \ApplicationPeer::doCount($c); $c = $oProcessMap->getCriteriaUsersCases('COMPLETED', $USR_UID); $history += \ApplicationPeer::doCount($c); $c = $oProcessMap->getCriteriaUsersCases('CANCELLED', $USR_UID); $history += \ApplicationPeer::doCount($c); if ($total > 0) { throw new \Exception(\G::LoadTranslation("ID_USER_CAN_NOT_BE_DELETED", array($USR_UID))); } else { $UID = $usrUid; \G::LoadClass('tasks'); $oTasks = new \Tasks(); $oTasks->ofToAssignUserOfAllTasks($UID); \G::LoadClass('groups'); $oGroups = new \Groups(); $oGroups->removeUserOfAllGroups($UID); $this->changeUserStatus($UID, 'CLOSED'); $_GET['USR_USERNAME'] = ''; $this->updateUser(array('USR_UID' => $UID, 'USR_USERNAME' => $_GET['USR_USERNAME']), ''); require_once (PATH_TRUNK . "workflow" . PATH_SEP . "engine" . PATH_SEP . "classes" . PATH_SEP . "model" . PATH_SEP . "Users.php"); $oUser = new \Users(); $aFields = $oUser->load($UID); $aFields['USR_STATUS'] = 'CLOSED'; $aFields['USR_USERNAME'] = ''; $oUser->update($aFields); //Delete Dashboard require_once (PATH_TRUNK . "workflow" . PATH_SEP . "engine" . PATH_SEP . "classes" . PATH_SEP . "model" . PATH_SEP . "DashletInstance.php"); $criteria = new \Criteria( 'workflow' ); $criteria->add( \DashletInstancePeer::DAS_INS_OWNER_UID, $UID ); $criteria->add( \DashletInstancePeer::DAS_INS_OWNER_TYPE , 'USER'); \DashletInstancePeer::doDelete( $criteria ); } } catch (\Exception $e) { throw $e; } }
/** * consolidatedUpdate * * @author Brayan Pereyra (Cochalo) <*****@*****.**> * @copyright Colosa - Bolivia */ function consolidatedUpdate($dynaformUid, $dataUpdate, $usr_uid) { G::LoadClass("case"); G::LoadClass("pmFunctions"); $delIndex = 1; $oCase = new \Cases(); $array = array(); $array["form"] = $dataUpdate; $appUid = $array["form"]["APP_UID"]; $fields = $oCase->loadCase($appUid); if (!isset($fields["DEL_INIT_DATE"])) { $oCase->setDelInitDate($appUid, $delIndex); //$aFields = $oCase->loadCase($appUid, $delIndex); $fields = $oCase->loadCase($appUid, $delIndex); } $auxAppDataApplication = $fields["APP_DATA"]["APPLICATION"]; $auxAppDataProcess = $fields["APP_DATA"]["PROCESS"]; $auxAppDataTask = $fields["APP_DATA"]["TASK"]; $auxAppDataIndex = $fields["APP_DATA"]["INDEX"]; foreach ($array["form"] as $key => $value) { $array["form"][$key] = (string)$array["form"][$key]; if (isset($fields["APP_DATA"][$key.'_label'])) { $array["form"][$key.'_label'] = (string)$array["form"][$key]; } } /* $_POST['form'] = $array["form"]; if (!class_exists('Smarty')) { require_once(PATH_THIRDPARTY . 'smarty' . PATH_SEP . 'libs' . PATH_SEP . 'Smarty.class.php'); } $oForm = new \Form( $auxAppDataProcess . "/" . $dynaformUid , PATH_DYNAFORM ); $oForm->validatePost(); $array["form"] = $_POST['form']; */ $fields["APP_DATA"] = array_merge($fields["APP_DATA"], G::getSystemConstants()); $fields["APP_DATA"] = array_merge($fields["APP_DATA"], $array["form"]); $fields["APP_DATA"]["APPLICATION"] = $auxAppDataApplication; $fields["APP_DATA"]["PROCESS"] = $auxAppDataProcess; $fields["APP_DATA"]["TASK"] = $auxAppDataTask; $fields["APP_DATA"]["INDEX"] = $auxAppDataIndex; $aData = array(); $aData["APP_NUMBER"] = $fields["APP_NUMBER"]; $aData["APP_PROC_STATUS"] = $fields["APP_PROC_STATUS"]; $aData["APP_DATA"] = $fields["APP_DATA"]; $aData["DEL_INDEX"] = $delIndex; $aData["TAS_UID"] = $fields["APP_DATA"]["TASK"]; $aData["CURRENT_DYNAFORM"] = $dynaformUid; $aData["USER_UID"] = $usr_uid; $aData["APP_STATUS"] = $fields["APP_STATUS"]; $aData["PRO_UID"] = $fields["APP_DATA"]["PROCESS"]; $oCase->updateCase($appUid, $aData); }
/** * */ public function pauseCase($usr_uid, $app_uid, $request_data) { $result = new \stdclass(); try { $unpauseDate = $request_data['unpauseDate'] . ' '. $request_data['unpauseTime']; $oCase = new \Cases(); $iDelIndex = $oCase->getCurrentDelegation( $app_uid, $usr_uid ); // Save the note pause reason if ($request_data['noteContent'] != '') { $request_data['noteContent'] = G::LoadTranslation('ID_CASE_PAUSE_LABEL_NOTE') . ' ' . $request_data['noteContent']; $appNotes = new \AppNotes(); $noteContent = addslashes($request_data['noteContent']); $appNotes->postNewNote($app_uid, $usr_uid, $noteContent, $request_data['notifyUser']); } // End save $oCase->pauseCase($app_uid, $iDelIndex, $usr_uid, $unpauseDate); $app = new \Application(); $caseData = $app->load($app_uid); $data['APP_NUMBER'] = $caseData['APP_NUMBER']; $data['UNPAUSE_DATE'] = $unpauseDate; $result->success = true; $result->msg = G::LoadTranslation('ID_CASE_PAUSED_SUCCESSFULLY', SYS_LANG, $data); } catch (\Exception $e) { throw $e; } return $result; }
/** * Catch Message-Events for the Cases * * @param bool $frontEnd Flag to represent progress bar * * return void */ public function catchMessageEvent($frontEnd = false) { try { \G::LoadClass("wsBase"); //Set variables $ws = new \wsBase(); $case = new \Cases(); $messageApplication = new \ProcessMaker\BusinessModel\MessageApplication(); $messageApplication->setFrontEnd($frontEnd); //Get data $totalMessageEvent = 0; $counterStartMessageEvent = 0; $counterIntermediateCatchMessageEvent = 0; $counter = 0; $flagFirstTime = false; $messageApplication->frontEndShow("START"); do { $flagNextRecords = false; $arrayMessageApplicationUnread = $messageApplication->getMessageApplications(array("messageApplicationStatus" => "UNREAD"), null, null, 0, 1000); if (!$flagFirstTime) { $totalMessageEvent = $arrayMessageApplicationUnread["total"]; $flagFirstTime = true; } foreach ($arrayMessageApplicationUnread["data"] as $value) { if ($counter + 1 > $totalMessageEvent) { $flagNextRecords = false; break; } $arrayMessageApplicationData = $value; $processUid = $arrayMessageApplicationData["PRJ_UID"]; $taskUid = $arrayMessageApplicationData["TAS_UID"]; $messageApplicationUid = $arrayMessageApplicationData["MSGAPP_UID"]; $messageApplicationCorrelation = $arrayMessageApplicationData["MSGAPP_CORRELATION"]; $messageEventDefinitionUserUid = $arrayMessageApplicationData["MSGED_USR_UID"]; $messageEventDefinitionCorrelation = $arrayMessageApplicationData["MSGED_CORRELATION"]; $arrayVariable = $messageApplication->mergeVariables($arrayMessageApplicationData["MSGED_VARIABLES"], $arrayMessageApplicationData["MSGAPP_VARIABLES"]); $flagCatched = false; switch ($arrayMessageApplicationData["EVN_TYPE"]) { case "START": if ($messageEventDefinitionCorrelation == $messageApplicationCorrelation && $messageEventDefinitionUserUid != "") { //Start and derivate new Case $result = $ws->newCase($processUid, $messageEventDefinitionUserUid, $taskUid, $arrayVariable); $arrayResult = json_decode(json_encode($result), true); if ($arrayResult["status_code"] == 0) { $applicationUid = $arrayResult["caseId"]; $result = $ws->derivateCase($messageEventDefinitionUserUid, $applicationUid, 1); $flagCatched = true; //Counter $counterStartMessageEvent++; } } break; case "INTERMEDIATE": $criteria = new \Criteria("workflow"); $criteria->addSelectColumn(\AppDelegationPeer::APP_UID); $criteria->addSelectColumn(\AppDelegationPeer::DEL_INDEX); $criteria->addSelectColumn(\AppDelegationPeer::USR_UID); $criteria->add(\AppDelegationPeer::PRO_UID, $processUid, \Criteria::EQUAL); $criteria->add(\AppDelegationPeer::TAS_UID, $taskUid, \Criteria::EQUAL); $criteria->add(\AppDelegationPeer::DEL_THREAD_STATUS, "OPEN", \Criteria::EQUAL); $criteria->add(\AppDelegationPeer::DEL_FINISH_DATE, null, \Criteria::ISNULL); $rsCriteria = \AppDelegationPeer::doSelectRS($criteria); $rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC); while ($rsCriteria->next()) { $row = $rsCriteria->getRow(); $applicationUid = $row["APP_UID"]; $delIndex = $row["DEL_INDEX"]; $userUid = $row["USR_UID"]; $arrayApplicationData = $case->loadCase($applicationUid); if (\G::replaceDataField($messageEventDefinitionCorrelation, $arrayApplicationData["APP_DATA"]) == $messageApplicationCorrelation) { //"Unpause" and derivate Case $arrayApplicationData["APP_DATA"] = array_merge($arrayApplicationData["APP_DATA"], $arrayVariable); $arrayResult = $case->updateCase($applicationUid, $arrayApplicationData); $result = $ws->derivateCase($userUid, $applicationUid, $delIndex); $flagCatched = true; } } //Counter if ($flagCatched) { $counterIntermediateCatchMessageEvent++; } break; } //Message-Application catch if ($flagCatched) { $result = $messageApplication->update($messageApplicationUid, array("MSGAPP_STATUS" => "READ")); } $counter++; //Progress bar $messageApplication->frontEndShow("BAR", "Message-Events (unread): " . $counter . "/" . $totalMessageEvent . " " . $messageApplication->progressBar($totalMessageEvent, $counter)); $flagNextRecords = true; } } while ($flagNextRecords); $messageApplication->frontEndShow("TEXT", "Total Message-Events unread: " . $totalMessageEvent); $messageApplication->frontEndShow("TEXT", "Total cases started: " . $counterStartMessageEvent); $messageApplication->frontEndShow("TEXT", "Total cases continued: " . $counterIntermediateCatchMessageEvent); $messageApplication->frontEndShow("TEXT", "Total Message-Events pending: " . ($totalMessageEvent - ($counterStartMessageEvent + $counterIntermediateCatchMessageEvent))); $messageApplication->frontEndShow("END"); } catch (\Exception $e) { throw $e; } }
/** * Get process list for start case * * @param string $usrUid id of user * @param string $typeView type of view * * return array Return an array with process list that the user can start. */ public function getCasesListStarCase($usrUid, $typeView) { try { Validator::usrUid($usrUid, '$usr_uid'); $case = new \Cases(); $response = $case->getProcessListStartCase($usrUid, $typeView); return $response; } catch (\Exception $e) { throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()); } }
/** * Delete Process * * @param string $processUid * @param bool $checkCases * * return bool Return true, if is succesfully * * @access public DEPRECATED public function deleteProcess($processUid, $checkCases = true) { if ($checkCases) { $process = new \Process(); $arrayCases = $process->getCasesCountInAllProcesses($processUid); $sum = 0; if (isset($arrayCases[$processUid]) && count($arrayCases[$processUid]) > 0) { foreach ($arrayCases[$processUid] as $value) { $sum = $sum + $value; } } if ($sum > 0) { throw (new \Exception("You can't delete the process, because it has $sum cases")); } } $processMap = new \processMap(); return $processMap->deleteProcess($processUid); }*/ public function deleteProcess($sProcessUID) { try { G::LoadClass('case'); G::LoadClass('reportTables'); //Instance all classes necesaries $oProcess = new Process(); $oDynaform = new Dynaform(); $oInputDocument = new InputDocument(); $oOutputDocument = new OutputDocument(); $oTrigger = new Triggers(); $oRoute = new Route(); $oGateway = new Gateway(); $oEvent = new Event(); $oSwimlaneElement = new SwimlanesElements(); $oConfiguration = new Configuration(); $oDbSource = new DbSource(); $oReportTable = new ReportTables(); $oCaseTracker = new CaseTracker(); $oCaseTrackerObject = new CaseTrackerObject(); //Delete the applications of process $oCriteria = new Criteria('workflow'); $oCriteria->add(ApplicationPeer::PRO_UID, $sProcessUID); $oDataset = ApplicationPeer::doSelectRS($oCriteria); $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC); $oDataset->next(); $oCase = new Cases(); while ($aRow = $oDataset->getRow()) { $oCase->removeCase($aRow['APP_UID']); $oDataset->next(); } //Delete the tasks of process $oCriteria = new Criteria('workflow'); $oCriteria->add(TaskPeer::PRO_UID, $sProcessUID); $oDataset = TaskPeer::doSelectRS($oCriteria); $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC); $oDataset->next(); while ($aRow = $oDataset->getRow()) { $this->deleteTask($aRow['TAS_UID']); $oDataset->next(); } //Delete the dynaforms of process $oCriteria = new Criteria('workflow'); $oCriteria->add(DynaformPeer::PRO_UID, $sProcessUID); $oDataset = DynaformPeer::doSelectRS($oCriteria); $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC); $oDataset->next(); while ($aRow = $oDataset->getRow()) { $oDynaform->remove($aRow['DYN_UID']); $oDataset->next(); } //Delete the input documents of process $oCriteria = new Criteria('workflow'); $oCriteria->add(InputDocumentPeer::PRO_UID, $sProcessUID); $oDataset = InputDocumentPeer::doSelectRS($oCriteria); $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC); $oDataset->next(); while ($aRow = $oDataset->getRow()) { $oInputDocument->remove($aRow['INP_DOC_UID']); $oDataset->next(); } //Delete the output documents of process $oCriteria = new Criteria('workflow'); $oCriteria->add(OutputDocumentPeer::PRO_UID, $sProcessUID); $oDataset = OutputDocumentPeer::doSelectRS($oCriteria); $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC); $oDataset->next(); while ($aRow = $oDataset->getRow()) { $oOutputDocument->remove($aRow['OUT_DOC_UID']); $oDataset->next(); } //Delete the triggers of process $oCriteria = new Criteria('workflow'); $oCriteria->add(TriggersPeer::PRO_UID, $sProcessUID); $oDataset = TriggersPeer::doSelectRS($oCriteria); $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC); $oDataset->next(); while ($aRow = $oDataset->getRow()) { $oTrigger->remove($aRow['TRI_UID']); $oDataset->next(); } //Delete the routes of process $oCriteria = new Criteria('workflow'); $oCriteria->add(RoutePeer::PRO_UID, $sProcessUID); $oDataset = RoutePeer::doSelectRS($oCriteria); $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC); $oDataset->next(); while ($aRow = $oDataset->getRow()) { $oRoute->remove($aRow['ROU_UID']); $oDataset->next(); } //Delete the gateways of process $oCriteria = new Criteria('workflow'); $oCriteria->add(GatewayPeer::PRO_UID, $sProcessUID); $oDataset = GatewayPeer::doSelectRS($oCriteria); $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC); $oDataset->next(); while ($aRow = $oDataset->getRow()) { $oGateway->remove($aRow['GAT_UID']); $oDataset->next(); } //Delete the Event of process $oCriteria = new Criteria('workflow'); $oCriteria->add(EventPeer::PRO_UID, $sProcessUID); $oDataset = EventPeer::doSelectRS($oCriteria); $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC); $oDataset->next(); while ($aRow = $oDataset->getRow()) { $oEvent->remove($aRow['EVN_UID']); $oDataset->next(); } //Delete the swimlanes elements of process $oCriteria = new Criteria('workflow'); $oCriteria->add(SwimlanesElementsPeer::PRO_UID, $sProcessUID); $oDataset = SwimlanesElementsPeer::doSelectRS($oCriteria); $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC); $oDataset->next(); while ($aRow = $oDataset->getRow()) { $oSwimlaneElement->remove($aRow['SWI_UID']); $oDataset->next(); } //Delete the configurations of process $oCriteria = new Criteria('workflow'); $oCriteria->add(ConfigurationPeer::PRO_UID, $sProcessUID); $oDataset = ConfigurationPeer::doSelectRS($oCriteria); $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC); $oDataset->next(); while ($aRow = $oDataset->getRow()) { $oConfiguration->remove($aRow['CFG_UID'], $aRow['OBJ_UID'], $aRow['PRO_UID'], $aRow['USR_UID'], $aRow['APP_UID']); $oDataset->next(); } //Delete the DB sources of process $oCriteria = new Criteria('workflow'); $oCriteria->add(DbSourcePeer::PRO_UID, $sProcessUID); $oDataset = DbSourcePeer::doSelectRS($oCriteria); $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC); $oDataset->next(); while ($aRow = $oDataset->getRow()) { /** * note added by gustavo cruz gustavo-at-colosa-dot-com 27-01-2010 * in order to solve the bug 0004389, we use the validation function Exists * inside the remove function in order to verify if the DbSource record * exists in the Database, however there is a strange behavior within the * propel engine, when the first record is erased somehow the "_deleted" * attribute of the next row is set to true, so when propel tries to erase * it, obviously it can't and trows an error. With the "Exist" function * we ensure that if there is the record in the database, the _delete attribute must be false. * * note added by gustavo cruz gustavo-at-colosa-dot-com 28-01-2010 * I have just identified the source of the issue, when is created a $oDbSource DbSource object * it's used whenever a record is erased or removed in the db, however the problem * it's that the same object is used every time, and the delete method invoked * sets the _deleted attribute to true when its called, of course as we use * the same object, the first time works fine but trowns an error with the * next record, cos it's the same object and the delete method checks if the _deleted * attribute it's true or false, the attrib _deleted is setted to true the * first time and later is never changed, the issue seems to be part of * every remove function in the model classes, not only DbSource * i recommend that a more general solution must be achieved to resolve * this issue in every model class, to prevent future problems. */ $oDbSource->remove($aRow['DBS_UID'], $sProcessUID); $oDataset->next(); } //Delete the supervisors $oCriteria = new Criteria('workflow'); $oCriteria->add(ProcessUserPeer::PRO_UID, $sProcessUID); ProcessUserPeer::doDelete($oCriteria); //Delete the object permissions $oCriteria = new Criteria('workflow'); $oCriteria->add(ObjectPermissionPeer::PRO_UID, $sProcessUID); ObjectPermissionPeer::doDelete($oCriteria); //Delete the step supervisors $oCriteria = new Criteria('workflow'); $oCriteria->add(StepSupervisorPeer::PRO_UID, $sProcessUID); StepSupervisorPeer::doDelete($oCriteria); //Delete the report tables $oCriteria = new Criteria('workflow'); $oCriteria->add(ReportTablePeer::PRO_UID, $sProcessUID); $oDataset = ReportTablePeer::doSelectRS($oCriteria); $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC); $oDataset->next(); while ($aRow = $oDataset->getRow()) { $oReportTable->deleteReportTable($aRow['REP_TAB_UID']); $oDataset->next(); } //Delete case tracker configuration $oCaseTracker->remove($sProcessUID); //Delete case tracker objects $oCriteria = new Criteria('workflow'); $oCriteria->add(CaseTrackerObjectPeer::PRO_UID, $sProcessUID); ProcessUserPeer::doDelete($oCriteria); //Delete the process try { $oProcess->remove($sProcessUID); } catch (Exception $oError) { throw ($oError); } return true; } catch (Exception $oError) { throw ($oError); } }
/** * Return starting task by users * * @param string $sProcessUID {@min 32} {@max 32} * @param string $sUserUID {@min 32} {@max 32} * * return array * * @access public */ public function getProjectStartingTaskUsers($sProcessUID, $sUserUID) { try { Validator::proUid($sProcessUID, '$prj_uid'); Validator::usrUid($sUserUID, '$usr_uid'); $aUsers = array(); \G::LoadClass('case'); $oCase = new \Cases(); $startTasks = $oCase->getStartCases($sUserUID); if (sizeof($startTasks) > 1) { foreach ($startTasks as $task) { if (isset($task['pro_uid']) && $task['pro_uid'] == $sProcessUID) { $taskValue = explode('(', $task['value']); $tasksLastIndex = count($taskValue) - 1; $taskValue = explode(')', $taskValue[$tasksLastIndex]); $aUsers[] = array('act_uid' => $task['uid'], 'act_name' => $taskValue[0]); } } } if (sizeof($aUsers) < 1) { throw new \Exception(\G::LoadTranslation("ID_USER_NOT_INITIAL ACTIVITIES", array($sUserUID))); } return $aUsers; } catch (Exception $e) { throw $e; } }