/** * 转发图度 * * @param $tudu * @param $output */ public function forward(Tudu_Model_Tudu_Entity_Tudu $tudu, &$output) { $user = self::getResource(self::RESOURCE_NAME_USER); $error = null; $time = time(); /* @var $daoTudu Dao_Td_Tudu_Tudu */ $daoTudu = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Tudu', Tudu_Dao_Manager::DB_TS); /* @var $daoPost Dao_Td_Tudu_Post */ $daoPost = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Post', Tudu_Dao_Manager::DB_TS); do { if (!$tudu->tuduId) { $error = 'tudu not exists'; break; } $fromTudu = $daoTudu->getTuduById($user->uniqueId, $tudu->tuduId); $isSender = $fromTudu->sender == $user->userName; $isAccepter = in_array($user->userName, $fromTudu->accepter); if (null === $fromTudu) { $error = 'tudu not exists'; break; } // 转发权限 if (!$user->getAccess()->isAllowed(Tudu_Access::PERM_FORWARD_TUDU)) { $error = 'perm deny forward tudu'; break; } // 图度组 if ($fromTudu->isTuduGroup) { $error = 'deny forward tudugroup'; break; } // 不是执行人 if (!$isAccepter) { $error = 'forbid non accepter forward'; break; } } while (false); if (null !== $error) { require_once 'Tudu/Model/Tudu/Exception.php'; throw new Tudu_Model_Tudu_Exception($error); } // 转发同时修改部分图度属性 $modify = false; if ($user->getAccess()->isAllowed(Tudu_Access::PERM_FORWARD_TUDU)) { if ($isSender) { $modify = true; } else { $boards = $this->_getBoards($user->orgId); $board = $boards[$tudu->boardId]; $isModerator = array_key_exists($this->_user->userId, $board['moderators']); $isSuperModerator = !empty($board['parentid']) && array_key_exists($this->_user->userId, $boards[$board['parentid']]['moderators']); if ($isModerator || $isSuperModerator) { $modify = true; } } } $tuduParams = array('lastposttime' => time(), 'lastposter' => $user->trueName, 'lastforward' => implode("\n", array($user->trueName, $time))); // 允许修改图度参数 if ($modify) { $tuduParams = array_merge($tudu->getAttributes(), $tuduParams); } // 处理执行人 $to = $tudu->to; foreach ($to as $k => $item) { if ($fromTudu->selfPercent < 100) { $to[$k]['percent'] = $fromTudu->selfPercent; } } $tudu->to = $to; $to = array(); foreach ($fromTudu->to as $k => $item) { if ($k != $user->userName) { $to[] = $k . ' ' . $item[0]; } } $tudu->to = array_merge($tudu->to, Tudu_Tudu_Storage::formatRecipients(implode("\n", $to))); if ($fromTudu->selfPercent >= 100) { $tudu->to = array_merge($tudu->to, array($user->userName => array('email' => $user->userName, 'truename' => $user->trueName, 'percent' => $fromTudu->selfPercent))); } $tuduParams['to'] = Tudu_Model_Entity_Tudu::formatReceiver($tudu->to); $tuduParams['cc'] = Tudu_Model_Entity_Tudu::formatReceiver($tuduParams['cc']); $tuduParams['bcc'] = Tudu_Model_Entity_Tudu::formatReceiver($tuduParams['bcc']); // 更新图度 if (!$daoTudu->updateTudu($tudu->tuduId, $tuduParams)) { require_once 'Tudu/Model/Tudu/Exception.php'; throw new Tudu_Model_Tudu_Exception('Save tudu failed'); } // 发送转发回复 $attachments = $tudu->getAttachments(); $attachNum = 0; foreach ($attachments as $attach) { if ($attach['isattach']) { $attachNum++; } } $postId = $daoPost->createPost(array('orgid' => $tudu->orgId, 'boardid' => $tudu->boardId, 'tuduid' => $tudu->tuduId, 'uniqueid' => $user->uniqueId, 'postid' => Dao_Td_Tudu_Post::getPostId(), 'poster' => $user->trueName, 'email' => $user->userName, 'content' => $tudu->content, 'attachnum' => $attachNum, 'isfirst' => 0)); if (!$postId) { require_once 'Tudu/Model/Tudu/Exception.php'; throw new Tudu_Model_Tudu_Exception('Save post failed'); } $daoPost->sendPost($tudu->tuduId, $postId); // 添加附件 /* @var $daoFile Dao_Td_Attachment_File */ $daoFile = Tudu_Dao_Manager::getDao('Dao_Td_Attachment_File', Tudu_Dao_Manager::DB_TS); foreach ($attachments as $attach) { $daoFile->addPost($tudu->tuduId, $postId, $attach['fileid'], (bool) $attach['isattach']); } // 发送图度 $this->sendTudu($tudu); // 加上转发标签 $daoTudu->addLabel($tudu->tuduId, $user->uniqueId, '^w'); $sqsParam = array('tsid' => $user->tsId, 'tuduid' => $tudu->tuduId, 'from' => $user->userName, 'uniqueid' => $user->uniqueId, 'server' => $_SERVER['HTTP_HOST'], 'type' => $tudu->type, 'ischangedCc' => $tudu->cc ? true : false); $httpsqs = self::getResource(self::RESOURCE_NAME_HTTPSQS); $httpsqs->put(implode(' ', array('tudu', 'update', '', http_build_query($sqsParam))), 'tudu'); return $tudu->tuduId; }
/** * 流动到指定(下一步)步骤 * * @param Model_Tudu_Tudu $tudu */ public function flowTo(Model_Tudu_Tudu &$tudu, $stepId = null) { /* @var $daoStep Dao_Td_Tudu_Step */ $daoStep = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Step', Tudu_Dao_Manager::DB_TS); /* @var $daoStep Dao_Td_Tudu_Tudu */ $daoTudu = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Tudu', Tudu_Dao_Manager::DB_TS); $steps = $daoStep->getSteps(array('tuduid' => $tudu->tuduId))->toArray('stepid'); // 默认流动到下一步 if (null === $stepId) { $currentStep = $steps[$tudu->stepId]; // 是否需要流到下一步 $users = $daoStep->getUsers($tudu->tuduId, $tudu->stepId); $currentUser = $users[$tudu->uniqueId]; $nextSection = false; $nextProcessIndex = null; unset($users[$tudu->uniqueId]); $nextUsers = array(); foreach ($users as $u) { // 不需要转到下一步 if ($u['processindex'] == $currentUser['processindex'] && $u['status'] < 2) { return; } // 本步骤有下一节点 if (null === $nextProcessIndex && $u['processindex'] > $currentUser['processindex']) { $nextSection = true; $nextProcessIndex = $u['processindex']; } if (null !== $nextProcessIndex && $u['processindex'] === $nextProcessIndex) { $arr = explode(' ', $u['userinfo']); $nextUsers[$arr[0]] = array('email' => $arr[0], 'truename' => $arr[1]); $daoStep->updateUser($tudu->tuduId, $tudu->stepId, $u['uniqueid'], array('status' => 1)); } } if (!$nextSection) { $stepId = $currentStep['nextstepid']; if (isset($steps[$stepId])) { $nextStep = $steps[$stepId]; $users = $daoStep->getUsers($tudu->tuduId, $stepId); $procIndex = null; $nextUsers = array(); foreach ($users as $u) { if ($procIndex === null) { $procIndex = $u['processindex']; } if (null !== $procIndex && $u['processindex'] !== $procIndex) { break; } $arr = explode(' ', $u['userinfo']); $nextUsers[$arr[0]] = array('email' => $arr[0], 'truename' => $arr[1]); $daoStep->updateUser($tudu->tuduId, $stepId, $u['uniqueid'], array('status' => 1)); } if ($nextStep['type'] == self::STEP_TYPE_EXAMINE) { $tudu->reviewer = array($nextUsers); } else { $tudu->to = $nextUsers; } } } else { $stepId = $tudu->stepId; if ($currentStep['type'] == self::STEP_TYPE_EXAMINE) { $tudu->reviewer = array($nextUsers); } else { $tudu->to = $nextUsers; } } } $updateStatus = false; if (isset($steps[$stepId]) && empty($nextSection)) { $nextStep = $steps[$stepId]; $nextStepUsers = $daoStep->getUsers($tudu->tuduId, $nextStep['stepid']); $nextIndex = null; if ($nextStep['type'] == self::STEP_TYPE_EXAMINE) { $reviewer = array(); foreach ($nextStepUsers as $item) { if (null === $nextIndex) { $nextIndex = $item['processindex']; } if (null !== $nextIndex && $item['processindex'] != $nextIndex) { break; } list($userName, $trueName) = explode(' ', $item['userinfo']); $reviewer[] = array('email' => $userName, 'truename' => $trueName); // 更新上一步骤用户状态 if ($item['status'] > 1) { $updateStatus = true; $daoStep->updateUser($tudu->tuduId, $nextStep['stepid'], $item['uniqueid'], array('status' => 1)); } } $tudu->reviewer = array($reviewer); } elseif ($nextStep['type'] == self::STEP_TYPE_EXECUTE) { $users = array(); // 准备执行人 foreach ($nextStepUsers as $item) { list($email, $trueName) = explode(' ', $item['userinfo']); $users[$email] = array('email' => $email, 'truename' => $trueName, 'percent' => (int) $item['percent']); // 更新上一步骤用户状态 if ($item['status'] > 1) { $updateStatus = true; $daoStep->updateUser($tudu->tuduId, $nextStep['stepid'], $item['uniqueid'], array('status' => 1)); $daoTudu->updateProgress($tudu->tuduId, $item['uniqueid'], 0); if ($tudu->parentId) { $daoTudu->calParentsProgress($tudu->parentId); } } } $tudu->reviewer = null; $tudu->to = Tudu_Tudu_Storage::formatRecipients($users); // 更新图度接收人信息 //$manager->updateTudu($tudu['tuduid'], array('to' => Tudu_Tudu_Storage::formatReceiver($users))); } if ($updateStatus) { $daoStep->updateStep($tudu->tuduId, $nextStep['stepid'], array('status' => 0)); } $stepId = $nextStep['stepid']; $sendParam['flowid'] = $tudu->flowId; $sendParam['nstepid'] = $stepId; $tudu->stepId = $stepId; } elseif (!$stepId) { $stepId = '^break'; $tudu->stepId = '^break'; } if ($stepId == '^break') { $tudu->to = array('email' => $tudu->from['username'], 'truename' => $tudu->from['truename']); // 更新图度接收人信息 $daoTudu->updateTudu($tudu->tuduId, array('to' => $tudu->from['username'] . ' ' . $tudu->from['truename'])); } // 准备发送 $updateParams = array(); if ($stepId != '^end') { // 移除原执行人 if (!$tudu->reviewer) { $accepters = $daoTudu->getAccepters($tudu->tuduId); $to = $tudu->to; foreach ($accepters as $item) { list($email, ) = explode(' ', $item['accepterinfo'], 2); // 移除执行人角色,我执行标签 if (!empty($to) && !array_key_exists($email, $to) && $daoTudu->getChildrenCount($tudu->tuduId, $item['uniqueid']) <= 0) { $daoTudu->removeAccepter($tudu->tuduId, $item['uniqueid']); $daoTudu->deleteLabel($tudu->tuduId, $item['uniqueid'], '^a'); } } } require_once 'Model/Tudu/Compose/Send.php'; $modelSend = new Model_Tudu_Compose_Send(); $modelSend->send($tudu); // 执行人自动接受图度 $lastUpdateTime = null; if ($stepId != '^break' && $stepId != '^head' && isset($steps[$stepId]) && $steps[$stepId]['type'] != Dao_Td_Tudu_Step::TYPE_EXAMINE) { if ($steps[$stepId]['type'] == Dao_Td_Tudu_Step::TYPE_EXECUTE) { $users = $daoStep->getUsers($tudu->tuduId, $stepId); foreach ($nextStepUsers as $item) { $daoTudu->updateTuduUser($tudu->tuduId, $item['uniqueid'], array('accepttime' => time(), 'tudustatus' => Dao_Td_Tudu_Tudu::STATUS_DOING)); $lastUpdateTime = time(); } $tudu->acceptMode = 0; // 认领模式 } else { if ($steps[$stepId]['type'] == Dao_Td_Tudu_Step::TYPE_CLAIM) { $tudu->acceptMode = 0; $tudu->acceptTime = 0; } } } } $tudu->stepId = $stepId; $attrs = $tudu->getStorageParams(); unset($attrs['from'], $attrs['reviewer']); if (!empty($lastUpdateTime)) { $attrs['lastupdatetime'] = $lastUpdateTime; } $daoTudu->updateTudu($tudu->tuduId, $attrs); }
/** * 格式化接收人(抄送,接收,审批等)参数 * * @param $key * @param $suffix */ private function _getReceiver($params, $name, $suffix = '') { $ret = array(); if (isset($params[$name . 'idx' . $suffix]) && is_array($params[$name . 'idx' . $suffix])) { $recIdx = $params[$name . 'idx' . $suffix]; $rec = array(); foreach ($recIdx as $index) { $info = $params[$name . '-' . $index . $suffix]; $arr = explode(' ', $info, 2); $item = array('truename' => $arr[1], 'email' => $arr[0]); if (isset($params[$name . '-percent-' . $index . $suffix])) { $item['percent'] = (int) $params[$name . '-percent-' . $index . $suffix]; } if (!$item['email']) { $ret[] = $item; } else { $ret[$item['email']] = $item; } } } else { if ($name == 'to' && $suffix) { $name = 'ch-' . $name; } if (isset($params[$name . $suffix])) { $ret = Tudu_Tudu_Storage::formatRecipients($params[$name . $suffix]); } } return $ret; }
/** * * @param $tudu */ public function preflowRejectUsers(Tudu_Tudu_Storage_Tudu &$tudu) { if ($tudu->stepId == '^head' || $tudu->stepId == '^break') { $tudu->to = Tudu_Tudu_Storage::formatRecipients($tudu->from); } else { $users = $this->getStepUsers($tudu->tuduId, $tudu->stepId); $to = array(); foreach ($users as $item) { $to[] = $item['userinfo']; } $tudu->to = Tudu_Tudu_Storage::formatRecipients(implode("\n", $to)); } return true; }
/** * 设置字段数据 * * @param $name * @param $value */ public function setAttribute($name, $value) { $name = strtolower($name); if (in_array($name, array('to', 'cc', 'bcc', 'reviewer')) && is_string($value)) { $value = Tudu_Tudu_Storage::formatRecipients($value); } $this->_attrs[$name] = $value; }
/** * 执行部同意流程 * @param Tudu_Model_Tudu_Entity_Tudu $tudu */ protected function _disAgree(Tudu_Model_Tudu_Entity_Tudu $tudu) { $daoStep = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Step', Tudu_Dao_Manager::DB_TS); if ($tudu->flowId) { //return $this->flowReviewReject($tudu); return; } $daoStep->updateUser($tudu->tuduId, $tudu->stepId, $tudu->uniqueId, array('status' => 3)); $steps = $daoStep->getSteps(array('tuduid' => $tudu->tuduId))->toArray('stepid'); if (!isset($steps[$tudu->stepId])) { return false; } $step = $steps[$tudu->stepId]; $prevId = $step['prevstepid']; $toStepId = $prevId; do { if (!isset($steps[$prevId])) { $prevId = '^head'; break; } $prev = $steps[$prevId]; if ($prev['type'] == 0) { break; } $prevId = $prev['prevstepid']; $toStepId = $prev['stepid']; if ($prevId == '^head') { break; } } while ($prev['type'] == 0); $tudu->stepId = $toStepId; if ($toStepId == '^head' || $toStepId == '^trunk') { $tudu->to = Tudu_Tudu_Storage::formatRecipients($tudu->from); } else { $users = $daoStep->getUsers($tudu->tuduId, $toStepId); $to = array(); foreach ($users as $item) { $to[] = $item['userinfo']; } $tudu->to = Tudu_Tudu_Storage::formatRecipients(implode("\n", $to)); } }