/** * 发送图度 * * @param Tudu_Model_Tudu_Entity_Tudu $tudu */ public function send(Tudu_Model_Tudu_Entity_Tudu &$tudu, &$output) { $user = self::getResource(self::RESOURCE_NAME_USER); $error = null; $code = 0; $isSender = true; $isAccepter = false; $fromTudu = null; $logDetail = array(); $logAction = 'create'; /* @var Dao_Td_Tudu_Tudu */ $daoTudu = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Tudu', Tudu_Dao_Manager::DB_TS); if ($tudu->tuduId) { $fromTudu = $daoTudu->getTuduById($user->uniqueId, $tudu->tuduId); $isSender = true; do { if (null === $fromTudu) { $error = 'tudu not exists'; break; } $isSender = $fromTudu->sender == $user->userName; // 草稿,权限上属新建操作 if ($tudu->isDraft) { if (!$tudu->uniqueId || !$user->getAccess()->isAllowed(Tudu_Access::PERM_CREATE_TUDU)) { $error = 'perm deny create tudu'; break; } // 编辑图度权限 // 有权限 && (发起人 || 版主 || 分区负责人) } else { if (!$user->getAccess()->isAllowed(Tudu_Access::PERM_UPDATE_TUDU)) { $error = 'perm deny create tudu'; break; } if (!$isSender) { // 版主权限 $boards = $this->_getBoards($user->orgId); $board = $boards[$fromTudu->boardId]; $isModerator = array_key_exists($user->userName, $board['moderators']); $isSuperModerator = null; // 不是版主,看看是不是分区负责人 if (!$isModerator && isset($boards[$board['parentid']])) { $parentBoard = $boards[$board['parentid']]; $isSuperModerator = array_key_exists($user->userName, $parentBoard['moderators']); } if (!$isModerator && !$isSuperModerator) { $error = 'perm deny create tudu'; break; } } $logAction = 'update'; } } while (false); if (null !== $error) { require_once 'Tudu/Model/Tudu/Exception.php'; throw new Tudu_Model_Tudu_Exception($error); } $params = array('stepid' => $fromTudu->stepId, 'postid' => $fromTudu->postId, 'from' => $fromTudu->sender . ' ' . $fromTudu->from[0], 'email' => $fromTudu->from[0], 'sender' => $fromTudu->sender); if ($tudu->isDraft) { $params['lastmodify'] = implode(chr(9), array($user->uniqueId, time(), $user->trueName)); } else { $params['createtime'] = time(); } $tudu->setAttribute($params); $logDetail = $this->_getLogDetails($params, $fromTudu); } else { // 创建权限 if (!$user->getAccess()->isAllowed(Tudu_Access::PERM_CREATE_TUDU)) { require_once 'Tudu/Model/Tudu/Exception.php'; throw new Tudu_Model_Tudu_Exception('perm deny create tudu'); } $tudu->setAttribute(array('tuduid' => Dao_Td_Tudu_Tudu::getTuduId(), 'isdraft' => true, 'from' => $user->userName . ' ' . $user->trueName, 'email' => $user->userName, 'sender' => $user->trueName, 'createtime' => time())); $logDetail = $this->_getLogDetails($tudu->getAttributes(), null); } // 处理扩展数据内容 $extensions = $tudu->getExtensions(); foreach ($extensions as $item) { if ($item instanceof Tudu_Model_Tudu_Entity_Extension_Flow) { $this->getExtension($item->getHandler())->prevSave($tudu, $item); } } // 保存图度数据 if (null !== $fromTudu) { $tuduId = $this->updateTudu($tudu); } else { $tuduId = $this->createTudu($tudu); } foreach ($extensions as $item) { if ($item instanceof Tudu_Model_Tudu_Entity_Extension_Flow || $item instanceof Tudu_Model_App_Attend_Tudu_Apply) { $this->getExtension($item->getHandler())->onSave($tudu, $item); } } $output['tuduid'] = $tudu->tuduId; // 执行发送操作 $this->sendTudu($tudu); foreach ($extensions as $item) { if ($item instanceof Tudu_Model_App_Attend_Tudu_Apply) { $this->getExtension($item->getHandler())->onSend($tudu, $item); } } $sqsParam = array('tsid' => $user->tsId, 'tuduid' => $tudu->tuduId, 'from' => $user->userName, 'uniqueid' => $user->uniqueId, 'server' => $_SERVER['HTTP_HOST'], 'type' => $tudu->type, 'ischangedCc' => isset($fromTudu) && !$fromTudu->isDraft && $tudu->cc ? true : false); $httpsqs = self::getResource(self::RESOURCE_NAME_HTTPSQS); $httpsqs->put(implode(' ', array('tudu', isset($fromTudu) ? 'update' : 'create', '', http_build_query($sqsParam))), 'tudu'); $this->createLog(Dao_Td_Log_Log::TYPE_TUDU, $tudu->tuduId, $logAction, $logDetail, 0); return $tuduId; }
/** * * @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']); } }
/** * 获取图度ID * * @return string */ private function _getTuduId() { return $this->_tuduDao->getTuduId(); }
/** * 发送图度 * * @param Model_Tudu_Tudu $tudu * @throws Model_Tudu_Exception */ public function compose(Model_Tudu_Tudu &$tudu) { if (!$tudu->tuduId) { $tudu->setAttribute('tuduid', Dao_Td_Tudu_Tudu::getTuduId()); } // 保存图度 if (null !== $tudu->fromTudu) { if (!$tudu->fromTudu->isDraft) { $user = Tudu_User::getInstance(); $time = time(); $tudu->lastPostTime = $time; $tudu->lastPoster = $user->trueName; $tudu->lastModify = implode(chr(9), array($user->uniqueId, $time, $user->trueName)); } $this->_updateTudu($tudu); } else { $this->_createTudu($tudu); } $logAction = null !== $tudu->fromTudu && !$tudu->fromTudu->isDraft ? 'update' : 'send'; $this->_tuduLog($logAction, $tudu); }
/** * 周期任务/会议 * 图度数据 * * @param $tudu * @param $fromUnId */ public function getCycleTuduParams($tudu, $cycle, $to, $fromUnId, $time) { // 基本参数 return array('orgid' => $tudu->orgId, 'boardid' => $tudu->boardId, 'classid' => $tudu->classId, 'tuduid' => Dao_Td_Tudu_Tudu::getTuduId(), 'special' => Dao_Td_Tudu_Tudu::SPECIAL_CYCLE, 'cycleid' => $cycle->cycleId, 'uniqueid' => $fromUnId, 'email' => $tudu->sender, 'type' => $tudu->type, 'subject' => $tudu->subject, 'from' => $tudu->from[3] . ' ' . $tudu->from[0], 'to' => implode("\n", $to), 'priority' => $tudu->priority, 'privacy' => $tudu->privacy, 'status' => Dao_Td_Tudu_Tudu::STATUS_UNSTART, 'content' => $tudu->content, 'poster' => $tudu->from[0], 'posterinfo' => $tudu->posterInfo, 'lastposter' => $tudu->from[0], 'lastposttime' => time(), 'starttime' => $time[0], 'endtime' => $time[1], 'createtime' => time(), 'password' => $tudu->password, 'isauth' => $tudu->isAuth, 'cyclenum' => $tudu->cycleNum + 1, 'stepid' => Dao_Td_Tudu_Step::getStepId(), 'stepnum' => 1, 'issend' => 1, 'acceptmode' => $tudu->acceptMode, 'needconfirm' => $tudu->needConfirm, 'attachment' => array(), 'file' => array()); }
/** * * @param $params * @param $tudu */ public function prepareTudu(array $params, Dao_Td_Tudu_Record_Tudu $tudu = null) { if (null !== $tudu) { $params['isdraft'] = $tudu->isDraft; $params['postid'] = $tudu->postId; $params['tuduid'] = $tudu->tuduId; $params['from'] = $tudu->from[3] . ' ' . $tudu->from[0]; $params['sender'] = $tudu->sender; $params['stepid'] = $tudu->stepId; $params['type'] = $tudu->type; $params['flowid'] = $tudu->flowId; if (!$tudu->isDraft) { $params['boardid'] = $tudu->boardId; } if ($tudu->parentId) { $params['parentid'] = $tudu->parentId; } if ($tudu->rootId) { $params['rootid'] = $tudu->rootId; } //$params['lastpost'] = ; // 继承需要的字段 if (!$tudu->isDraft) { // 抄送人,只添加 if ($tudu->cc) { $cc = !empty($params['cc']) ? $params['cc'] : array(); foreach ($tudu->cc as $key => $item) { if (false !== strpos($key, '@')) { $cc[$key] = array('email' => $key, 'truename' => $item[0]); } else { $cc[$key] = array('groupid' => $key, 'truename' => $item[0]); } } $params['cc'] = $cc; } if ($tudu->bcc) { $bcc = !empty($params['bcc']) ? $params['bcc'] : array(); foreach ($tudu->bcc as $key => $item) { if (false !== strpos($key, '@')) { $bcc[$key] = array('email' => $key, 'truename' => $item[0]); } else { $bcc[$key] = array('groupid' => $key, 'truename' => $item[0]); } } $params['bcc'] = $bcc; } } } else { $params['tuduid'] = Dao_Td_Tudu_Tudu::getTuduId(); } if (isset($params['vote'])) { if (!Tudu_Tudu_Extension::isRegistered('vote')) { Tudu_Tudu_Extension::registerExtension('vote', 'Tudu_Tudu_Extension_Vote'); } } $tudu = new Tudu_Tudu_Storage_Tudu($params, $tudu); if ($tudu->type == 'task' && $tudu->to && is_array($tudu->to)) { $to = array(); foreach ($tudu->to as $item) { foreach ($item as $val) { $to[$val['email']] = array('email' => $val['email'], 'truename' => $val['truename']); if (isset($val['percent'])) { $to[$val['email']]['percent'] = $val['percent']; } } break; } $tudu->setAttributes(array('to' => $to, 'stepto' => $tudu->to)); } $extensions = Tudu_Tudu_Extension::getRegisteredExtensions(); foreach ($extensions as $key) { Tudu_Tudu_Extension::getExtension($key)->onPrepare($tudu, $params); } return $tudu; }