/** * 创建图度 * * @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; }
/** * 调用 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; }