/** * (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 _updateTudu(Model_Tudu_Tudu &$tudu, $updates = null) { /* @var $daoTudu Dao_Td_Tudu_Tudu */ $daoTudu = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Tudu', Tudu_Dao_Manager::DB_TS); /* @var $daoPost Dao_Td_Post_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); $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; if (!empty($params['acceptmode'])) { $params['accepttime'] = null; $params['status'] = 0; } if ($tudu->fromTudu && !$tudu->fromTudu->isDraft) { unset($params['createtime']); } unset($params['from']); 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); } if (!$daoPost->updatePost($tudu->tuduId, $tudu->postId, $params)) { require_once 'Model/Tudu/Exception.php'; throw new Model_Tudu_Exception('Tudu content save failed', Model_Tudu_Exception::SAVE_FAILED); } // 添加附件关联 $daoAttach->deletePost($tudu->tuduId, $tudu->postId); foreach ($attachments as $attach) { $daoAttach->addPost($tudu->tuduId, $tudu->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); }