/** * 获取对象实例 * * @param Zend_Db_Adapter_Abstract $db * @return Tudu_Tudu_Manager */ public static function getInstance() { if (null === self::$_instance) { self::$_instance = new self(); } return self::$_instance; }
/** * 发送图度 * * @param $tudu */ public function sendTudu(Tudu_Model_Tudu_Entity_Tudu &$tudu) { /* @var Tudu_Deliver $deliver */ $deliver = Tudu_Tudu_Deliver::getInstance(); $user = self::getResource(self::RESOURCE_NAME_USER); $daoTudu = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Tudu', Tudu_Dao_Manager::DB_TS); $daoGroup = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Group', Tudu_Dao_Manager::DB_TS); $recipients = $deliver->prepareRecipients($user->uniqueId, $user->userId, $tudu); // 公告,发送包含审批,则过滤接收人 if ($tudu->type == 'notice' && $tudu->reviewer) { foreach ($recipients as $uniqueId => $recipient) { if (!array_key_exists($recipient['email'], $tudu->reviewer)) { unset($recipients[$uniqueId]); } } } // 不含审批的修改,需要重新关联执行人 if (!$tudu->isDraft && $tudu->type == 'task' && !$tudu->reviewer) { $accepters = $daoTudu->getAccepters($tudu->tuduId); $to = $tudu->to; foreach ($accepters as $item) { list($email, ) = explode(' ', $item['accepterinfo'], 2); // 移除执行人角色,我执行标签 if (!array_key_exists($email, $to) && $daoGroup->getChildrenCount($tudu->tuduId, $item['uniqueid']) <= 0) { $daoTudu->removeAccepter($tudu->tuduId, $item['uniqueid']); $daoTudu->deleteLabel($tudu->tuduId, $item['uniqueid'], '^a'); } } } // 发送图度到接收人 $deliver->sendTudu($tudu, $recipients); // 计算进度 $progress = $daoTudu->updateProgress($tudu->tuduId, null, null); // 自己发送的任务/会议,自动接受 if ($tudu->type == 'task' || $tudu->type == 'meeting') { if ($tudu->to && array_key_exists($user->userName, $tudu->to) && !$tudu->acceptMode) { $daoTudu->updateTuduUser($tudu->tuduId, $user->uniqueId, array('accepttime' => time(), 'tudustatus' => Dao_Td_Tudu_Tudu::STATUS_DOING)); $daoTudu->updateLastAcceptTime($tudu->tuduId); } } $daoTudu->addUser($tudu->tuduId, $user->uniqueId); // 移除草稿 if ($tudu->isDraft) { $daoTudu->deleteLabel($tudu->tuduId, $user->uniqueId, '^r'); } $daoTudu->addLabel($tudu->tuduId, $user->uniqueId, '^all'); $daoTudu->addLabel($tudu->tuduId, $user->uniqueId, '^i'); $daoTudu->addLabel($tudu->tuduId, $user->uniqueId, '^f'); $tudu->setAttribute('recipient', $recipients); return true; }
/** * /compose/send * * 图度发送统一接口 * 接管保存,发送,更新,转发,申请审批等操作 * */ public function sendAction() { $post = $this->_request->getPost(); // 当前操作类型 $action = self::ACTION_SEND; // 图度类型 $type = isset($post['type']) ? $post['type'] : 'task'; // 操作的保存图度列表 // array('tuduid' => $params ...) $tuduList = array(); // 提交主任务ID $tuduId = isset($post['ftid']) ? $post['ftid'] : null; // 图度组根任务ID $rootId = null; // 是否包含分工 $hasDivide = isset($post['chidx']) && is_array($post['chidx']); // 日志详细信息 $logDetails = array(); // 返回数据 $returnData = array(); // 是否重开讨论 $isReopen = isset($post['isclose']) && $type == 'discuss'; if (!empty($post['action']) && $post['action'] == 'save') { $action = self::ACTION_SAVE; } if (!empty($post['forward'])) { $action = self::ACTION_FORWARD; } elseif (!empty($post['invite'])) { $action = self::ACTION_INVITE; } elseif (!empty($post['divide'])) { $action = self::ACTION_DIVIDE; } elseif (!empty($post['review'])) { $action = self::ACTION_REVIEW; } elseif (!empty($post['apply'])) { $action = self::ACTION_APPLY; } /* @var $manager Tudu_Tudu_Manager */ $manager = Tudu_Tudu_Manager::getInstance(); /* @var $storage Tudu_Tudu_Storage */ $storage = Tudu_Tudu_Storage::getInstance(); $Indexes = array(''); if ($type == 'task' && $hasDivide && $action != self::ACTION_FORWARD && $action != self::ACTION_APPLY) { $Indexes = array_merge($Indexes, $post['chidx']); } // 周期任务 if (($type == 'task' || $type == 'meeting') && $tuduId && !Tudu_Tudu_Extension::isRegistered('cycle')) { Tudu_Tudu_Extension::registerExtension('cycle', 'Tudu_Tudu_Extension_Cycle'); } // 需要图度组 if ($type == 'task') { Tudu_Tudu_Extension::registerExtension('group', 'Tudu_Tudu_Extension_Group'); } // 需要流程 if (($type == 'task' || $type == 'notice') && !Tudu_Tudu_Extension::isRegistered('flow')) { Tudu_Tudu_Extension::registerExtension('flow', 'Tudu_Tudu_Extension_Flow'); } // 版块列表 $boards = $this->getBoards(false); // 遍历提交图度参数,填充图度列表 $children = array(); foreach ($Indexes as $suffix) { if ('' !== $suffix) { $suffix = '-' . $suffix; } // 获取已存在图度数据 $fromTudu = null; if (!empty($post['ftid' . $suffix])) { $tid = $post['ftid' . $suffix]; $fromTudu = $manager->getTuduById($tid, $this->_user->uniqueId); if (null === $fromTudu) { return $this->json(false, $this->lang['tudu_not_exists']); } } // 创建图度 if (null === $fromTudu) { // 转发、分工等图度不存在 if ($action != self::ACTION_SEND && $action != self::ACTION_SAVE && $action != self::ACTION_DIVIDE || $action == self::ACTION_DIVIDE && '' === $suffix) { return $this->json(false, $this->lang['tudu_not_exists']); } // 创建权限 if (!$this->_user->getAccess()->isAllowed(Tudu_Access::PERM_CREATE_TUDU)) { return $this->json(false, $this->lang['perm_deny_create_tudu']); } } else { // 非草稿状态下的分工,没有修改则不进行后续更新操作 if (!empty($suffix) && empty($post['ismodified' . $suffix]) && !($fromTudu->isDraft && $action != self::ACTION_SAVE)) { $idx = str_replace('-', '', $suffix); $children[$idx] = $fromTudu->tuduId; continue; } // 保存草稿,图度必须为草稿状态 if ($action == self::ACTION_SAVE) { if (!$fromTudu->isDraft) { return $this->json(false, $this->lang['forbid_save_sent']); } } else { $isSender = true; $isAccepter = in_array($this->_user->address, $fromTudu->accepter, true) || in_array($this->_user->userName, $fromTudu->accepter, true); switch ($action) { // 更新,权限,发起人/版主/分区负责人 case self::ACTION_SEND: // 更新权限 if ($fromTudu && !$fromTudu->isDraft && !$this->_user->getAccess()->isAllowed(Tudu_Access::PERM_UPDATE_TUDU)) { return $this->json(false, $this->lang['perm_deny_update_tudu']); } // 权限 $board = $boards[$fromTudu->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 (!$isSender && !$isModerator && !$isSuperModerator) { return $this->json(false, $this->lang['perm_deny_update_tudu']); } break; // 转发,权限,任务,已发送,执行人,非图度组 // 转发,权限,任务,已发送,执行人,非图度组 case self::ACTION_FORWARD: // 转发权限 if (!$this->_user->getAccess()->isAllowed(Tudu_Access::PERM_FORWARD_TUDU)) { return $this->json(false, $this->lang['perm_deny_forward_tudu']); } // 图度组 if ($fromTudu->isTuduGroup) { return $this->json(false, $this->lang['deny_forward_tudugroup']); } // 不是执行人 if (!$isAccepter) { return $this->json(false, $this->lang['forbid_non_accepter_forward']); } $isSender = $fromTudu->sender == $this->_user->userName; break; // 分工,任务,已发送,执行人,有分工 // 分工,任务,已发送,执行人,有分工 case self::ACTION_DIVIDE: if (empty($post['chidx'])) { return $this->json(false, $this->lang['no_divide_tudu']); } if ($fromTudu->isDraft) { return $this->json(false, $this->lang['tudu_not_exists']); } $isSender = $fromTudu->sender == $this->_user->userName; break; // 邀请,必须为会议,已经发送 // 邀请,必须为会议,已经发送 case self::ACTION_INVITE: if ($fromTudu->type != 'meeting') { return $this->json(false, null); } if ($fromTudu->isDraft) { return $this->json(false, $this->lang['tudu_not_exists']); } $isSender = $fromTudu->sender == $this->_user->userName; break; // 申请审批,必须为任务,已发送,执行人,非图度组 // 申请审批,必须为任务,已发送,执行人,非图度组 case self::ACTION_APPLY: // 图度组不能参与审批 if ($fromTudu->isTuduGroup) { return $this->json(false, $this->lang['tudu_group_review']); } // 非图度执行人不能进行申请审批操作 if (!$isAccepter) { return $this->json(false, $this->lang['no_accepter_apply']); } // 审批人为空 if (empty($post['reviewer' . $suffix])) { return $this->json(false, $this->lang['no_reviewer']); } $isSender = $fromTudu->sender == $this->_user->userName; break; // 审批,审批步骤,审批人是当前用户 // 审批,审批步骤,审批人是当前用户 case self::ACTION_REVIEW: if (!$fromTudu->stepId || false !== strpos('^', $fromTudu->stepId)) { return $this->json(false, $this->lang['disable_review']); } $flow = Tudu_Tudu_Extension::getExtension('flow'); $reviewer = $flow->getStepUser($fromTudu->tuduId, $fromTudu->stepId, $this->_user->uniqueId); if (!$reviewer || $reviewer['type'] != Dao_Td_Tudu_Step::TYPE_EXAMINE || $reviewer['status'] != 1) { return $this->json(false, $this->lang['disable_review']); } $isSender = $fromTudu->sender == $this->_user->userName; break; } if ($action != self::ACTION_SEND && $fromTudu->isDraft) { return $this->json(false, $this->lang['forbid_save_sent']); } } } $params = $this->_formatTuduParams($post, $suffix); $params['action'] = $action; if (null === $fromTudu) { // 发起人参数 $params['from'] = $this->_user->userName . ' ' . $this->_user->trueName; $params['email'] = $this->_user->userName; $params['sender'] = $this->_user->userName; } else { if (!empty($params['flowid']) && $action != self::ACTION_REVIEW && $action != self::ACTION_FORWARD) { unset($params['to']); } if (!$fromTudu->isDraft) { $params['lastmodify'] = implode(chr(9), array($this->_user->uniqueId, time(), $this->_user->trueName)); } } // 创建时间 if (null === $fromTudu || $fromTudu->isDraft) { $params['createtime'] = time(); } // 转发,没有编辑权限,去除保存参数 $isClearModify = false; if ($action == self::ACTION_FORWARD) { // 权限 $board = $boards[$fromTudu->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 (!$this->_user->getAccess()->isAllowed(Tudu_Access::PERM_UPDATE_TUDU) || !$isSender && !$isModerator && !$isSuperModerator) { $isClearModify = true; } } if ($action == self::ACTION_REVIEW || $action == self::ACTION_APPLY) { $isClearModify = true; } if ($isClearModify) { unset($params['classid'], $params['subject'], $params['privacy'], $params['password'], $params['priority'], $params['isauth'], $params['needconfirm'], $params['notifyall']); } try { $tudu = $storage->prepareTudu($params, $fromTudu); } catch (Tudu_Tudu_Exception $e) { switch ($e->getCode()) { case Tudu_Tudu_Exception::CODE_FLOW_STEP_NULL: $this->json(false, $this->lang['missing_flow_steps']); break; case Tudu_Tudu_Exception::CODE_NOT_EXISTS_UPPER: $this->json(false, $this->lang['missing_flow_steps_upper_reviewer']); break; case Tudu_Tudu_Exception::CODE_NOT_EXISTS_USER: $this->json(false, $this->lang['missing_flow_steps_receiver']); break; /* case Tudu_Tudu_Exception::MISSING_VOTE_TITLE: $this->json(false, $this->lang['missing_vote_title']); break; case Tudu_Tudu_Exception::MISSING_VOTE_OPTIONS: $this->json(false, $this->lang['missing_vote_option']); break; */ } } if ('' === $suffix) { $tuduId = $tudu->tuduId; $rootId = $tudu->rootId ? $tudu->rootId : $tudu->tuduId; } // 返回投票数据参数 if ($tudu->type == 'discuss' && $tudu->vote) { $vote = $tudu->vote; if ($vote && !empty($vote['newoptions'])) { foreach ($vote['newoptions'] as $item) { $returnData['votes'][$item['index']] = $item['optionid']; } } } // 部分操作不需要继承原文内容 if ('' == $suffix && $action != self::ACTION_REVIEW && $action != self::ACTION_FORWARD && $action != self::ACTION_INVITE) { if ($fromTudu && !$fromTudu->isDraft) { $tudu->boardId = $tudu->boardId ? $tudu->boardId : $fromTudu->boardId; $tudu->content = $tudu->content ? $tudu->content : $fromTudu->content; $tudu->startTime = isset($post['starttime' . $suffix]) ? $tudu->startTime : $fromTudu->startTime; $tudu->endTime = isset($post['endtime' . $suffix]) ? $tudu->endTime : $fromTudu->endTime; } } // 设置子任务的父级ID if ('' !== $suffix && $type == 'task') { $tudu->parentId = $tuduId; $tudu->rootId = $rootId; $tudu->nodeType = $tudu->nodeType ? $tudu->nodeType : Dao_Td_Tudu_Group::TYPE_LEAF; $parent = $tuduList[$tuduId]; if (!$fromTudu) { $tudu->boardId = $tudu->boardId ? $tudu->boardId : $parent->boardId; $tudu->classId = $tudu->classId ? $tudu->classId : $parent->classId; //$tudu->content = $tudu->content ? $tudu->content : $parent->content; $tudu->startTime = $tudu->startTime ? $tudu->startTime : $parent->startTime; $tudu->endTime = $tudu->endTime ? $tudu->endTime : $parent->endTime; $content = trim(strip_tags($tudu->content, 'img')); if (!$content) { $tudu->content = $parent->content; } } else { $tudu->boardId = $tudu->boardId ? $tudu->boardId : $fromTudu->boardId; $tudu->content = $tudu->content ? $tudu->content : $fromTudu->content; $tudu->startTime = $tudu->startTime ? $tudu->startTime : $fromTudu->startTime; $tudu->endTime = $tudu->endTime ? $tudu->endTime : $fromTudu->endTime; } $returnData['children'][(string) str_replace('-', '', $suffix)] = $tudu->tuduId; $idx = str_replace('-', '', $suffix); $children[$idx] = $tudu->tuduId; } if ('' === $suffix && $hasDivide && $type == 'task') { $tudu->rootId = $rootId; $tudu->nodeType = Dao_Td_Tudu_Group::TYPE_NODE; } // 没有分工 if (!$hasDivide && $tuduId == $tudu->tuduId && $fromTudu && $fromTudu->nodeType && $manager->getChildrenCount($tudu->tuduId) <= 0) { $tudu->nodeType = Dao_Td_Tudu_Group::TYPE_LEAF; } // 未发送,更新创建时间 /*if (!$fromTudu || $fromTudu->isDraft) { $tudu->createTime = time(); }*/ // 空内容 if ($action != self::ACTION_REVIEW && $action != self::ACTION_SAVE && !$tudu->content) { return $this->json(false, $this->lang['params_invalid_content']); } // 转发 if ($action == self::ACTION_FORWARD || $action == self::ACTION_INVITE) { // 输入用户已经是执行人 $to = $tudu->to; foreach ($to as $k => $item) { /*if (is_string($item['email']) && in_array($item['email'], $fromTudu->accepter, true)) { return $this->json(false, sprintf($this->lang['user_is_accepter'], $item['truename'])); }*/ if ($action == self::ACTION_FORWARD && $fromTudu->selfPercent < 100) { $to[$k]['percent'] = $fromTudu->selfPercent; } } $tudu->to = $to; $to = array(); foreach ($fromTudu->to as $k => $item) { if ($k != $this->_user->userName) { $to[] = $k . ' ' . $item[0]; } } $tudu->to = array_merge($tudu->to, Tudu_Tudu_Storage::formatRecipients(implode("\n", $to))); } // 邀请 || 100% 转发 加上自己 if ($action == self::ACTION_INVITE || $action == self::ACTION_FORWARD && $fromTudu->selfPercent >= 100) { $tudu->to = array_merge($tudu->to, array($this->_user->userName => array('email' => $this->_user->userName, 'truename' => $this->_user->trueName, 'percent' => $fromTudu->selfPercent))); } // 执行人 -- 自己 if ($action == self::ACTION_APPLY) { $tudu->to = Tudu_Tudu_Storage::formatRecordRecipients($fromTudu->to); } // 暂时不能输入自己 - 界面交互有问题不能支持 if ($action == self::ACTION_REVIEW && $tudu->reviewer) { if (array_key_exists($this->_user->address, $tudu->reviewer) || array_key_exists($this->_user->userName, $tudu->reviewer)) { return $this->json(false, $this->lang['add_reviewer_self']); } } $tuduList[$tudu->tuduId] = $tudu; $act = $tudu->tuduId == $tuduId ? $action : 'send'; if ($act == 'send') { $act = $fromTudu && !$fromTudu->isDraft ? 'update' : 'send'; } $detail = $this->_getLogDetail($params, $fromTudu); if (in_array($action, array(self::ACTION_REVIEW, self::ACTION_APPLY, self::ACTION_FORWARD, self::ACTION_INVITE))) { unset($detail['content']); } $logDetails[$tudu->tuduId] = array('action' => $act, 'detail' => $detail); } foreach ($tuduList as $tid => $item) { $prevId = $item->prevTuduId; if ($prevId && strpos($prevId, 'child-') !== false) { $prevId = (int) str_replace('child-', '', $prevId); if (isset($children[$prevId])) { $item->prevTuduId = $children[$prevId]; } } } // 遍历图度列表保存 foreach ($tuduList as $tid => $tudu) { // 主任务按照操作处理 // 处理审批流程 if ($action == self::ACTION_REVIEW) { $agree = $this->_request->getPost('agree'); $storage->reviewTudu($tudu, $agree); // 其他操作 } else { if ($tid == $tuduId) { $func = $action == 'send' ? 'save' : $action; $func .= 'Tudu'; } else { $func = 'saveTudu'; } $ret = $storage->{$func}($tudu); if (!$ret) { return $this->json(false, $this->lang['save_failure']); } } $returnData['tuduid'] = $tuduId; } //Tudu_Tudu_Deliver::initAddressBook($this->multidb->getDefaultDb()); $deliver = Tudu_Tudu_Deliver::getInstance(); // 遍历图度列表发送图度 if ($action !== self::ACTION_SAVE) { $config = $this->bootstrap->getOption('httpsqs'); $httpsqs = new Oray_Httpsqs($config['host'], $config['port'], $config['chartset'], $config['name']); foreach ($tuduList as $tid => $tudu) { // 发送到接收人 $recipients = $deliver->prepareRecipients($this->_user->uniqueId, $this->_user->userId, $tudu); if ($action == self::ACTION_REVIEW && $tudu->type == 'notice' && !$this->_request->getPost('agree')) { $recipients = array(); $addressBook = $deliver->getAddressBook(); $fromSender = $addressBook->searchUser($tudu->orgId, $tudu->sender); if (!empty($fromSender)) { $fromSender['accepterinfo'] = $fromSender['email'] . ' ' . $fromSender['truename']; $fromSender['issender'] = $fromSender['email'] == $tudu->sender; $recipients[$fromSender['uniqueid']] = $fromSender; } } // 公告(含审批时),过滤接收人 if ($tudu->type == 'notice' && $tudu->reviewer) { $users = array(); foreach ($tudu->reviewer as $item) { foreach ($item as $reviewer) { $users[] = $reviewer['email']; } } // 过滤非审批人的接收用户 foreach ($recipients as $uniqueId => $recipient) { if (!in_array($recipient['email'], $users)) { unset($recipients[$uniqueId]); } } } // 移除原执行人 if (($tudu->type == 'meeting' || $tudu->type == 'task' && !$tudu->reviewer) && !$tudu->isDraft()) { $accepters = $manager->getTuduAccepters($tudu->tuduId); $to = $tudu->to; foreach ($accepters as $item) { list($email, ) = explode(' ', $item['accepterinfo'], 2); // 移除执行人角色,我执行标签 if (!empty($to) && !array_key_exists($email, $to) && $manager->getChildrenCount($tudu->tuduId, $item['uniqueid']) <= 0) { $deliver->removeAccepter($tudu->tuduId, $item['uniqueid']); $manager->deleteLabel($tudu->tuduId, $item['uniqueid'], '^a'); $manager->deleteLabel($tudu->tuduId, $item['uniqueid'], '^td'); } // 过滤外发执行人 避免重复发送 if ($action != self::ACTION_SEND) { foreach ($recipients as $uniqueId => $recipient) { if (!empty($recipient['isforeign']) && !empty($to) && array_key_exists($recipient['email'], $to)) { unset($recipients[$uniqueId]); } } } // 转发,继续之前的用户进度 if ($action == self::ACTION_FORWARD && isset($recipients[$item['uniqueid']])) { $recipients[$item['uniqueid']]['tudustatus'] = (int) $item['tudustatus']; } // 审批,继续之前的用户进度 if ($action == self::ACTION_REVIEW && isset($recipients[$item['uniqueid']])) { $recipients[$item['uniqueid']]['percent'] = (int) $item['percent']; } } } foreach ($recipients as $key => $recipient) { // 需要验证 if (!empty($recipient['isforeign'])) { $recipients[$key]['authcode'] = $tudu->isAuth ? Oray_Function::randKeys(4) : null; } // 标记转发 // 进度小于 100%是继承进度,100%时为0 if ($action == self::ACTION_FORWARD || $action == self::ACTION_INVITE) { $newAccepter = $this->_getReceiver($post, 'to'); $fromTudu = $tudu->getFromTudu(); if (isset($recipient['role']) && $recipient['role'] == 'to' && array_key_exists($recipient['email'], $newAccepter)) { $recipients[$key]['forwardinfo'] = $this->_user->trueName . "\n" . time(); $recipients[$key]['percent'] = $fromTudu->selfPercent < 100 ? $fromTudu->selfPercent : 0; $recipients[$key]['tudustatus'] = $fromTudu->selfTuduStatus < 2 ? $fromTudu->selfTuduStatus : 0; } } if ($tudu->flowId && isset($recipient['role']) && $recipient['role'] == 'to') { $recipients[$key]['tudustatus'] = 1; $recipients[$key]['percent'] = 0; } } // 过滤外发人 避免重复发送 /*if ($action != self::ACTION_SEND) { $fromTudu = $tudu->getFromTudu(); foreach ($recipients as $uniqueId => $recipient) { if (!empty($recipient['isforeign']) && (($fromTudu->to && array_key_exists($recipient['email'], $fromTudu->to)) || ($fromTudu->cc && array_key_exists($recipient['email'], $fromTudu->cc)) || ($fromTudu->bcc && array_key_exists($recipient['email'], $fromTudu->bcc)))) { unset($recipients[$uniqueId]); } } }*/ // 标记当前用户已转发 if ($action == self::ACTION_FORWARD) { $manager->markForward($tudu->tuduId, $this->_user->uniqueId); } // 加上当前用户(发起人) if ((!$tudu->isFromTudu() || $tudu->isDraft()) && !isset($recipients[$this->_user->uniqueId])) { $recipients[$this->_user->uniqueId] = array('uniqueid' => $this->_user->uniqueId, 'role' => 'from', 'issender' => true); } // 发送图度到接收人 $deliver->sendTudu($tudu, $recipients); $flowPercent = null; // 计算进度 if ($tudu->flowId) { if ($tudu->isChange('stepid')) { $progress = $manager->updateFlowProgress($tudu->tuduId, null, $tudu->stepId, null, $flowPercent); } } else { $progress = $manager->updateProgress($tudu->tuduId, null, null); } // 需要计算父任务进度 if ($tudu->parentId) { $manager->calParentsProgress($tudu->tuduId); // 小于100%的分工从图度箱移除 if (!$tudu->flowId) { if ($progress < 100 && !array_key_exists($this->_user->address, $tudu->to)) { $manager->deleteLabel($tudu->tuduId, $this->_user->uniqueId, '^i'); $manager->deleteLabel($tudu->tuduId, $this->_user->uniqueId, '^td'); $manager->deleteLabel($tudu->tuduId, $this->_user->uniqueId, '^c'); } } } // 自己接受当前任务 if ($action == self::ACTION_SEND || $action == self::ACTION_DIVIDE) { if (($tudu->type == 'task' || $tudu->type == 'meeting') && !$tudu->flowId) { if ($tudu->to && array_key_exists($this->_user->userName, $tudu->to) || $recipients && array_key_exists($this->_user->uniqueId, $recipients) && !$tudu->acceptMode) { $manager->acceptTudu($tudu->tuduId, $this->_user->uniqueId, null); } } } // 转发操作,添加我转发标签,其他则添加到已发送 if ($action == self::ACTION_FORWARD) { $manager->addLabel($tuduId, $this->_user->uniqueId, '^w'); } else { if ($action != self::ACTION_REVIEW) { $manager->addLabel($tuduId, $this->_user->uniqueId, '^f'); } } // 审批标签 if ($action == self::ACTION_REVIEW) { $manager->deleteLabel($tuduId, $this->_user->uniqueId, '^e'); $manager->deleteLabel($tuduId, $this->_user->uniqueId, '^td'); $manager->addLabel($tuduId, $this->_user->uniqueId, '^v'); $fromTudu = $tudu->getFromTudu(); if (null != $fromTudu) { if (is_array($tudu->to) && array_key_exists($fromTudu->sender, $tudu->to) && $tudu->stepId != '^head' && $tudu->stepId != '^break' && !$tudu->flowId && !$tudu->acceptMode) { $addressBook = Tudu_AddressBook::getInstance(); $user = $addressBook->searchUser($this->_user->orgId, $fromTudu->sender); if (null !== $user) { $manager->acceptTudu($tudu->tuduId, $user['uniqueid'], null); } } } } // 移除草稿 if ($tudu->isDraft()) { $manager->deleteLabel($tuduId, $this->_user->uniqueId, '^r'); } if (isset($logDetails[$tid])) { // 图度日志 $this->_writeLog(Dao_Td_Log_Log::TYPE_TUDU, $tid, $logDetails[$tid]['action'], $logDetails[$tid]['detail'], 0); } // 记录私密密码 if ($tudu->password) { $this->session->privacy[$tudu->tuduId] = $tudu->password; } // 标记所有人未读状态 $manager->markAllUnRead($tudu->tuduId); // 重开讨论 if ($isReopen) { $manager->closeTudu($tudu->tuduId, 0); } // 工作流执行人自动接受任务 if ($tudu->flowId) { $daoStep = $this->getDao('Dao_Td_Tudu_Step'); $step = $daoStep->getStep(array('tuduid' => $tudu->tuduId, 'stepid' => $tudu->stepId)); if (null !== $step) { $stepUsers = $daoStep->getUsers($tudu->tuduId, $tudu->stepId); if ($step->type == Dao_Td_Tudu_Step::TYPE_EXECUTE && !empty($stepUsers) && $tudu->stepId != '^head' && $tudu->stepId != '^break') { foreach ($stepUsers as $item) { $manager->acceptTudu($tudu->tuduId, $item['uniqueid'], null); } $manager->updateTudu($tudu->tuduId, array('acceptmode' => 0)); // 认领模式 } else { if ($step->type == Dao_Td_Tudu_Step::TYPE_CLAIM) { $manager->updateTudu($tudu->tuduId, array('acceptmode' => 1, 'accepttime' => null)); } } } if ($flowPercent == 100 && !$tudu->needConfirm) { $manager->doneTudu($tudu->tuduId, true, 0); // 添加操作日志 $this->_writeLog(Dao_Td_Log_Log::TYPE_TUDU, $tudu->tuduId, Dao_Td_Log_Log::ACTION_TUDU_DONE, array('percent' => $flowPercent), false, true); } } // 记录外发人员 $contacts = array(); foreach ($recipients as $item) { if (!empty($item['isforeign'])) { $contacts[] = $item['uniqueid']; } } if ($contacts) { $this->session->tuduContact[$tudu->tuduId] = $contacts; } $sqsAction = !$tudu->isFromTudu() || $tudu->isDraft() ? 'create' : 'update'; $isChangedCc = $tudu->isChange('cc') || $tudu->isChange('bcc'); $sqsParam = array('tsid' => $this->_user->tsId, 'tuduid' => $tid, 'from' => $this->_user->userName, 'uniqueid' => $this->_user->uniqueId, 'server' => $this->_request->getServer('HTTP_HOST'), 'type' => $type, 'ischangedCc' => $sqsAction == 'update' && $isChangedCc ? $isChangedCc : false); if ($action == self::ACTION_SEND && $tudu->flowId && $sqsAction == 'create') { $sqsParam['nstepid'] = $tudu->stepId; $sqsParam['flowid'] = $tudu->flowId; } if ($action == self::ACTION_REVIEW) { $sqsAction = 'review'; $sqsParam['stepid'] = $tudu->getFromTudu()->stepId; $sqsParam['agree'] = $this->_request->getPost('agree'); if ($tudu->flowId) { $sqsParam['nstepid'] = $tudu->stepId; $sqsParam['flowid'] = $tudu->flowId; $sqsParam['stepstatus'] = $tudu->currentStepStatus; } if ($tudu->type == 'notice' && ($tudu->stepId = '^end')) { $sqsAction = 'create'; } } $httpsqs->put(implode(' ', array('tudu', $sqsAction, '', http_build_query($sqsParam))), 'tudu'); } // 保存到发起人草稿箱 } else { foreach ($tuduList as $tid => $tudu) { if (!$tudu->parentId) { $deliver->saveDraft($tudu); } } } $message = $action !== self::ACTION_SAVE ? $this->lang['send_success'] : $this->lang['save_success']; Tudu_Tudu_Extension::unRegisterAll(); return $this->json(true, $message, $returnData); }
/** * 添加接收人 */ public function foreignAddAction() { $tuduId = $this->_request->getPost('tid'); $to = $this->_request->getPost('to'); $cc = $this->_request->getPost('cc'); // 参数:图度ID必须存在 if (!$tuduId) { return $this->json(false, $this->lang['invalid_tuduid']); } $fromTudu = $this->manager->getTuduById($tuduId, $this->_user->uniqueId); // 图度必须存在 if (null === $fromTudu) { return $this->json(false, $this->lang['tudu_not_exists']); } // 必须是发起人才具备此操作 if ($fromTudu->sender != $this->_user->userName) { return $this->json(false, $this->lang['perm_deny_add_foreign']); } // 检查外发用户email格式,外发用户是否存在,不存在则创建 $address = array('to' => $this->_formatRecipients($to), 'cc' => $this->_formatRecipients($cc)); $tuduAddr = array('to' => array(), 'cc' => array()); $sendTo = array(); foreach ($fromTudu->to as $k => $item) { $tuduAddr['to'][] = implode(' ', array(!is_numeric($k) ? $k : '', $item[0])); } foreach ($fromTudu->cc as $k => $item) { $tuduAddr['cc'][] = implode(' ', array(!is_int($k) ? $k : '', $item[0])); } /* @var $addressBook Tudu_AddressBook */ $addressBook = Tudu_AddressBook::getInstance(); $receivers = $this->manager->getTuduUsers($tuduId, array('isforeign' => 1)); foreach ($address as $k => $arr) { foreach ($arr as $email => $name) { if (!$email && !$name) { continue; } $email = preg_replace('/^#+/', '', $email); // 本系统用户不参与外发 if (false !== strpos($email, '@') && null !== $addressBook->searchUser($this->_user->orgId, $email)) { return $this->json(false, $this->lang['deny_add_user_to_foreign']); } // 新添加的外发用户是否已存在 foreach ($receivers as $receiver) { if ($email && $email == $receiver['email']) { $display = $email ? $email : $name; return $this->json(false, sprintf($this->lang['foreign_user_already_exists'], $display)); } } // 不存在联系人时创建 if (!$addressBook->searchContact($this->_user->uniqueId, $email, $name)) { $this->manager->createContact($this->_user->uniqueId, $email, $name); } $sendTo[] = $email; $tuduAddr[$k][] = implode(' ', array($email, $name)); } } /* @var $deliver Tudu_Tudu_Deliver */ $deliver = Tudu_Tudu_Deliver::getInstance(); /* @var $storage Tudu_Tudu_Storage */ $storage = Tudu_Tudu_Storage::getInstance(); $tudu = $storage->prepareTudu(array('to' => $to, 'cc' => $cc), $fromTudu); $recipients = $deliver->prepareRecipients($this->_user->uniqueId, $this->_user->userId, $tudu); // 添加用户 if (!$deliver->sendTudu($tudu, $recipients)) { return $this->json(false, $this->lang['add_foreign_failure']); } // 更新图度用户 $this->manager->updateTudu($tuduId, array('to' => implode("\n", $tuduAddr['to']), 'cc' => implode("\n", $tuduAddr['cc']))); $config = $this->bootstrap->getOption('httpsqs'); // 发送邮件 $httpsqs = new Oray_Httpsqs($config['host'], $config['port'], $config['chartset'], $config['name']); // 发送外部邮件(如果有),处理联系人 $data = implode(' ', array('send', 'tudu', '', http_build_query(array('tsid' => $this->_user->tsId, 'tuduid' => $tuduId, 'uniqueid' => $this->_user->uniqueId, 'to' => implode(',', $sendTo))))); $httpsqs->put($data, 'send'); return $this->json(true, $this->lang['add_foreign_success']); }
/** * * @param string $params */ public function createUser($params) { list($orgId, $address, $uniqueId, $truename) = explode(':', $params); $daoUser = Tudu_Dao_Manager::getDao('Dao_Md_User_User', Tudu_Dao_Manager::DB_MD); $user = $daoUser->getUser(array('uniqueid' => $uniqueId)); $defaultTime = mktime(0, 0, 0, 11, 23, 2011); if ($user->createTime > $defaultTime) { $daoOrg = Tudu_Dao_Manager::getDao('Dao_Md_Org_Org', Tudu_Dao_Manager::DB_MD); $org = $daoOrg->getOrg(array('orgid' => $orgId)); $tsId = $org->tsid; Tudu_Dao_Manager::setDb(Tudu_Dao_Manager::DB_TS, $this->_tsDbs['ts' . $tsId]); $manager = Tudu_Tudu_Manager::getInstance(Tudu_Dao_Manager::getDb(Tudu_Dao_Manager::DB_TS)); // 系统欢迎公告ID $tuduId = md5($orgId . '-welcome'); // 查看系统欢迎公告是否存在 $tudu = $manager->getTuduById($tuduId, $uniqueId); if (null === $tudu) { $manager->addRecipient($tuduId, $uniqueId); $manager->addLabel($tuduId, $uniqueId, '^all'); $manager->addLabel($tuduId, $uniqueId, '^i'); $manager->addLabel($tuduId, $uniqueId, '^n'); $this->getLogger()->debug("System Welcome Notice Tudu id:{$tuduId} done"); } // 查看图度新手任务是否存在 $newbieTuduId = 'newbie-' . $uniqueId; $newbieTudu = $manager->getTuduById($newbieTuduId, $uniqueId); if (null === $newbieTudu) { $content = file_get_contents($this->_options['data']['path'] . '/templates/tudu/newbie_tudu_task.tpl'); if ($content) { $tudu = array('orgid' => $orgId, 'tuduid' => $newbieTuduId, 'boardid' => '^system', 'uniqueid' => $this->_unId, 'type' => 'task', 'subject' => '图度新手任务', 'email' => '*****@*****.**', 'from' => $this->_unId . ' ' . $this->_unName, 'to' => $address . ' ' . $truename, 'cc' => null, 'priority' => 0, 'privacy' => 0, 'issend' => 1, 'needconfirm' => 0, 'status' => Dao_Td_Tudu_Tudu::STATUS_UNSTART, 'content' => $content, 'starttime' => strtotime(date('Y-m-d', time())), 'endtime' => null, 'totaltime' => 3 * 3600, 'poster' => $this->_unName, 'posterinfo' => '', 'lastposter' => $this->_unName, 'lastposttime' => time(), 'createtime' => time(), 'attachment' => array()); $tudu = new Tudu_Tudu_Storage_Tudu($tudu); $storage = Tudu_Tudu_Storage::getInstance(Tudu_Dao_Manager::getDb(Tudu_Dao_Manager::DB_TS)); $deliver = Tudu_Tudu_Deliver::getInstance(); // 创建新手任务 $tuduId = $storage->createTudu($tudu); if (!$tuduId) { $this->getLogger()->warn("Create newbie Tudu failed id:{$newbieTuduId}"); return; } // 发送新手任务 $ret = $deliver->sendTudu($tudu, array()); if (!$ret) { $this->getLogger()->warn("Send newbie Tudu failed id:{$newbieTuduId}"); return; } $manager->addRecipient($tuduId, $uniqueId, array('role' => 'to')); $manager->addLabel($tuduId, $uniqueId, '^all'); $manager->addLabel($tuduId, $uniqueId, '^i'); $manager->addLabel($tuduId, $uniqueId, '^a'); $this->getLogger()->debug("Newbie Tudu id:{$tuduId} done"); } } } }
/** * 生成周期图度 * * @param $params */ public function cycle($params) { if (empty($params['tuduid']) || empty($params['cycleid']) || empty($params['tsid'])) { return; } $tuduId = $params['tuduid']; $cycleId = $params['cycleid']; $tsId = $params['tsid']; $daoUser = Tudu_Dao_Manager::getDao('Dao_Md_User_User', Tudu_Dao_Manager::DB_MD); $daoCycle = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Cycle', Tudu_Dao_Manager::DB_TS); $manager = Tudu_Tudu_Manager::getInstance(Tudu_Dao_Manager::getDb(Tudu_Dao_Manager::DB_TS)); $tudu = $manager->getTuduById($tuduId, $this->_unId); $fromTuduId = $tudu->tuduId; $acceptMode = $tudu->acceptMode; $isAuth = $tudu->isAuth; if (null === $tudu) { $this->getLogger()->warn("Tudu id: {$tuduId} is not exists"); return; } $cycle = $daoCycle->getCycle(array('cycleid' => $cycleId)); if (null === $cycle) { $this->getLogger()->warn("Tudu Cycle id: {$cycleId} is not exists"); return; } // 已经失效的周期设置 if ($cycle->isValid == 0) { return; } if (Dao_Td_Tudu_Cycle::END_TYPE_COUNT == $cycle->endType && $cycle->count >= $cycle->endCount) { $daoCycle->deleteCycle($cycle->cycleId); return; } if (Dao_Td_Tudu_Cycle::END_TYPE_DATE == $cycle->endType && time() >= $cycle->endDate) { $daoCycle->deleteCycle($cycle->cycleId); return; } $time = $daoCycle->getCycleTime($cycle, $tudu->startTime, $tudu->endTime); $recipients = array(); $to = array(); $fromUnId = null; $u = $daoUser->getUserByAddress($tudu->sender); if ($u) { $recipients[$u->uniqueId] = array('uniqueid' => $u->uniqueId, 'role' => 'from'); $fromUnId = $u->uniqueId; } if (!$acceptMode) { $accepters = $manager->getTuduAccepters($tudu->tuduId); foreach ($accepters as $a) { $recipients[$a['uniqueid']] = array('accepterinfo' => $a['accepterinfo'], 'uniqueid' => $a['uniqueid'], 'role' => Dao_Td_Tudu_Tudu::ROLE_ACCEPTER, 'tudustatus' => Dao_Td_Tudu_Tudu::STATUS_UNSTART, 'isforeign' => (int) $a['isforeign'], 'percent' => 0, 'authcode' => (int) $a['isforeign'] && $tudu->isAuth ? Oray_Function::randKeys(4) : null); if ($tudu->isAuth) { $recipients[$a['uniqueid']]['authcode'] = $a['authcode']; } $to[] = $a['accepterinfo']; } } // 公共周期任务图度数据 $params = $this->getCycleTuduParams($tudu, $cycle, $to, $fromUnId, $time); // 抄送 if (!empty($tudu->cc)) { $cc = array(); $sendCc = array(); foreach ($tudu->cc as $userName => $item) { $cc[] = $userName . ' ' . $item[0]; } $params['cc'] = implode("\n", $cc); $sendCc = $this->formatRecipients($params['cc']); $addressBook = Tudu_AddressBook::getInstance(); foreach ($sendCc as $key => $item) { if (isset($item['groupid'])) { if (0 === strpos($item['groupid'], 'XG')) { $users = $addressBook->getGroupContacts($tudu->orgId, $fromUnId, $item['groupid']); } else { $users = $addressBook->getGroupUsers($tudu->orgId, $item['groupid']); } $recipients = array_merge($users, $recipients); } else { $user = $addressBook->searchUser($tudu->orgId, $item['email']); if (null === $user) { $user = $addressBook->searchContact($fromUnId, $item['email'], $item['truename']); if (null === $user) { $user = $addressBook->prepareContact($item['email'], $item['truename']); } } if (!isset($recipients[$user['uniqueid']])) { $recipients[$user['uniqueid']] = $user; } } } } // 密送 if (!empty($tudu->bcc)) { $bcc = array(); $sendBcc = array(); foreach ($tudu->bcc as $userName => $item) { $bcc[] = $userName . ' ' . $item[0]; } $params['bcc'] = implode("\n", $bcc); $sendBcc = $this->formatRecipients($params['bcc']); $addressBook = Tudu_AddressBook::getInstance(); foreach ($sendBcc as $key => $item) { if (isset($item['groupid'])) { if (0 === strpos($item['groupid'], 'XG')) { $users = $addressBook->getGroupContacts($tudu->orgId, $fromUnId, $item['groupid']); } else { $users = $addressBook->getGroupUsers($tudu->orgId, $item['groupid']); } $recipients = array_merge($users, $recipients); } else { $user = $addressBook->searchUser($tudu->orgId, $item['email']); if (null === $user) { $user = $addressBook->searchContact($fromUnId, $item['email'], $item['truename']); if (null === $user) { $user = $addressBook->prepareContact($item['email'], $item['truename']); } } if (!isset($recipients[$user['uniqueid']])) { $recipients[$user['uniqueid']] = $user; } } } } // 会议数据 if ($tudu->type == 'meeting') { $daoMeeting = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Meeting', Tudu_Dao_Manager::DB_TS); $meeting = $daoMeeting->getMeeting(array('tuduid' => $tudu->tuduId)); if ($meeting) { $params['meeting'] = array('notifytype' => $meeting->notifyType, 'location' => $meeting->location, 'isallday' => $meeting->isAllday); $params['meeting']['notifytime'] = Dao_Td_Tudu_Meeting::calNotifyTime($params['starttime'], $meeting->notifyType); } } // 保留周期任务的附件 if ($cycle->isKeepAttach) { $daoAttach = Tudu_Dao_Manager::getDao('Dao_Td_Attachment_File', Tudu_Dao_Manager::DB_TS); $attaches = $daoAttach->getFiles(array('tuduid' => $tudu->tuduId, 'postid' => $tudu->postId))->toArray(); $attachNum = 0; foreach ($attaches as $attach) { if ($attach['isattach']) { $params['attachment'][] = $attach['fileid']; } else { $params['file'][] = $attach['fielid']; } } } $stepId = $params['stepid']; $tudu = new Tudu_Tudu_Storage_Tudu($params); $storage = Tudu_Tudu_Storage::getInstance(Tudu_Dao_Manager::getDb(Tudu_Dao_Manager::DB_TS)); $deliver = Tudu_Tudu_Deliver::getInstance(); $tuduId = $storage->createTudu($tudu); if (!$tuduId) { $this->getLogger()->warn("Create Cycle Tudu failed id:{$tuduId}"); return; } if ($params['type'] == 'task' && $tuduId) { $daoFlow = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Flow', Tudu_Dao_Manager::DB_TS); $flow = $daoFlow->getFlow(array('tuduid' => $fromTuduId)); $steps = $flow->steps; $step = reset($steps); $modelFlow = new Model_Tudu_Extension_Flow(array('orgid' => $tudu->orgId, 'tuduid' => $tuduId)); /*$step = $daoStep->getStep(array('tuduid' => $fromTuduId, 'prevstepid' => '^head')); $orderNum = 1;*/ $prevStepId = '^head'; $addressBook = Tudu_AddressBook::getInstance(); // 认领 if ($step && $step['type'] == Dao_Td_Tudu_Step::TYPE_CLAIM) { $modelFlow->addStep(array('stepid' => $step['stepid'], 'prev' => $step['prev'], 'next' => '^end', 'type' => $step['type'])); $acceptMode = true; $to = array(); foreach ($step['section'] as $idx => $sec) { $section = array(); foreach ($sec as $user) { $section[] = array('uniqueid' => $user['uniqueid'], 'username' => $user['username'], 'truename' => $user['truename']); if ($idx == 0) { $to[] = $user['username'] . ' ' . $user['truename']; $recipient = array('uniqueid' => $user['uniqueid'], 'userinfo' => $user['username'] . ' ' . $user['truename'], 'role' => Dao_Td_Tudu_Tudu::ROLE_ACCEPTER, 'tudustatus' => Dao_Td_Tudu_Tudu::STATUS_UNSTART, 'percent' => 0); $u = $addressBook->searchUser($fromUnId, $user['username']); if (!$u) { $recipient['isforeign'] = 1; if ($isAuth) { $recipient['auth'] = Oray_Function::randKeys(4); } } $recipients[$recipient['uniqueid']] = $recipient; } } $modelFlow->addStepSection($step['stepid'], $sec); } $modelFlow->stepNum = 1; $modelFlow->flowTo($step['stepid']); $daoFlow->createFlow($modelFlow->toArray()); // 更新to字段 $manager->updateTudu($tuduId, array('to' => implode("\n", $to), 'acceptmode' => 1, 'accepttime' => null)); } else { // 审批 $nextId = $step['next']; $modelFlow->addStep(array('stepid' => $step['stepid'], 'prev' => $step['prev'], 'next' => $step['next'], 'type' => $step['type'])); foreach ($step['section'] as $idx => $sec) { $section = array(); foreach ($sec as $user) { $section[] = array('uniqueid' => $user['uniqueid'], 'username' => $user['username'], 'truename' => $user['truename']); if ($idx == 0) { $to[] = $user['username'] . ' ' . $user['truename']; $recipient = array('uniqueid' => $user['uniqueid'], 'userinfo' => $user['username'] . ' ' . $user['truename'], 'role' => isset($recipients[$user['uniqueid']]) ? $recipients[$user['uniqueid']]['role'] : null, 'isreview' => true, 'tudustatus' => Dao_Td_Tudu_Tudu::STATUS_UNSTART); $recipients[$recipient['uniqueid']] = $recipient; } } $modelFlow->addStepSection($step['stepid'], $sec); } if (isset($flow->steps[$nextId])) { $next = $flow->steps[$nextId]; $modelFlow->addStep(array('stepid' => $next['stepid'], 'prev' => $next['prev'], 'next' => '^end', 'type' => $next['type'])); foreach ($next['section'] as $idx => $sec) { $section = array(); foreach ($sec as $user) { $section[] = array('uniqueid' => $user['uniqueid'], 'username' => $user['username'], 'truename' => $user['truename']); } $modelFlow->addStepSection($next['stepid'], $sec); } } $modelFlow->stepNum = count($modelFlow->steps); $modelFlow->flowTo($step['stepid']); $daoFlow->createFlow($modelFlow->toArray()); } } $sendParams = array(); if ($tudu->type == 'meeting') { $sendParams['meeting'] = true; } if (empty($reviewer)) { $ret = $deliver->sendTudu($tudu, $recipients, $sendParams); if (!$ret) { $this->getLogger()->warn("Send Tudu failed id:{$tuduId}"); return; } if (!$acceptMode) { foreach ($recipients as $unId => $recipient) { if (isset($recipient['role']) && $recipient['role'] == Dao_Td_Tudu_Tudu::ROLE_ACCEPTER) { $manager->acceptTudu($tuduId, $unId, null); } } } } else { $rev = array_shift($reviewer); $ret = $deliver->sendTudu($tudu, array($rev['uniqueid'] => array('tuduid' => $tuduId, 'uniqueid' => $rev['uniqueid']), $fromUnId => array('tuduid' => $tuduId, 'uniqueid' => $fromUnId)), null); if (!$ret) { $this->getLogger()->warn("Send Tudu failed id:{$tuduId}"); return; } $manager->addLabel($tuduId, $rev['uniqueid'], '^e'); } // 发起人的 if (null !== $fromUnId) { $manager->addLabel($tuduId, $fromUnId, '^f'); $manager->addLabel($tuduId, $fromUnId, '^i'); } $daoCycle->increment($cycle->cycleId); // 收发规则过滤 $data = implode(' ', array('tudu', 'filter', '', http_build_query(array('tsid' => $tsId, 'tuduid' => $tuduId)))); $this->_httpsqs->put($data, $this->_options['httpsqs']['names']['tudu']); // 外发请求 $data = implode(' ', array('send', 'tudu', '', http_build_query(array('tsid' => $tsId, 'tuduid' => $tuduId, 'uniqueid' => $fromUnId, 'to' => '')))); $this->_httpsqs->put($data, $this->_options['httpsqs']['names']['send']); $this->getLogger()->debug("Tudu id:{$tuduId} done"); }
/** * 调用 Tudu_Model_Tudu_Compose中与当前类名相同的方法 * 实现图度审批的流程 * * @param Tudu_Model_Tudu_Entity_Tudu $tudu */ public function composeHandler(Tudu_Model_Tudu_Entity_Tudu $tudu) { $user = Tudu_Model_Tudu_Abstract::getResource(Tudu_Model_Tudu_Abstract::RESOURCE_NAME_USER); if (!$tudu->tuduId) { require_once 'Tudu/Model/Tudu/Exception.php'; throw new Tudu_Model_Tudu_Exception('missing tuduid'); } $error = null; do { $daoTudu = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Tudu', Tudu_Dao_Manager::DB_TS); $fromTudu = $daoTudu->getTuduById($user->uniqueId, $tudu->tuduId); if (null === $fromTudu) { $error = 'tudu not exists'; break; } $daoStep = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Step', Tudu_Dao_Manager::DB_TS); $reviewer = $daoStep->getCurrentStep($fromTudu->tuduId, $fromTudu->stepId, $user->uniqueId); if (!$reviewer || $reviewer['type'] != Dao_Td_Tudu_Step::TYPE_EXAMINE || $reviewer['status'] != 1) { $error = 'disable review'; break; } $tudu->stepId = $fromTudu->stepId; if ($fromTudu->flowId) { $tudu->flowId = $fromTudu->flowId; } } while (false); if (null !== $error) { require_once 'Tudu/Model/Tudu/Exception.php'; throw new Tudu_Model_Tudu_Exception($error); } if ($tudu->type == 'notice') { // 公告 流程 ... } $isAgree = $tudu->isAgree; // 同意审批 if ($isAgree) { $daoStep->updateUser($tudu->tuduId, $tudu->stepId, $tudu->uniqueId, array('status' => 2)); $daoTudu->addLabel($tudu->tuduId, $tudu->uniqueId, '^v'); $tudu->currentStepStatus = false; // 有修改图度后续执行步骤 if ($tudu->reviewer || $tudu->to) { $this->_updateTuduSteps($tudu); } else { $this->_agree($tudu); } } else { $this->_disAgree($tudu); $daoTudu->addLabel($tudu->tuduId, $tudu->uniqueId, '^v'); } // 更新图度 $attrs = $tudu->getAttributes(); if (isset($attrs['to'])) { $params['to'] = Tudu_Model_Entity_Tudu::formatReceiver($attrs['to']); } if (isset($attrs['cc'])) { $params['cc'] = Tudu_Model_Entity_Tudu::formatReceiver($attrs['cc']); } $params['stepid'] = $attrs['stepid']; $ret = $daoTudu->updateTudu($tudu->tuduId, $params); if (!$ret) { require_once 'Tudu/Model/Tudu/Exception.php'; throw new Tudu_Model_Tudu_Exception('tudu save failure'); } $deliver = Tudu_Tudu_Deliver::getInstance(); $recipients = $deliver->prepareRecipients($user->uniqueId, $user->userId, $tudu); $deliver->sendTudu($tudu, $recipients); $tudu->setAttribute('recipient', $recipients); // 发送回复 $header = array('action' => 'review', 'tudu-act-value' => $isAgree ? 1 : 0); $headerKey = $tudu->reviewer ? 'tudu-reviewer' : 'tudu-to'; $items = $tudu->reviewer ? $tudu->reviewer : $tudu->to; $val = array(); if ($tudu->reviewer) { $items = $tudu->reviewer; $items = array_shift($items); } else { $items = $tudu->to; } if ($items) { foreach ($items as $item) { if (!empty($attrs['samereview'])) { break; } $val[] = $item['truename']; if ($tudu->reviewer) { break; } } } $header[$headerKey] = implode(',', $val); if ($tudu->type == 'notice' || empty($val)) { unset($header[$headerKey]); } $postParams = array('orgid' => $tudu->orgId, 'boardid' => $tudu->boardId, 'tuduid' => $tudu->tuduId, 'postid' => Dao_Td_Tudu_Post::getPostId($tudu->tuduId), 'header' => $header, 'content' => isset($attrs['content']) ? $attrs['content'] : '', 'poster' => $tudu->poster, 'postinfo' => $tudu->posterInfo, 'email' => $attrs['email'], 'uniqueid' => $tudu->uniqueId, 'attachment' => !empty($attrs['attachment']) ? (array) $attrs['attachment'] : array(), 'file' => !empty($attrs['file']) ? (array) $attrs['file'] : array()); $daoPost = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Post', Tudu_Dao_Manager::DB_TS); $postId = $daoPost->createPost($postParams); $daoPost->sendPost($tudu->tuduId, $postId); $extensions = $tudu->getExtensions(); foreach ($extensions as $name => $item) { $this->getExtension($item->getHandler())->onReview($tudu, $item); } return $tudu->tuduId; }