/** * * @param Model_Tudu_Tudu $tudu */ public function prepareTuduReview(Model_Tudu_Tudu &$tudu) { /* @var $daoFlow Dao_Td_Tudu_Flow */ $daoFlow = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Flow', Tudu_Dao_Manager::DB_TS); $flowData = $daoFlow->getFlow(array('tuduid' => $tudu->tuduId)); if (null === $flowData) { require_once 'Model/Tudu/Exception.php'; throw new Model_Tudu_Exception('Not allow to review tudu', Model_Tudu_Exception::PERMISSION_DENIED); } $flow = new Model_Tudu_Extension_Flow($flowData->toArray()); $flow->fromFlow = true; if (!$flow->isCurrentUser($tudu->uniqueId)) { require_once 'Model/Tudu/Exception.php'; throw new Model_Tudu_Exception('Not allow to review tudu', Model_Tudu_Exception::PERMISSION_DENIED); } // 处理同意流程 $flow->review($tudu->uniqueId, $tudu->agree); if ($tudu->agree) { $this->renewTuduFlow($tudu, $flow); } else { $step = $flow->getStep($flow->currentStepId); $next = $tudu->agree ? null : $step['prev']; if (null !== $next && 0 !== strpos($next, '^')) { $flow->flowTo($next); $nextStep = $flow->getStep($flow->currentStepId); $su = $flow->getStepSection($flow->currentStepId); // XXX :-( $users = array(); foreach ($su as $k => $u) { $users[$u['username']] = array('uniqueid' => $u['uniqueid'], 'email' => $u['username'], 'username' => $u['username'], 'truename' => $u['truename']); } if ($nextStep && $nextStep['type'] == 1) { $tudu->reviewer = $users; } else { if ($nextStep['type'] == 2) { $tudu->acceptMode = 1; } $tudu->to = $users; } } } $tudu->setExtension($flow); }
/** * /compose/reply * * 回覆 */ public function replyAction() { $tuduId = $this->_request->getPost('tid'); $action = $this->_request->getPost('action'); $type = $this->_request->getPost('type'); $post = $this->_request->getPost(); $uniqueId = $this->_user->uniqueId; $fromPost = null; $fromPostId = trim($this->_request->getPost('fpid')); $isDoneTudu = false; /* @var $manager Tudu_Tudu_Manager */ $manager = Tudu_Tudu_Manager::getInstance(); /* @var $storage Tudu_Tudu_Storage */ $storage = Tudu_Tudu_Storage::getInstance(); $tudu = $manager->getTuduById($tuduId, $uniqueId); if (null === $tudu) { return $this->json(false, $this->lang['tudu_not_exists']); } // 编辑回复的权限判断 if ($this->_user->orgId != $tudu->orgId) { return $this->json(false, $this->lang['tudu_not_exists']); } // 已确认图度 if ($tudu->isDone) { return $this->json(false, $this->lang['tudu_is_done']); } if ($fromPostId) { $fromPost = $manager->getPostById($tuduId, $fromPostId); } $isReceiver = $this->_user->uniqueId == $tudu->uniqueId && count($tudu->labels); $isAccepter = in_array($this->_user->userName, $tudu->accepter, true); $isSender = in_array($tudu->sender, array($this->_user->address, $this->_user->account)); $sendParam = array(); if ('modify' == $action) { if (null == $fromPost) { return $this->json(false, $this->lang['post_not_exists']); } // 编辑回复的权限判断 if (!$this->_user->getAccess()->isAllowed(Tudu_Access::PERM_UPDATE_POST) && $fromPost->isSend) { return $this->json(false, $this->lang['perm_deny_update_post']); } // 非回复者时,需要判断版主的权限 if ($fromPost->uniqueId != $this->_user->uniqueId) { $boards = $this->getBoards(false); $board = $boards[$tudu->boardId]; $isModerators = array_key_exists($this->_user->userId, $board['moderators']); if (!$isModerators) { return $this->json(false, $this->lang['perm_deny_update_post']); } } if (!$fromPost->isSend) { $sendParam['remind'] = true; } } else { // 发表回复的权限判断 - 参与人员或回复权限 if (!$isReceiver && !$this->_user->getAccess()->isAllowed(Tudu_Access::PERM_CREATE_POST)) { return $this->json(false, $this->lang['perm_deny_create_post']); } // 需要发送提醒 $sendParam['remind'] = true; } // 空内容 if ($type != 'save' && empty($post['content'])) { return $this->json(false, $this->lang['missing_content']); } // 构造参数 $params = array('orgid' => $tudu->orgId, 'boardid' => $tudu->boardId, 'tuduid' => $tudu->tuduId, 'uniqueid' => $uniqueId, 'email' => $this->_user->userName, 'poster' => $this->_user->trueName, 'posterinfo' => $this->_user->position, 'content' => $post['content'], 'attachment' => !empty($post['attach']) ? array_unique((array) $post['attach']) : array(), 'file' => !empty($post['file']) ? array_unique((array) $post['file']) : array()); $elapsedtime = round((double) $this->_request->getPost('elapsedtime'), 2) * 3600; $percent = min(100, (int) $this->_request->getPost('percent')); if ($fromPost && $fromPost->isSend) { $isLog = $fromPost->isLog; $params['elapsedtime'] = $fromPost->elapsedtime; $params['percent'] = $fromPost->percent; } else { if (isset($post['percent'])) { $isLog = $percent != $tudu->selfPercent || $elapsedtime > 0; } else { $isLog = $elapsedtime > 0; } } $params['islog'] = $isLog; if ($isLog && $tudu->selfPercent < 100) { $params['elapsedtime'] = $elapsedtime; $params['percent'] = $percent; } // 处理网盘附件 if (!empty($post['nd-attach'])) { $params['attachment'] = array_diff($params['attachment'], $post['nd-attach']); $daoNdFile = $this->getDao('Dao_Td_Netdisk_File'); $daoAttachment = $this->getDao('Dao_Td_Attachment_File'); foreach ($post['nd-attach'] as $ndfileId) { $fileId = $ndfileId; $attach = $daoAttachment->getFile(array('fileid' => $fileId)); if (null !== $attach) { $params['attachment'][] = $fileId; continue; } $file = $daoNdFile->getFile(array('uniqueid' => $this->_user->uniqueId, 'fileid' => $ndfileId)); if ($file->fromFileId) { $fileId = $file->fromFileId; } if ($file->attachFileId) { $fileId = $file->attachFileId; } $ret = $daoAttachment->createFile(array('uniqueid' => $this->_user->uniqueId, 'fileid' => $fileId, 'orgid' => $this->_user->orgId, 'filename' => $file->fileName, 'path' => $file->path, 'type' => $file->type, 'size' => $file->size, 'createtime' => time())); if ($ret) { $params['attachment'][] = $fileId; } } } if (!$fromPost) { $postId = $storage->createPost($params); if (!$postId) { return $this->json(false, $this->lang['post_send_failure']); } // 添加操作日志 $this->_writeLog(Dao_Td_Log_Log::TYPE_POST, $postId, Dao_Td_Log_Log::ACTION_CREATE, $params); } else { $postId = $fromPost->postId; // 增加最后编辑信息 if ($fromPost->isSend) { $params['lastmodify'] = implode(chr(9), array($uniqueId, $this->_timestamp, $this->_user->trueName)); } else { $params['createtime'] = time(); } $storage->updatePost($tuduId, $postId, $params); // 记录更新内容 $arrFromPost = $fromPost->toArray(); $updates = array(); foreach ($params as $key => $val) { if (in_array($key, array('file', 'attachment'))) { continue; } if ($val != $arrFromPost[$key]) { $updates[$key] = $val; } } // 添加操作日志 $this->_writeLog(Dao_Td_Log_Log::TYPE_POST, $postId, Dao_Td_Log_Log::ACTION_CREATE, $updates); } if ($type != 'save') { // 未读 if (!$fromPost || !$fromPost->isSend) { $manager->markAllUnread($tudu->tuduId); } // 标记已经读 // 加入了批量更新和回复,所以在更新时就需要标示已读 if ($tudu->isRead) { $manager->markRead($tudu->tuduId, $this->_user->uniqueId, true); } $config = $this->bootstrap->getOption('httpsqs'); // 插入消息队列 $httpsqs = new Oray_Httpsqs($config['host'], $config['port'], $config['chartset'], $config['name']); $tuduPercent = $tudu->percent; $flowPercent = null; if ($isLog && $tudu->selfPercent < 100) { if ($tudu->flowId) { $tuduPercent = $manager->updateFlowProgress($tudu->tuduId, $tudu->uniqueId, $tudu->stepId, (int) $params['percent'], $flowPercent); } else { $tuduPercent = $manager->updateProgress($tudu->tuduId, $tudu->uniqueId, (int) $params['percent']); } if (!$fromPost || !$fromPost->isSend) { // 添加操作日志 $this->_writeLog(Dao_Td_Log_Log::TYPE_TUDU, $tudu->tuduId, Dao_Td_Log_Log::ACTION_TUDU_PROGRESS, array('percent' => $params['percent'], 'elapsedtime' => $tudu->elapsedTime + (int) $post['elapsedtime'])); } } // 自动确认 if ($isLog && $tuduPercent == 100 && null === $flowPercent || $isLog && $flowPercent == 100) { if ($isSender && $isAccepter || !$tudu->needConfirm) { $isDoneTudu = true; $doneParams = array('tuduid' => $tudu->tuduId, 'percent' => $params['percent'], 'elapsedtime' => $tudu->elapsedTime + (int) $post['elapsedtime']); // 添加到发起人图度箱 -- 待确认中 } else { /* @var $addressBook Tudu_AddressBook */ $addressBook = Tudu_AddressBook::getInstance(); $sender = $addressBook->searchUser($this->_user->orgId, $tudu->sender); $manager->addLabel($tudu->tuduId, $sender['uniqueid'], '^i'); } } // 计算父级图度进度 及 图度组达到100%时,确认 if ($tudu->parentId) { $parentPercent = $manager->calParentsProgress($tudu->parentId); if ($parentPercent >= 100) { $sendParam['confirm'] = true; } } // 发送回复 $manager->sendPost($tuduId, $postId); // 统计时间 if ($isLog) { $manager->calcElapsedTime($tuduId); } // 周期任务 if ($isLog && $tudu->cycleId && $tuduPercent >= 100) { $daoCycle = $this->getDao('Dao_Td_Tudu_Cycle'); $cycle = $daoCycle->getCycle(array('cycleid' => $tudu->cycleId)); if ($cycle->count == $tudu->cycleNum) { $sendParam['cycle'] = true; } } $sendParam['tuduid'] = $tudu->tuduId; $sendParam['from'] = $this->_user->userName; $sendParam['sender'] = $this->_user->trueName; $sendParam['uniqueid'] = $this->_user->uniqueId; $sendParam['postid'] = $postId; $sendParam['tsid'] = $this->_user->tsId; $sendParam['server'] = $this->_request->getServer('HTTP_HOST'); // 处理工作流 // 处理流程发送过程 if ($tudu->type == 'task' && $percent >= 100) { /* @var $daoFlow Dao_Td_Tudu_Flow */ $daoFlow = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Flow', Tudu_Dao_Manager::DB_TS); $flowData = $daoFlow->getFlow(array('tuduid' => $tudu->tuduId)); if (null !== $flowData) { /* @var $flow Model_Tudu_Extension_Flow */ $flow = new Model_Tudu_Extension_Flow($flowData->toArray()); $isCurrentUser = $flow->isCurrentUser($this->_user->uniqueId); $isComplete = false; if ($isCurrentUser) { $flow->complete($this->_user->uniqueId); if ($flow->isStepComplete()) { $isComplete = true; $flow->flowTo(); } } $modelFlow = $flow->getHandler($flow->getHandlerClass()); $modelFlow->updateFlow($flow); if ($flow->currentStepId != '^end') { $isDoneTudu = false; } // 发送下一步 if (false === strpos($flow->currentStepId, '^') && $isComplete) { $section = $flow->getStepSection($flow->currentStepId); $tuduParams = array('tuduid' => $tudu->tuduId, 'type' => $tudu->type, 'fromtudu' => $tudu); $users = array(); foreach ($section as $sec) { $users[$sec['username']] = array('uniqueid' => $sec['uniqueid'], 'truename' => $sec['truename'], 'username' => $sec['username'], 'email' => $sec['username']); } $step = $flow->getStep($flow->currentStepId); if ($step['type'] == 1) { $tuduParams['reviewer'] = $users; } else { $tuduParams['to'] = $users; if ($step['type'] == 2) { $tuduParams['acceptmode'] = 1; } } $sendTudu = new Model_Tudu_Tudu($tuduParams); $daoTudu = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Tudu', Tudu_Dao_Manager::DB_TS); $params = $sendTudu->getStorageParams(); if (!empty($params['to'])) { $accepters = $daoTudu->getAccepters($tudu->tuduId); foreach ($accepters as $item) { $daoTudu->removeAccepter($tudu->tuduId, $item['uniqueid']); } } $daoTudu->updateTudu($tudu->tuduId, $params); $modelTudu = new Model_Tudu_Send_Common(); $modelTudu->send($sendTudu); // 更新进度 $manager->updateProgress($tudu->tuduId, $this->_user->uniqueId); if ($tudu->parentId) { $manager->calParentsProgress($tudu->parentId); } } } } // 自动确认 if ($isDoneTudu && isset($doneParams)) { $manager->doneTudu($doneParams['tuduid'], true, 0); // 添加操作日志 $this->_writeLog(Dao_Td_Log_Log::TYPE_TUDU, $doneParams['tuduid'], Dao_Td_Log_Log::ACTION_TUDU_DONE, array('percent' => $doneParams['percent'], 'elapsedtime' => $doneParams['elapsedtime']), false, true); } // 回复消息 $data = implode(' ', array('tudu', 'reply', '', http_build_query($sendParam))); $httpsqs->put($data, 'tudu'); } return $this->json(true, $this->lang['post_send_success'], array('postid' => $postId)); }
/** * * @param Model_Tudu_Tudu $tudu */ public function prepareTuduReview(Model_Tudu_Tudu &$tudu) { /* @var $daoFlow Dao_Td_Tudu_Flow */ $daoFlow = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Flow', Tudu_Dao_Manager::DB_TS); $flowData = $daoFlow->getFlow(array('tuduid' => $tudu->tuduId)); if (null === $flowData) { require_once 'Model/Tudu/Exception.php'; throw new Model_Tudu_Exception('Not allow to review tudu', Model_Tudu_Exception::PERMISSION_DENIED); } $flow = new Model_Tudu_Extension_Flow($flowData->toArray()); $flow->fromFlow = true; if (!$flow->isCurrentUser($tudu->uniqueId)) { require_once 'Model/Tudu/Exception.php'; throw new Model_Tudu_Exception('Not allow to review tudu', Model_Tudu_Exception::PERMISSION_DENIED); } // 处理同意流程 $flow->review($tudu->uniqueId, $tudu->agree); if (!$tudu->flowId) { $this->renewTuduFlow($tudu, $flow); } else { $flow->flowTo(); $step = $flow->getSteps(); if ($step['type'] == 1) { $tudu->reviewer = $flow->getStepSection($step['stepid']); } else { $tudu->to = $flow->getStepSection($step['stepid']); } } $tudu->setExtension($flow); }