public static function DeleteByWorkflow($workflowId) { global $DB; $workflowId = trim($workflowId); if (strlen($workflowId) <= 0) throw new Exception("workflowId"); $dbRes = $DB->Query( "SELECT ID ". "FROM b_bp_task ". "WHERE WORKFLOW_ID = '".$DB->ForSql($workflowId)."' " ); while ($arRes = $dbRes->Fetch()) { $taskId = intval($arRes["ID"]); $dbResUser = $DB->Query("SELECT USER_ID FROM b_bp_task_user WHERE TASK_ID = ".$taskId." "); while ($arResUser = $dbResUser->Fetch()) CUserCounter::Decrement($arResUser["USER_ID"], 'bp_tasks', '**'); $DB->Query("DELETE FROM b_bp_task_user WHERE TASK_ID = ".$taskId." ", true); foreach (GetModuleEvents("bizproc", "OnTaskDelete", true) as $arEvent) ExecuteModuleEventEx($arEvent, array($taskId)); } $DB->Query( "DELETE FROM b_bp_task ". "WHERE WORKFLOW_ID = '".$DB->ForSql($workflowId)."' ", true ); }
public static function Update($id, $arFields) { global $DB; $id = intval($id); if ($id <= 0) { throw new Exception("id"); } self::ParseFields($arFields, $id); $strUpdate = $DB->PrepareUpdate("b_bp_task", $arFields); $strSql = "UPDATE b_bp_task SET " . "\t" . $strUpdate . ", " . "\tMODIFIED = " . $DB->CurrentTimeFunction() . " " . "WHERE ID = " . intval($id) . " "; $DB->Query($strSql, False, "File: " . __FILE__ . "<br>Line: " . __LINE__); if (is_set($arFields, "USERS")) { $dbResUser = $DB->Query("SELECT USER_ID FROM b_bp_task_user WHERE TASK_ID = " . intval($id) . " "); while ($arResUser = $dbResUser->Fetch()) { CUserCounter::Decrement($arResUser["USER_ID"], 'bp_tasks', '**'); } $DB->Query("DELETE FROM b_bp_task_user WHERE TASK_ID = " . intval($id) . " "); $ar = array(); foreach ($arFields["USERS"] as $userId) { $userId = intval($userId); if (in_array($userId, $ar)) { continue; } $DB->Query("INSERT INTO b_bp_task_user (USER_ID, TASK_ID) " . "VALUES (" . intval($userId) . ", " . intval($id) . ") "); CUserCounter::Increment($userId, 'bp_tasks', '**'); $ar[] = $userId; } } foreach (GetModuleEvents("bizproc", "OnTaskUpdate", true) as $arEvent) { ExecuteModuleEventEx($arEvent, array($id, $arFields)); } return $id; }
public static function Update($id, $arFields) { global $DB; $id = intval($id); if ($id <= 0) { throw new Exception("id"); } self::ParseFields($arFields, $id); $strUpdate = $DB->PrepareUpdate("b_bp_task", $arFields); $strSql = "UPDATE b_bp_task SET " . "\t" . $strUpdate . ", " . "\tMODIFIED = " . $DB->CurrentTimeFunction() . " " . "WHERE ID = " . intval($id) . " "; $DB->Query($strSql, False, "File: " . __FILE__ . "<br>Line: " . __LINE__); $removedUsers = array(); if (is_set($arFields, "USERS")) { $dbResUser = $DB->Query("SELECT USER_ID FROM b_bp_task_user WHERE TASK_ID = " . intval($id) . " "); while ($arResUser = $dbResUser->Fetch()) { CUserCounter::Decrement($arResUser["USER_ID"], 'bp_tasks', '**'); $removedUsers[] = $arResUser["USER_ID"]; } $DB->Query("DELETE FROM b_bp_task_user WHERE TASK_ID = " . intval($id) . " "); $ar = array(); foreach ($arFields["USERS"] as $userId) { $userId = intval($userId); if (in_array($userId, $ar)) { continue; } $DB->Query("INSERT INTO b_bp_task_user (USER_ID, TASK_ID, ORIGINAL_USER_ID) " . "VALUES (" . intval($userId) . ", " . intval($id) . ", " . intval($userId) . ") "); CUserCounter::Increment($userId, 'bp_tasks', '**'); $ar[] = $userId; } } $userStatuses = array(); if (isset($arFields['STATUS']) && $arFields['STATUS'] > CBPTaskStatus::Running) { $dbResUser = $DB->Query("SELECT USER_ID FROM b_bp_task_user WHERE TASK_ID = " . $id . " AND STATUS = " . CBPTaskUserStatus::Waiting); while ($arResUser = $dbResUser->Fetch()) { CUserCounter::Decrement($arResUser["USER_ID"], 'bp_tasks', '**'); if ($arFields['STATUS'] == CBPTaskStatus::Timeout) { $userStatuses[$arResUser["USER_ID"]] = CBPTaskUserStatus::No; } else { $removedUsers[] = $arResUser["USER_ID"]; } } if ($arFields['STATUS'] == CBPTaskStatus::Timeout) { $DB->Query("UPDATE b_bp_task_user SET STATUS = " . CBPTaskUserStatus::No . ", DATE_UPDATE = " . $DB->CurrentTimeFunction() . " WHERE TASK_ID = " . $id . " AND STATUS = " . CBPTaskUserStatus::Waiting); } else { $DB->Query("DELETE FROM b_bp_task_user WHERE TASK_ID = " . $id . " AND STATUS = " . CBPTaskUserStatus::Waiting); } } foreach (GetModuleEvents("bizproc", "OnTaskUpdate", true) as $arEvent) { ExecuteModuleEventEx($arEvent, array($id, $arFields)); } if ($removedUsers) { $arFields['USERS_REMOVED'] = $removedUsers; } if ($userStatuses) { $arFields['USERS_STATUSES'] = $userStatuses; } self::onTaskChange($id, $arFields, CBPTaskChangedStatus::Update); return $id; }
public function MarkCompleted($id, $userId) { global $DB; $id = intval($id); if ($id <= 0) { throw new Exception("id"); } $userId = intval($userId); if ($userId <= 0) { throw new Exception("userId"); } $DB->Query("DELETE FROM b_bp_task_user WHERE TASK_ID = " . intval($id) . " AND USER_ID = " . intval($userId) . " ", true); $dbRes = $DB->Query("SELECT COUNT(ID) as CNT FROM b_bp_task_user WHERE TASK_ID = " . intval($id) . " "); $arRes = $dbRes->Fetch(); if (intval($arRes["CNT"]) <= 0) { $DB->Query("DELETE FROM b_bp_task WHERE ID = " . intval($id) . " ", true); } CUserCounter::Decrement($userId, 'bp_tasks', '**'); $events = GetModuleEvents("bizproc", "OnTaskMarkCompleted"); while ($arEvent = $events->Fetch()) { ExecuteModuleEventEx($arEvent, array($id, $userId)); } }
public static function DeleteByWorkflow($workflowId) { global $DB; $workflowId = trim($workflowId); if (strlen($workflowId) <= 0) { throw new Exception("workflowId"); } $dbRes = $DB->Query("SELECT ID " . "FROM b_bp_task " . "WHERE WORKFLOW_ID = '" . $DB->ForSql($workflowId) . "' "); while ($arRes = $dbRes->Fetch()) { $taskId = intval($arRes["ID"]); $removedUsers = array(); $dbResUser = $DB->Query("SELECT USER_ID, STATUS FROM b_bp_task_user WHERE TASK_ID = " . $taskId . " "); while ($arResUser = $dbResUser->Fetch()) { if ($arResUser['STATUS'] == CBPTaskUserStatus::Waiting) { CUserCounter::Decrement($arResUser["USER_ID"], 'bp_tasks', '**'); } $removedUsers[] = $arResUser['USER_ID']; } $DB->Query("DELETE FROM b_bp_task_user WHERE TASK_ID = " . $taskId . " ", true); self::onTaskChange($taskId, array('USERS_REMOVED' => $removedUsers), CBPTaskChangedStatus::Delete); foreach (GetModuleEvents("bizproc", "OnTaskDelete", true) as $arEvent) { ExecuteModuleEventEx($arEvent, array($taskId)); } } $DB->Query("DELETE FROM b_bp_task " . "WHERE WORKFLOW_ID = '" . $DB->ForSql($workflowId) . "' ", true); }
public static function Decrement($code, $site_id = SITE_ID, $sendPull = true, $decrement = 1) { return CUserCounter::Decrement(CUserCounter::SYSTEM_USER_ID, $code, $site_id, $sendPull, $decrement); }
private static function processUsersCounters($counterId, $operation, $arUsers, $delta) { if (!is_array($arUsers)) { CTaskAssert::logError('[0x9418f293] '); return; } $arUsers = array_unique($arUsers); if ($operation === self::OP_DECREMENT) { foreach ($arUsers as $userId) { $userId = (int) $userId; if ($userId < 1) { CTaskAssert::logError('[0x8886cc18] '); continue; } //$x = '[USER_ID= ' . $userId . '] ' . $counterId . '--'; //soundex($x); CUserCounter::Decrement($userId, $counterId, '**', false, $delta); } } elseif ($operation === self::OP_INCREMENT) { foreach ($arUsers as $userId) { $userId = (int) $userId; if ($userId < 1) { CTaskAssert::logError('[0x01f722e7] '); continue; } //$x = '[USER_ID= ' . $userId . '] ' . $counterId . '+=' . $delta; //soundex($x); CUserCounter::Increment((int) $userId, $counterId, '**', false, $delta); } } else { CTaskAssert::logError('[0x0a5999d4] Invalid operation: ' . $operation); } }