/** * 创建图度 * * @param $tudu */ public static function createTudu(Tudu_Model_Tudu_Entity_Tudu &$tudu) { $params = $tudu->getAttributes(); $daoTudu = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Tudu', Tudu_Dao_Manager::DB_TS); $daoPost = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Post', Tudu_Dao_Manager::DB_TS); $params['to'] = !empty($params['to']) ? Tudu_Model_Entity_Tudu::formatReceiver($params['to']) : null; $params['cc'] = !empty($params['cc']) ? Tudu_Model_Entity_Tudu::formatReceiver($params['cc']) : null; $params['bcc'] = !empty($params['bcc']) ? Tudu_Model_Entity_Tudu::formatReceiver($params['bcc']) : null; $tuduId = $daoTudu->createTudu($params); if (!$tuduId) { require_once 'Tudu/Model/Tudu/Exception.php'; throw new Tudu_Model_Tudu_Exception('Save tudu failed'); } $post = array('orgid' => $params['orgid'], 'boardid' => $params['boardid'], 'tuduid' => $tuduId, 'uniqueid' => $params['uniqueid'], 'postid' => Dao_Td_Tudu_Post::getPostId(), 'poster' => $params['poster'], 'email' => $params['email'], 'content' => !empty($params['content']) ? $params['content'] : '', 'isfirst' => 1, 'issend' => 1); $attachments = $tudu->getAttachments(); $attachNum = 0; foreach ($attachments as $attach) { if ($attach['isattach']) { $attachNum++; } } $post['attachnum'] = $attachNum; $postId = $daoPost->createPost($post); if (!$postId) { $daoTudu->deleteTudu($tuduId); require_once 'Tudu/Model/Tudu/Exception.php'; throw new Tudu_Model_Tudu_Exception('Save tudu failed'); } if (count($attachments) > 0) { $daoFile = Tudu_Dao_Manager::getDao('Dao_Td_Attachment_File', Tudu_Dao_Manager::DB_TS); foreach ($attachments as $attach) { $daoFile->addPost($tuduId, $postId, $attach['fileid'], (bool) $attach['isattach']); } } $output['tuduid'] = $tuduId; $tudu->setAttribute(array('tuduid' => $tuduId, 'postid' => $post['postid'])); return $tuduId; }
/** * (non-PHPdoc) * @see Model_Tudu_Compose_Abstract::compose() */ public function compose(Model_Tudu_Tudu &$tudu) { /* @var $daoTudu Dao_Td_Tudu_Tudu */ $daoTudu = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Tudu', Tudu_Dao_Manager::DB_TS); $user = Tudu_User::getInstance(); $attrs = $tudu->getStorageParams(); if ($this->_isModified) { $params = array(); foreach ($attrs as $key => $val) { if (in_array($key, array('content', 'attach', 'attachment', 'subject', 'flowid', 'from'))) { continue; } $params[$key] = $val; } if (!empty($attrs['stepid'])) { $params['stepid'] = $attrs['stepid']; } $time = time(); $params['lastposttime'] = $time; $params['lastposter'] = $user->trueName; if (!$daoTudu->updateTudu($tudu->tuduId, $params)) { require_once 'Model/Tudu/Exception.php'; throw new Model_Tudu_Exception('Tudu save failed', Model_Tudu_Exception::SAVE_FAILED); } } else { $params = array('to' => $attrs['to']); if (!empty($attrs['cc'])) { $params['cc'] = $attrs['cc']; } if (!empty($attrs['bcc'])) { $params['bcc'] = $attrs['bcc']; } if (!empty($attrs['stepid'])) { $params['stepid'] = $attrs['stepid']; } if (!$daoTudu->updateTudu($tudu->tuduId, $params)) { require_once 'Model/Tudu/Exception.php'; throw new Model_Tudu_Exception('Tudu save failed', Model_Tudu_Exception::SAVE_FAILED); } } /* @var $daoPost Dao_Td_Tudu_Post */ $daoPost = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Post', Tudu_Dao_Manager::DB_TS); /* @var $daoAttach Dao_Td_Attachment_File */ $daoAttach = Tudu_Dao_Manager::getDao('Dao_Td_Attachment_File', Tudu_Dao_Manager::DB_TS); /* @var $daoFile Dao_Td_Netdisk_File */ $daoFile = Tudu_Dao_Manager::getDao('Dao_Td_Netdisk_File', Tudu_Dao_Manager::DB_TS); $toArr = array(); foreach ($tudu->to as $sec) { foreach ($sec as $item) { $toArr[] = array('username' => $item['username'], 'truename' => $item['truename']); } break; } $header = array('action' => 'forward', 'to' => $toArr); if ($tudu->reviewer) { $header['reviewer'] = array(); foreach ($tudu->reviewer as $sec) { foreach ($sec as $item) { $header['reviewer'][] = array('username' => $item['username'], 'truename' => $item['truename']); } } } $attachments = $tudu->getAttachments(); // 处理网盘附件 $attachNum = 0; foreach ($attachments as $k => $attach) { if ($attach['isnetdisk']) { $fileId = $attach['fileid']; if (null !== $daoAttach->getFile(array('fileid' => $fileId))) { $ret['attachment'][] = $fileId; continue; } $file = $daoFile->getFile(array('uniqueid' => $user->uniqueId, 'fileid' => $fileId)); if (null === $file) { continue; } $fileId = $file->fromFileId ? $file->fromFileId : $file->attachFileId; $ret = $daoAttach->createFile(array('uniqueid' => $user->uniqueId, 'fileid' => $fileId, 'orgid' => $user->orgId, 'filename' => $file->fileName, 'path' => $file->path, 'type' => $file->type, 'size' => $file->size, 'createtime' => $this->_time)); if ($ret) { $attachments[$k]['fileid'] = $fileId; } else { unset($attachments[$k]); } } if ($attach['isattach']) { $attachNum++; } } $postParams = array('orgid' => $tudu->orgId, 'tuduid' => $tudu->tuduId, 'boardid' => $tudu->boardId, 'postid' => Dao_Td_Tudu_Post::getPostId($tudu->tuduId), 'uniqueid' => $this->_user->uniqueId, 'poster' => $this->_user->trueName, 'email' => $this->_user->userName, 'content' => $tudu->content, 'attachnum' => $attachNum, 'createtime' => time(), 'header' => $header); $postId = $daoPost->createPost($postParams); $daoPost->sendPost($tudu->tuduId, $postId); $attachments = $tudu->getAttachments(); foreach ($attachments as $id => $attach) { $daoAttach->addPost($tudu->tuduId, $postId, $attach['fileid'], $attach['isattach']); } $this->_tuduLog('forward', $tudu); }
/** * (non-PHPdoc) * @see Model_Tudu_Compose_Abstract::compose() */ public function compose(Model_Tudu_Tudu &$tudu) { /* @var $daoTudu Dao_Td_Tudu_Tudu */ $daoTudu = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Tudu', Tudu_Dao_Manager::DB_TS); $attrs = $tudu->getStorageParams(); $params = array('to' => $attrs['to']); if (!empty($attrs['cc'])) { $params['cc'] = $attrs['cc']; } if (!empty($attrs['bcc'])) { $params['bcc'] = $attrs['bcc']; } if (!$daoTudu->updateTudu($tudu->tuduId, $params)) { require_once 'Model/Tudu/Exception.php'; throw new Model_Tudu_Exception('Tudu save failed', Model_Tudu_Exception::SAVE_FAILED); } /* @var $daoPost Dao_Td_Tudu_Post */ $daoPost = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Post', Tudu_Dao_Manager::DB_TS); /* @var $daoFile Dao_Td_Attachment_File */ $daoFile = Tudu_Dao_Manager::getDao('Dao_Td_Attachment_File', Tudu_Dao_Manager::DB_TS); $toArr = array(); foreach ($tudu->to as $sec) { foreach ($sec as $item) { $toArr[] = array('username' => $item['username'], 'truename' => $item['truename']); } break; } $header = array('action' => 'forward', 'to' => $toArr); if ($tudu->reviewer) { $header['reviewer'] = array(); foreach ($tudu->reviewer as $sec) { foreach ($sec as $item) { $header['reviewer'][] = array('username' => $item['username'], 'truename' => $item['truename']); } } } $postParams = array('orgid' => $tudu->orgId, 'tuduid' => $tudu->tuduId, 'boardid' => $tudu->boardId, 'postid' => Dao_Td_Tudu_Post::getPostId($tudu->tuduId), 'uniqueid' => $this->_user->uniqueId, 'poster' => $this->_user->trueName, 'email' => $this->_user->userName, 'content' => $tudu->content, 'createtime' => time(), 'header' => $header); $postId = $daoPost->createPost($postParams); $daoPost->sendPost($tudu->tuduId, $postId); $attachments = $tudu->getAttachments(); foreach ($attachments as $id => $attach) { $daoFile->addPost($tudu->tuduId, $postId, $attach['attachid'], $attach['isattachment']); } $this->_tuduLog('forward', $tudu); }
/** * * @param Model_Tudu_Tudu $tudu * @throws Model_Tudu_Exception */ protected function _createTudu(Model_Tudu_Tudu &$tudu) { /* @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); /* @var $daoAttach Dao_Td_Attachment_File */ $daoAttach = Tudu_Dao_Manager::getDao('Dao_Td_Attachment_File', Tudu_Dao_Manager::DB_TS); /* @var $daoFile Dao_Td_Netdisk_File */ $daoFile = Tudu_Dao_Manager::getDao('Dao_Td_Netdisk_File', Tudu_Dao_Manager::DB_TS); if (!$tudu->tuduId) { $tudu->tuduId = Dao_Td_Tudu_Tudu::getTuduId(); } if (!$tudu->postId) { $tudu->postId = Dao_Td_Tudu_Post::getPostId($tudu->tuduId); } $params = $tudu->getStorageParams(); $attachments = $tudu->getAttachments(); // 处理网盘附件 $attachNum = 0; foreach ($attachments as $k => $attach) { if ($attach['isnetdisk']) { $fileId = $attach['fileid']; if (null !== $daoAttach->getFile(array('fileid' => $fileId))) { $ret['attachment'][] = $fileId; continue; } $file = $daoFile->getFile(array('uniqueid' => $this->_user->uniqueId, 'fileid' => $fileId)); if (null === $file) { continue; } $fileId = $file->fromFileId ? $file->fromFileId : $file->attachFileId; $ret = $daoAttach->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' => $this->_time)); if ($ret) { $attachments[$k]['fileid'] = $fileId; } else { unset($attachments[$k]); } } if ($attach['isattach']) { $attachNum++; } } $params['attachnum'] = $attachNum; $params['isfirst'] = 1; $tuduId = $daoTudu->createTudu($params); if (!$tuduId) { require_once 'Model/Tudu/Exception.php'; throw new Model_Tudu_Exception('Tudu save failed', Model_Tudu_Exception::SAVE_FAILED); } $params['issend'] = 1; $postId = $daoPost->createPost($params); if (!$postId) { $daoTudu->deleteTudu($tuduId); require_once 'Model/Tudu/Exception.php'; throw new Model_Tudu_Exception('Tudu content save failed', Model_Tudu_Exception::SAVE_FAILED); } $tudu->postId = $postId; foreach ($attachments as $attach) { $daoAttach->addPost($tuduId, $postId, $attach['fileid'], (bool) $attach['isattach']); } }
/** * (non-PHPdoc) * @see Model_Tudu_Compose_Abstract::compose() */ public function compose(Model_Tudu_Tudu &$tudu) { /* @var $daoTudu Dao_Td_Tudu_Tudu */ $daoTudu = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Tudu', Tudu_Dao_Manager::DB_TS); $attrs = $tudu->getStorageParams(); $params = array(); if (!empty($attrs['to'])) { $params['to'] = $attrs['to']; } if (!empty($attrs['cc'])) { $params['cc'] = $attrs['cc']; } if (isset($attrs['acceptmode'])) { $params['acceptmode'] = $attrs['acceptmode']; } if (!empty($params)) { if (!$daoTudu->updateTudu($tudu->tuduId, $params)) { require_once '/Model/Tudu/Exception.php'; throw new Model_Tudu_Exception('Review failed', Model_Tudu_Exception::SAVE_FAILED); } } // 发送回复 /* @var $daoPost Dao_Td_Tudu_Post */ $daoPost = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Post', Tudu_Dao_Manager::DB_TS); /* @var $daoFile Dao_Td_Attachment_File */ $daoFile = Tudu_Dao_Manager::getDao('Dao_Td_Attachment_File', Tudu_Dao_Manager::DB_TS); $header = array('action' => 'review', 'tudu-act-value' => $tudu->agree ? 1 : 0); if ($this->_fromTudu->type != 'notice') { $headerKey = $tudu->reviewer ? 'tudu-reviewer' : 'tudu-to'; $items = $tudu->reviewer ? $tudu->reviewer : $tudu->to; if ($items) { $val = array(); foreach ($items as $item) { $val[] = $item['truename']; } $header[$headerKey] = implode(',', $val); } } $postParams = array('orgid' => $this->_fromTudu->orgId, 'tuduid' => $this->_fromTudu->tuduId, 'boardid' => $this->_fromTudu->boardId, 'uniqueid' => $this->_user->uniqueId, 'postid' => Dao_Td_Tudu_Post::getPostId($this->_fromTudu->tuduId), 'poster' => $this->_user->trueName, 'posterinfo' => $this->_user->position, 'email' => $this->_user->userName, 'content' => $tudu->content, 'header' => $header, 'createtime' => time()); $postId = $daoPost->createPost($postParams); $daoPost->sendPost($tudu->tuduId, $postId); $attachments = $tudu->getAttachments(); foreach ($attachments as $id => $attach) { $daoFile->addPost($tudu->tuduId, $postId, $attach['attachid'], $attach['isattachment']); } $this->_tuduLog('review', $tudu); }
/** * 认领 * * 必要参数 * tuduid|uniqueid|orgid|username|server|postparams|truename */ public function claim(array $params) { if (empty($params['tuduid'])) { require_once 'Model/Tudu/Exception.php'; throw new Model_Tudu_Exception('Missing or invalid value of parameter "tuduid"', self::CODE_INVALID_TUDUID); } $orgId = $this->_user->orgId; $uniqueId = $this->_user->uniqueId; $userName = $this->_user->userName; $tuduId = $params['tuduid']; //$manager = $this->getManager(); /* @var $daoFlow Dao_Td_Tudu_Flow*/ $daoFlow = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Flow', Tudu_Dao_Manager::DB_TS); /* @var $daoTudu Dao_Td_Tudu_Flow*/ $daoTudu = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Tudu', Tudu_Dao_Manager::DB_TS); // 获取图度信息 $tudu = $daoTudu->getTuduById($uniqueId, $tuduId); // 判读图度是否存在 if (null == $tudu) { require_once 'Model/Tudu/Exception.php'; throw new Model_Tudu_Exception('This tudu is not exists', self::CODE_TUDU_NOTEXISTS); } // 获取步骤 $flowRecord = $daoFlow->getFlow(array('tuduid' => $tudu->tuduId)); $step = isset($flowRecord->steps[$flowRecord->currentStepId]) ? $flowRecord->steps[$flowRecord->currentStepId] : null; // 判断当前是否为认领操作 if (!$step || $step['type'] != Dao_Td_Tudu_Step::TYPE_CLAIM) { require_once 'Model/Tudu/Exception.php'; throw new Model_Tudu_Exception('This tudu current step is not claim', self::CODE_STEP_NOTCLAIM); } // 判读图度是否已有user认领 if ($tudu->acceptTime) { require_once 'Model/Tudu/Exception.php'; throw new Model_Tudu_Exception('This tudu current step is claimed', self::CODE_STEP_CLAIM_FINISH); } $accepters = $daoTudu->getAccepters($tuduId); foreach ($accepters as $accepter) { if ($uniqueId == $accepter['uniqueid']) { $claimAccepter = $accepter; } else { $removeAccepter[] = $accepter; } } require_once 'Model/Tudu/Extension/Flow.php'; $flow = new Model_Tudu_Extension_Flow(); $flow->setAttributes($flowRecord->toArray()); // 插入新的步骤 $stepId = Dao_Td_Tudu_Step::getStepId(); $flow->complete($flow->currentStepId, $this->_user->uniqueId); if ($tudu->flowId && strstr($step['next'], 'ST-')) { $flow->deleteStep($step['next']); } $flow->addStep(array('stepid' => $stepId, 'prev' => $step['stepid'], 'next' => $step['next'], 'type' => 0)); $flow->updateStep($step['stepid'], array('next' => $stepId)); $flow->addStepSection($stepId, array(array('uniqueid' => $this->_user->uniqueId, 'truename' => $this->_user->trueName, 'username' => $this->_user->userName, 'email' => $this->_user->userName, 'status' => 0))); $flow->flowTo($stepId); if (!$daoFlow->updateFlow($flow->tuduId, $flow->toArray())) { require_once 'Model/Tudu/Exception.php'; throw new Model_Tudu_Exception('Tudu flow save failed', self::CODE_SAVE_FAILED); } $ret = $daoTudu->updateTudu($tuduId, array('to' => $claimAccepter['accepterinfo'], 'stepid' => $stepId, 'stepnum' => count($flow->steps), 'acceptmode' => 0)); $params = array('accepttime' => time(), 'tudustatus' => Dao_Td_Tudu_Tudu::STATUS_DOING); // 更新认领人 td_tudu_user $ret = $daoTudu->updateTuduUser($tuduId, $uniqueId, $params); if (!$ret) { require_once 'Model/Tudu/Exception.php'; throw new Model_Tudu_Exception('Claim tudu failed', self::CODE_SAVE_FAILED); } // 更新图度的接受时间 $daoTudu->updateLastAcceptTime($tuduId); // 更新需要移除的执行人及去除“我执行”标签 if (!empty($removeAccepter)) { foreach ($removeAccepter as $rmAccept) { if (!$daoTudu->updateTuduUser($tuduId, $rmAccept['uniqueid'], array('role' => null))) { continue; } if (!$daoTudu->deleteLabel($tuduId, $rmAccept['uniqueid'], '^a')) { continue; } } } /* @var $daoPost Dao_Td_Tudu_Post */ $daoPost = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Post', Tudu_Dao_Manager::DB_TS); $content = sprintf('%s 认领了该图度。', $this->_user->trueName); $header = array('action' => 'claim', 'tudu-claimer' => $this->_user->trueName); $postParams = array('orgid' => $this->_user->orgId, 'boardid' => $tudu->boardId, 'tuduid' => $tudu->tuduId, 'uniqueid' => $this->_user->uniqueId, 'poster' => $this->_user->trueName, 'posterinfo' => $this->_user->position, 'email' => $this->_user->userName, 'postid' => Dao_Td_Tudu_Post::getPostId($tuduId), 'header' => $header, 'content' => $content, 'lastmodify' => implode(chr(9), array($this->_user->uniqueId, time(), $this->_user->trueName))); $postId = $daoPost->createPost($postParams); //发送回复 $daoPost->sendPost($tuduId, $postId); //标记未读 $daoTudu->markAllUnRead($tuduId); // 添加操作日志 $this->_writeLog(Dao_Td_Log_Log::TYPE_TUDU, $tuduId, Dao_Td_Log_Log::ACTION_TUDU_CLAIM, array('orgid' => $orgId, 'uniqueid' => $uniqueId, 'userinfo' => $this->_user->userInfo), array('claimuser' => $this->_user->trueName, 'claimtime' => time(), 'status' => Dao_Td_Tudu_Tudu::STATUS_DOING)); if (Tudu_Model::hasResource(Tudu_Model::RESOURCE_CONFIG)) { $config = Tudu_Model::getResource(Tudu_Model::RESOURCE_CONFIG); if ($config['httpsqs']) { $options = $config['httpsqs']; $charset = isset($config['charset']) ? $config['charset'] : 'utf-8'; $httpsqs = new Oray_Httpsqs($options['host'], $options['port'], $charset, $options['name']); $notifyTo = array($tudu->sender); $notifyTo = array_merge($notifyTo, array_keys($tudu->to)); if ($tudu->notifyAll) { $notifyTo = array_merge($notifyTo, array_keys($tudu->cc)); } $tpl = <<<HTML <strong>您刚收到一个新的回复</strong><br /> <a href="http://{$this->_user->domainName}/frame#m=view&tid=%s&page=1" target="_blank" _tid="{$tuduId}">%s</a><br /> 发起人:{$this->_user->trueName}<br /> 更新日期:%s<br /> {$content} HTML; $data = implode(' ', array('tudu', 'reply', '', http_build_query(array('tuduid' => $tudu->tuduId, 'from' => $userName, 'to' => implode(',', $notifyTo), 'content' => sprintf($tpl, $tudu->tuduId, $tudu->subject, date('Y-m-d H:i:s', time())))))); $httpsqs->put($data); } } }
/** * 获取回复ID * * @param string $tuduId * @return string */ private function _getPostId($tuduId) { return $this->_postDao->getPostId($tuduId); }
/** * 认领 */ public function claimAction() { // 获取步骤 $step = $this->_manager->getStep($this->_tudu->tuduId, $this->_tudu->stepId); // 判断当前是否为认领操作 if ($step->type != Dao_Td_Tudu_Step::TYPE_CLAIM) { return $this->json(false, $this->lang['step_not_claim']); } // 判读图度是否已有user认领 if ($this->_tudu->acceptTime) { return $this->json(false, $this->lang['tudu_has_already_claim']); } $ret = $this->_manager->claimTudu($this->_tudu->tuduId, $this->_tudu->orgId, $this->_user['uniqueid']); if (!$ret) { return $this->json(false, $this->lang['tudu_claim_failure']); } //创建回复 $content = sprintf($this->lang['claim_accepter_log'], $this->_user['truename']); $params = array('orgid' => $this->_tudu->orgId, 'boardid' => $this->_tudu->boardId, 'tuduid' => $this->_tudu->tuduId, 'uniqueid' => $this->_user['uniqueid'], 'poster' => $this->_user['truename'], 'email' => $this->_user['email'], 'postid' => Dao_Td_Tudu_Post::getPostId($this->_tudu->tuduId), 'content' => $content, 'lastmodify' => implode(chr(9), array($this->_user['uniqueid'], time(), $this->_user['truename']))); $postId = $this->_manager->createPost($params); $this->_manager->sendPost($this->_tudu->tuduId, $postId); // 标记为未读 $this->_manager->markAllUnRead($this->_tudu->tuduId); // 添加操作日志 $this->_writeLog(Dao_Td_Log_Log::TYPE_TUDU, $this->_tudu->tuduId, Dao_Td_Log_Log::ACTION_TUDU_CLAIM, array('claimuser' => $this->_user['truename'], 'claimtime' => time(), 'status' => Dao_Td_Tudu_Tudu::STATUS_DOING)); $notifyTo = array($this->_tudu->sender); $notifyTo = array_merge($notifyTo, array_keys($this->_tudu->to)); if ($this->_tudu->notifyAll) { $notifyTo = array_merge($notifyTo, array_keys($this->_tudu->cc)); } // 消息队列 $config = $this->_bootstrap->getOption('httpsqs'); $httpsqs = new Oray_Httpsqs($config['host'], $config['port'], $config['chartset'], $config['name']); $tpl = <<<HTML <strong>您刚收到一个新的回复</strong><br /> <a href="http://{$this->_request->getServer('HTTP_HOST')}/frame#m=view&tid=%s&page=1" target="_blank" _tid="{$this->_tudu->tuduId}">%s</a><br /> 发起人:{$this->_user['truename']}<br /> 更新日期:%s<br /> {$content} HTML; $data = implode(' ', array('tudu', 'reply', '', http_build_query(array('tuduid' => $this->_tudu->tuduId, 'from' => $this->_user['email'], 'to' => implode(',', $notifyTo), 'content' => sprintf($tpl, $this->_tudu->tuduId, $this->_tudu->subject, date('Y-m-d H:i:s', time())))))); $httpsqs->put($data); return $this->json(true, $this->lang['tudu_claim_success']); }
/** * 调用 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; }
/** * * @param Model_Tudu_Post $post */ public function save(Model_Tudu_Post &$post) { $time = time(); /* @var $daoPost Dao_Td_Tudu_Post */ $daoPost = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Post', Tudu_Dao_Manager::DB_TS); $params = array('content' => $post->content); if (null !== $post->percent) { $params['percent'] = $post->percent; } if (null !== $post->elapsedTime) { $params['elapsedtime'] = $post->elapsedTime; } if (null === $this->_fromPost) { $post->postId = Dao_Td_Tudu_Post::getPostId($this->_tudu->tuduId); $params['postid'] = $post->postId; $params['orgid'] = $this->_tudu->orgId; $params['boardid'] = $this->_tudu->boardId; $params['tuduid'] = $this->_tudu->tuduId; $params['uniqueid'] = $this->_user->uniqueId; $params['email'] = $this->_user->userName; $params['poster'] = $this->_user->trueName; $params['posterinfo'] = $this->_user->position; if (!$daoPost->createPost($params)) { require 'Model/Tudu/Exception.php'; throw new Model_Tudu_Exception('Save post failed', Model_Tudu_Exception::PERMISSION_DENIED); } } else { // 增加最后编辑信息 if ($this->_fromPost->isSend) { $params['lastmodify'] = implode(chr(9), array($this->_user->uniqueId, $time, $this->_user->trueName)); } else { $params['createtime'] = $time; } if (!$daoPost->updatePost($this->_tudu->tuduId, $this->_fromPost->postId, $params)) { require 'Model/Tudu/Exception.php'; throw new Model_Tudu_Exception('Save post failed', Model_Tudu_Exception::PERMISSION_DENIED); } } $attachments = $post->getAttachments(); if (count($attachments)) { /* @var $daoFile Td_Attachment_File */ $daoFile = Tudu_Dao_Manager::getDao('Dao_Td_Attachment_File', Tudu_Dao_Manager::DB_TS); /* @var $daoNdFile Td_Netdisk_File */ $daoNdFile = Tudu_Dao_Manager::getDao('Dao_Td_Netdisk_File', Tudu_Dao_Manager::DB_TS); foreach ($attachments as $attach) { if ($attach['isnetdisk']) { $fileId = $attach['fileid']; if (null !== $daoFile->getFile(array('fileid' => $fileId))) { $ret['attachment'][] = $fileId; continue; } $file = $daoNdFile->getFile(array('uniqueid' => $this->_user->uniqueId, 'fileid' => $fileId)); if (null === $file) { continue; } $fileId = $file->fromFileId ? $file->fromFileId : $file->attachFileId; $ret = $daoFile->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) { continue; } $attach['fileid'] = $fileId; } $daoFile->addPost($this->_tudu->tuduId, $post->postId, $attach['fileid'], $attach['isattach']); } } $updates = array(); if (null !== $this->_fromPost) { $arrFromPost = $this->_fromPost->toArray(); foreach ($params as $key => $val) { if (in_array($key, array('file', 'attachment'))) { continue; } if ($val != $arrFromPost[$key]) { $updates[$key] = $val; } } } else { $updates = $params; } /* @var $daoLog Dao_Td_Log_Log */ $daoLog = Tudu_Dao_Manager::getDao('Dao_Td_Log_Log', Tudu_Dao_Manager::DB_TS); $daoLog->createLog(array('orgid' => $this->_user->orgId, 'uniqueid' => $this->_user->uniqueId, 'operator' => $this->_user->userName . ' ' . $this->_user->trueName, 'logtime' => $time, 'targettype' => Dao_Td_Log_Log::TYPE_POST, 'targetid' => $post->postId, 'action' => $this->_fromPost ? Dao_Td_Log_Log::ACTION_CREATE : Dao_Td_Log_Log::ACTION_UPDATE, 'detail' => serialize($updates), 'privacy' => 0)); }
/** * 创建回复 * * @param $tuduId * @param $params */ public function createPost(array $params) { if (empty($params['orgid']) || empty($params['boardid']) || empty($params['tuduid']) || empty($params['uniqueid'])) { return false; } if (!isset($params['postid'])) { $params['postid'] = Dao_Td_Tudu_Post::getPostId($params['tuduid']); } $attachment = array(); if (!empty($params['attachment']) && is_array($params['attachment'])) { foreach ($params['attachment'] as $item) { $attachment[] = array('fileid' => $item, 'isattach' => true); } unset($params['attachment']); } $params['attachnum'] = count($attachment); if (!empty($params['file']) && is_array($params['file'])) { foreach ($params['file'] as $item) { $attachment[] = array('fileid' => $item, 'isattach' => false); } unset($params['file']); } $params['isfirst'] = false; /* @var $postDao Dao_Td_Tudu_Post */ $postDao = $this->getDao('Dao_Td_Tudu_Post'); $postId = $postDao->createPost($params); if (!$postId) { return false; } /* @var $fileDao Dao_Td_Attachment_File */ $daoFile = $this->getDao('Dao_Td_Attachment_File'); if (!empty($attachment)) { foreach ($attachment as $attach) { $daoFile->addPost($params['tuduid'], $postId, $attach['fileid'], (bool) $attach['isattach']); } } return $postId; }