/** * * @param Model_Tudu_Tudu $tudu * @param Model_Tudu_Extension_Flow $flow */ public function renewTuduFlow(Model_Tudu_Tudu &$tudu, Model_Tudu_Extension_Flow &$flow) { // 手动工作流,可修改当前步骤或不同意的后续步骤 $isExceed = false; $prev = $flow->currentStepId ? $flow->currentStepId : '^head'; $next = '^end'; if ($tudu->operation != 'forward' && ($tudu->reviewer || $tudu->to)) { foreach ($flow->steps as $key => $item) { $stepId = $item['stepid']; foreach ($item['section'] as $idx => $section) { if ($isExceed) { $flow->removeStepSection($stepId, $idx); if (empty($flow->steps[$stepId]['section'])) { $flow->deleteStep($stepId); } continue; } foreach ($section as $k => $u) { if (isset($u['status']) && $u['status'] >= 2 && $item['type'] == 1) { $isExceed = true; $prev = $stepId; } if ($isExceed && $u['status'] < 2) { $flow->removeStepSection($key, $idx); } } } } } if ($tudu->operation == 'forward') { if (isset($flow->steps[$flow->currentStepId])) { $next = $flow->steps[$flow->currentStepId]['next']; } } $flowTo = null; if ($tudu->reviewer) { $reviewer = $tudu->reviewer; $stepId = $flow->addStep(array('type' => Dao_Td_Tudu_Step::TYPE_EXAMINE, 'prev' => $prev, 'next' => $next)); $flowTo = $prev = $stepId; $prev = $stepId; foreach ($reviewer as $item) { $flow->addStepSection($stepId, $item); } $tudu->reviewer = $flow->getStepSection($stepId, 0); } if ($tudu->to) { $to = $tudu->to; $stepId = $flow->addStep(array('type' => $tudu->acceptMode ? Dao_Td_Tudu_Step::TYPE_CLAIM : Dao_Td_Tudu_Step::TYPE_EXECUTE, 'prev' => $prev, 'next' => $next)); foreach ($to as $item) { $flow->addStepSection($stepId, $item); } $to = $flow->getStepSection($stepId, 0); foreach ($to as $k => $t) { if (isset($tudu->to[0][$t['username']]) && isset($tudu->to[0][$t['username']]['percent'])) { $to[$k]['percent'] = $tudu->to[0][$t['username']]['percent']; continue; } } $tudu->to = $to; if (0 !== strpos($prev, '^')) { $flow->updateStep($prev, array('next' => $stepId)); } if (null === $flowTo) { $flowTo = $stepId; } } $isComplete = true; if ($tudu->operation == 'forward') { $flow->complete(); } if ($flow->currentStepId && 0 !== strpos($flow->currentStepId, '^')) { $step = $flow->getStep($flow->currentStepId); $sec = $flow->getStepSection($step['stepid'], $step['currentSection']); if ($sec) { foreach ($sec as $u) { if (!empty($u['status']) && $u['status'] < 2) { $isComplete = false; break; } } } } if ($isComplete) { $flow->flowTo($flowTo); } // 到头了 if (0 === strpos($flow->currentStepId, '^') || !$flow->currentStepId) { return; } $step = $flow->getStep($flow->currentStepId); $su = $flow->getStepSection($flow->currentStepId); $users = array(); $to = $tudu->to; foreach ($su as $k => $u) { $users[$u['username']] = array('uniqueid' => $u['uniqueid'], 'username' => $u['username'], 'truename' => $u['truename'], 'email' => $u['username']); foreach ($to as $t) { if ($t['uniqueid'] == $u['uniqueid'] && !empty($t['percent'])) { $users[$u['username']]['percent'] = $t['percent']; break; } } } if ($step['type'] == 1) { if (!$tudu->reviewer) { $tudu->reviewer = $users; } } else { if ($step['type'] == 2) { $tudu->acceptMode = 1; } if (!$tudu->to) { $tudu->to = $users; } } }
/** * * @param Model_Tudu_Tudu $tudu * @param Model_Tudu_Extension_Flow $flow */ public function renewTuduFlow(Model_Tudu_Tudu &$tudu, Model_Tudu_Extension_Flow &$flow) { // 手动工作流,可修改当前步骤或不同意的后续步骤 $isExceed = false; $prev = '^head'; if ($tudu->reviewer || $tudu->to) { foreach ($flow->steps as $key => $item) { $stepId = $item['stepid']; foreach ($item['section'] as $idx => $section) { if ($isExceed) { $flow->deleteStep($stepId); continue; } foreach ($section as $k => $u) { if (isset($u['status']) && $u['status'] >= 2) { $isExceed = true; $prev = $stepId; } if ($isExceed && $u['status'] < 2) { $flow->removeStepSection($key, $idx); } } if ($isExceed && empty($item['section'])) { $prev = $item['prev']; $flow->deleteStep($stepId); } } } } $flowTo = null; if ($tudu->reviewer) { $reviewer = $tudu->reviewer; $stepId = $flow->addStep(array('type' => Dao_Td_Tudu_Step::TYPE_EXAMINE, 'prev' => $prev)); $flowTo = $prev = $stepId; foreach ($reviewer as $item) { $flow->addStepSection($stepId, $item); } $tudu->reviewer = $flow->getStepSection($stepId, 0); } if ($tudu->to) { $to = $tudu->to; $stepId = $flow->addStep(array('type' => $tudu->acceptMode ? Dao_Td_Tudu_Step::TYPE_CLAIM : Dao_Td_Tudu_Step::TYPE_EXECUTE, 'prev' => $prev)); foreach ($to as $item) { $flow->addStepSection($stepId, $item); } $tudu->to = $flow->getStepSection($stepId, 0); if (0 !== strpos($prev, '^')) { $flow->updateStep($prev, array('next' => $stepId)); } if (null === $flowTo) { $flowTo = $stepId; } } $flow->flowTo($flowTo); $step = $flow->getStep($flow->currentStepId); if ($step['type'] == 1) { if (!$tudu->reviewer) { $tudu->reviewer = $flow->getStepSection($flow->currentStepId); } } else { if (!$tudu->to) { $tudu->to = $flow->getStepSection($flow->currentStepId); } } }