/** * * @param array $params * @return string */ public function addStep(array $params, $fixPos = true) { if (!isset($params['type'])) { return false; } $stepId = isset($params['stepid']) ? $params['stepid'] : Dao_Td_Tudu_Flow::getStepId($this->_attrs['tuduid']); $prev = end($this->_steps); $prevId = !$prev ? Model_Tudu_Flow_Flow::NODE_START : $prev['stepid']; $step = array('stepid' => $stepId, 'type' => $params['type'], 'section' => array(), 'prev' => isset($params['prev']) ? $params['prev'] : $prevId, 'next' => isset($params['next']) ? $params['next'] : Model_Tudu_Flow_Flow::NODE_END); if (!empty($params['subject'])) { $step['subject'] = $params['subject']; } if (!empty($params['description'])) { $step['description'] = $params['description']; } // 上一步 if (!$this->flowId) { if (isset($this->_steps[$step['prev']])) { $next = $this->_steps[$step['prev']]['next']; if ($this->_steps[$step['prev']]['next'] != Model_Tudu_Flow_Flow::NODE_BREAK) { $this->_steps[$step['prev']]['next'] = $stepId; } if (empty($params['next'])) { $step['next'] = $next; } if (0 != strpos($next, '^') && 0 !== strpos($this->_steps[$next]['prev'], '^')) { $this->_steps[$next]['prev'] = $stepId; } } } // 调整排序 if (isset($step['next']) && isset($this->_steps[$step['next']])) { $steps = array(); if (0 !== strpos($this->_steps[$step['next']]['prev'], '^')) { $this->_steps[$step['next']]['prev'] = $stepId; } foreach ($this->_steps as $item) { if ($item['stepid'] == $step['next']) { $steps[$step['stepid']] = $step; } $steps[$item['stepid']] = $item; } $this->_steps = $steps; } else { $this->_steps[$step['stepid']] = $step; } return $stepId; }
/** * * @param Model_Tudu_Tudu $tudu */ public function filter(Model_Tudu_Tudu &$tudu) { $apply = $tudu->getExtension('Model_App_Attend_Tudu_Apply'); if (!$apply) { return; } /* @var $daoApply Dao_App_Attend_Apply */ $daoApply = Tudu_Dao_Manager::getDao('Dao_App_Attend_Apply', Tudu_Dao_Manager::DB_APP); if ($tudu->tuduId) { $this->_fromApply = $daoApply->getApply(array('tuduid' => $tudu->tuduId)); if ($this->_fromApply) { $apply->applyId = $this->_fromApply->applyId; if ($tudu->operation == 'review') { $apply->setAttributes($this->_fromApply->toArray()); } } } // 创建审批流程 if ($tudu->operation == 'send' || $tudu->operation == 'save') { $error = null; $issend = $tudu->operation == 'send'; do { if (!$apply->categoryId) { $error = 'Invalid Category id for attend apply'; break; } if ($issend && (!$apply->startTime && $apply->categoryId != '^checkin')) { $error = 'Invalid Starttime for attend apply'; break; } if ($issend && (!$apply->endTime && $apply->categoryId != '^checkin')) { $error = 'Invalid Endtime for attend apply'; break; } } while (false); // 参数错误 if (null != $error) { require_once 'Model/App/Attend/Exception.php'; $code = false !== strpos($error, 'Category') ? Model_App_Attend_Exception::APPLY_MISSING_CATEGORYID : Model_App_Attend_Exception::APPLY_INVALID_TIME; throw new Model_App_Attend_Exception($error, $code); } /* @var $daoCategory Dao_App_Attend_Category */ $daoCategory = Tudu_Dao_Manager::getDao('Dao_App_Attend_Category', Tudu_Dao_Manager::DB_APP); $category = $daoCategory->getCategory(array('categoryid' => $apply->categoryId, 'orgid' => $apply->orgId)); if (null === $category) { require_once 'Model/App/Attend/Exception.php'; throw new Model_App_Attend_Exception('Category id: [' . $apply->categoryId . '] is not exists', Model_App_Attend_Exception::CATEGORY_NOT_EXISTS); } $tudu->subject = $category->categoryName; // 创建图度工作流 if ($tudu->operation == 'send' && ($apply->status == 0 || $apply->status == 3) && !$this->_fromApply) { require_once 'Model/Tudu/Extension/Flow.php'; $flow = new Model_Tudu_Extension_Flow(array('orgid' => $tudu->orgId)); $steps = $category->flowSteps; $stepIds = array(); foreach ($steps as $item) { $stepId = isset($item['stepid']) ? $item['stepid'] : Dao_Td_Tudu_Flow::getStepId(null); $stepIds[] = $stepId; $flow->addStep(array('stepid' => $stepId, 'prev' => !empty($item['prev']) ? $item['prev'] : '^head', 'next' => !empty($item['next']) ? $item['next'] : '^end', 'type' => 1, 'description' => isset($item['description']) ? $item['description'] : null, 'subject' => isset($item['subject']) ? $item['subject'] : null)); if (is_array($item['sections'])) { foreach ($item['sections'] as $section) { $flow->addStepSection($stepId, $section); } } else { $flow->addStepSection($stepId, $item['sections'], $tudu); } } $flow->flowTo($stepIds[0]); $users = $flow->getCurrentUser(); $flow->isPrepared = true; $tudu->reviewer = $users; $tudu->setExtension($flow); } // 新建的 if (!$this->_fromApply) { if ($apply->target) { list($userName, $trueName) = explode(' ', $apply->target); $addressBook = Tudu_AddressBook::getInstance(); $user = $addressBook->searchUser($userName); if ($user) { $apply->uniqueId = $user['uniqueid']; $apply->userInfo = $userName . ' ' . $trueName; $tudu->bcc = array(array('uniqueid' => $user['uniqueid'], 'username' => $user['username'], 'truename' => $user['truename'])); } } else { $apply->uniqueId = $apply->senderId; $apply->userInfo = $tudu->poster . ' ' . $tudu->email; } } } }