/** * * @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)); }