Пример #1
0
 /**
  * 获取对象实例
  *
  * @param Zend_Db_Adapter_Abstract $db
  * @return Tudu_Tudu_Manager
  */
 public static function getInstance($db = null)
 {
     if (null === self::$_instance) {
         self::$_instance = new self($db);
     }
     return self::$_instance;
 }
Пример #2
0
 /**
  * 转发图度
  *
  * @param $tudu
  * @param $output
  */
 public function forward(Tudu_Model_Tudu_Entity_Tudu $tudu, &$output)
 {
     $user = self::getResource(self::RESOURCE_NAME_USER);
     $error = null;
     $time = time();
     /* @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);
     do {
         if (!$tudu->tuduId) {
             $error = 'tudu not exists';
             break;
         }
         $fromTudu = $daoTudu->getTuduById($user->uniqueId, $tudu->tuduId);
         $isSender = $fromTudu->sender == $user->userName;
         $isAccepter = in_array($user->userName, $fromTudu->accepter);
         if (null === $fromTudu) {
             $error = 'tudu not exists';
             break;
         }
         // 转发权限
         if (!$user->getAccess()->isAllowed(Tudu_Access::PERM_FORWARD_TUDU)) {
             $error = 'perm deny forward tudu';
             break;
         }
         // 图度组
         if ($fromTudu->isTuduGroup) {
             $error = 'deny forward tudugroup';
             break;
         }
         // 不是执行人
         if (!$isAccepter) {
             $error = 'forbid non accepter forward';
             break;
         }
     } while (false);
     if (null !== $error) {
         require_once 'Tudu/Model/Tudu/Exception.php';
         throw new Tudu_Model_Tudu_Exception($error);
     }
     // 转发同时修改部分图度属性
     $modify = false;
     if ($user->getAccess()->isAllowed(Tudu_Access::PERM_FORWARD_TUDU)) {
         if ($isSender) {
             $modify = true;
         } else {
             $boards = $this->_getBoards($user->orgId);
             $board = $boards[$tudu->boardId];
             $isModerator = array_key_exists($this->_user->userId, $board['moderators']);
             $isSuperModerator = !empty($board['parentid']) && array_key_exists($this->_user->userId, $boards[$board['parentid']]['moderators']);
             if ($isModerator || $isSuperModerator) {
                 $modify = true;
             }
         }
     }
     $tuduParams = array('lastposttime' => time(), 'lastposter' => $user->trueName, 'lastforward' => implode("\n", array($user->trueName, $time)));
     // 允许修改图度参数
     if ($modify) {
         $tuduParams = array_merge($tudu->getAttributes(), $tuduParams);
     }
     // 处理执行人
     $to = $tudu->to;
     foreach ($to as $k => $item) {
         if ($fromTudu->selfPercent < 100) {
             $to[$k]['percent'] = $fromTudu->selfPercent;
         }
     }
     $tudu->to = $to;
     $to = array();
     foreach ($fromTudu->to as $k => $item) {
         if ($k != $user->userName) {
             $to[] = $k . ' ' . $item[0];
         }
     }
     $tudu->to = array_merge($tudu->to, Tudu_Tudu_Storage::formatRecipients(implode("\n", $to)));
     if ($fromTudu->selfPercent >= 100) {
         $tudu->to = array_merge($tudu->to, array($user->userName => array('email' => $user->userName, 'truename' => $user->trueName, 'percent' => $fromTudu->selfPercent)));
     }
     $tuduParams['to'] = Tudu_Model_Entity_Tudu::formatReceiver($tudu->to);
     $tuduParams['cc'] = Tudu_Model_Entity_Tudu::formatReceiver($tuduParams['cc']);
     $tuduParams['bcc'] = Tudu_Model_Entity_Tudu::formatReceiver($tuduParams['bcc']);
     // 更新图度
     if (!$daoTudu->updateTudu($tudu->tuduId, $tuduParams)) {
         require_once 'Tudu/Model/Tudu/Exception.php';
         throw new Tudu_Model_Tudu_Exception('Save tudu failed');
     }
     // 发送转发回复
     $attachments = $tudu->getAttachments();
     $attachNum = 0;
     foreach ($attachments as $attach) {
         if ($attach['isattach']) {
             $attachNum++;
         }
     }
     $postId = $daoPost->createPost(array('orgid' => $tudu->orgId, 'boardid' => $tudu->boardId, 'tuduid' => $tudu->tuduId, 'uniqueid' => $user->uniqueId, 'postid' => Dao_Td_Tudu_Post::getPostId(), 'poster' => $user->trueName, 'email' => $user->userName, 'content' => $tudu->content, 'attachnum' => $attachNum, 'isfirst' => 0));
     if (!$postId) {
         require_once 'Tudu/Model/Tudu/Exception.php';
         throw new Tudu_Model_Tudu_Exception('Save post failed');
     }
     $daoPost->sendPost($tudu->tuduId, $postId);
     // 添加附件
     /* @var $daoFile Dao_Td_Attachment_File */
     $daoFile = Tudu_Dao_Manager::getDao('Dao_Td_Attachment_File', Tudu_Dao_Manager::DB_TS);
     foreach ($attachments as $attach) {
         $daoFile->addPost($tudu->tuduId, $postId, $attach['fileid'], (bool) $attach['isattach']);
     }
     // 发送图度
     $this->sendTudu($tudu);
     // 加上转发标签
     $daoTudu->addLabel($tudu->tuduId, $user->uniqueId, '^w');
     $sqsParam = array('tsid' => $user->tsId, 'tuduid' => $tudu->tuduId, 'from' => $user->userName, 'uniqueid' => $user->uniqueId, 'server' => $_SERVER['HTTP_HOST'], 'type' => $tudu->type, 'ischangedCc' => $tudu->cc ? true : false);
     $httpsqs = self::getResource(self::RESOURCE_NAME_HTTPSQS);
     $httpsqs->put(implode(' ', array('tudu', 'update', '', http_build_query($sqsParam))), 'tudu');
     return $tudu->tuduId;
 }
Пример #3
0
 /**
  *
  * @param Model_Tudu_Tudu $tudu
  */
 protected function _getLogDetail(Model_Tudu_Tudu $tudu)
 {
     $detail = array();
     $params = $tudu->getStorageParams();
     if (!$this->_fromTudu || $this->_fromTudu->isDraft) {
         foreach ($params as $key => $value) {
             if (!empty($value)) {
                 $detail[$key] = $value;
             }
         }
         return $detail;
     }
     $excepts = array('attach', 'uniqueid', 'status', 'poster', 'posterinfo', 'lastposter', 'issend');
     $tudu = $this->_fromTudu->toArray();
     $ret = array();
     foreach ($params as $key => $val) {
         if (in_array($key, $excepts) || empty($val)) {
             continue;
         }
         if ($key == 'to') {
             if (count($params[$key]) != count($tudu['accepter'])) {
                 $val = Tudu_Tudu_Storage::formatReceiver($params[$key]);
             } elseif (is_array($params[$key])) {
                 foreach ($params[$key] as $k => $val) {
                     if (!in_array($k, $tudu['accepter'])) {
                         $val = Tudu_Tudu_Storage::formatReceiver($params[$key]);
                     }
                 }
             }
             continue;
         }
         if ($key == 'cc' || $key == 'bcc') {
             $val = Tudu_Tudu_Storage::formatReceiver($params[$key]);
         }
         if (array_key_exists($key, $tudu) && $params[$key] != $tudu[$key]) {
             $detail[$key] = $val;
         }
     }
     return $detail;
 }
Пример #4
0
 /**
  * 流动到指定(下一步)步骤
  *
  * @param Model_Tudu_Tudu $tudu
  */
 public function flowTo(Model_Tudu_Tudu &$tudu, $stepId = null)
 {
     /* @var $daoStep Dao_Td_Tudu_Step */
     $daoStep = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Step', Tudu_Dao_Manager::DB_TS);
     /* @var $daoStep Dao_Td_Tudu_Tudu */
     $daoTudu = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Tudu', Tudu_Dao_Manager::DB_TS);
     $steps = $daoStep->getSteps(array('tuduid' => $tudu->tuduId))->toArray('stepid');
     // 默认流动到下一步
     if (null === $stepId) {
         $currentStep = $steps[$tudu->stepId];
         // 是否需要流到下一步
         $users = $daoStep->getUsers($tudu->tuduId, $tudu->stepId);
         $currentUser = $users[$tudu->uniqueId];
         $nextSection = false;
         $nextProcessIndex = null;
         unset($users[$tudu->uniqueId]);
         $nextUsers = array();
         foreach ($users as $u) {
             // 不需要转到下一步
             if ($u['processindex'] == $currentUser['processindex'] && $u['status'] < 2) {
                 return;
             }
             // 本步骤有下一节点
             if (null === $nextProcessIndex && $u['processindex'] > $currentUser['processindex']) {
                 $nextSection = true;
                 $nextProcessIndex = $u['processindex'];
             }
             if (null !== $nextProcessIndex && $u['processindex'] === $nextProcessIndex) {
                 $arr = explode(' ', $u['userinfo']);
                 $nextUsers[$arr[0]] = array('email' => $arr[0], 'truename' => $arr[1]);
                 $daoStep->updateUser($tudu->tuduId, $tudu->stepId, $u['uniqueid'], array('status' => 1));
             }
         }
         if (!$nextSection) {
             $stepId = $currentStep['nextstepid'];
             if (isset($steps[$stepId])) {
                 $nextStep = $steps[$stepId];
                 $users = $daoStep->getUsers($tudu->tuduId, $stepId);
                 $procIndex = null;
                 $nextUsers = array();
                 foreach ($users as $u) {
                     if ($procIndex === null) {
                         $procIndex = $u['processindex'];
                     }
                     if (null !== $procIndex && $u['processindex'] !== $procIndex) {
                         break;
                     }
                     $arr = explode(' ', $u['userinfo']);
                     $nextUsers[$arr[0]] = array('email' => $arr[0], 'truename' => $arr[1]);
                     $daoStep->updateUser($tudu->tuduId, $stepId, $u['uniqueid'], array('status' => 1));
                 }
                 if ($nextStep['type'] == self::STEP_TYPE_EXAMINE) {
                     $tudu->reviewer = array($nextUsers);
                 } else {
                     $tudu->to = $nextUsers;
                 }
             }
         } else {
             $stepId = $tudu->stepId;
             if ($currentStep['type'] == self::STEP_TYPE_EXAMINE) {
                 $tudu->reviewer = array($nextUsers);
             } else {
                 $tudu->to = $nextUsers;
             }
         }
     }
     $updateStatus = false;
     if (isset($steps[$stepId]) && empty($nextSection)) {
         $nextStep = $steps[$stepId];
         $nextStepUsers = $daoStep->getUsers($tudu->tuduId, $nextStep['stepid']);
         $nextIndex = null;
         if ($nextStep['type'] == self::STEP_TYPE_EXAMINE) {
             $reviewer = array();
             foreach ($nextStepUsers as $item) {
                 if (null === $nextIndex) {
                     $nextIndex = $item['processindex'];
                 }
                 if (null !== $nextIndex && $item['processindex'] != $nextIndex) {
                     break;
                 }
                 list($userName, $trueName) = explode(' ', $item['userinfo']);
                 $reviewer[] = array('email' => $userName, 'truename' => $trueName);
                 // 更新上一步骤用户状态
                 if ($item['status'] > 1) {
                     $updateStatus = true;
                     $daoStep->updateUser($tudu->tuduId, $nextStep['stepid'], $item['uniqueid'], array('status' => 1));
                 }
             }
             $tudu->reviewer = array($reviewer);
         } elseif ($nextStep['type'] == self::STEP_TYPE_EXECUTE) {
             $users = array();
             // 准备执行人
             foreach ($nextStepUsers as $item) {
                 list($email, $trueName) = explode(' ', $item['userinfo']);
                 $users[$email] = array('email' => $email, 'truename' => $trueName, 'percent' => (int) $item['percent']);
                 // 更新上一步骤用户状态
                 if ($item['status'] > 1) {
                     $updateStatus = true;
                     $daoStep->updateUser($tudu->tuduId, $nextStep['stepid'], $item['uniqueid'], array('status' => 1));
                     $daoTudu->updateProgress($tudu->tuduId, $item['uniqueid'], 0);
                     if ($tudu->parentId) {
                         $daoTudu->calParentsProgress($tudu->parentId);
                     }
                 }
             }
             $tudu->reviewer = null;
             $tudu->to = Tudu_Tudu_Storage::formatRecipients($users);
             // 更新图度接收人信息
             //$manager->updateTudu($tudu['tuduid'], array('to' => Tudu_Tudu_Storage::formatReceiver($users)));
         }
         if ($updateStatus) {
             $daoStep->updateStep($tudu->tuduId, $nextStep['stepid'], array('status' => 0));
         }
         $stepId = $nextStep['stepid'];
         $sendParam['flowid'] = $tudu->flowId;
         $sendParam['nstepid'] = $stepId;
         $tudu->stepId = $stepId;
     } elseif (!$stepId) {
         $stepId = '^break';
         $tudu->stepId = '^break';
     }
     if ($stepId == '^break') {
         $tudu->to = array('email' => $tudu->from['username'], 'truename' => $tudu->from['truename']);
         // 更新图度接收人信息
         $daoTudu->updateTudu($tudu->tuduId, array('to' => $tudu->from['username'] . ' ' . $tudu->from['truename']));
     }
     // 准备发送
     $updateParams = array();
     if ($stepId != '^end') {
         // 移除原执行人
         if (!$tudu->reviewer) {
             $accepters = $daoTudu->getAccepters($tudu->tuduId);
             $to = $tudu->to;
             foreach ($accepters as $item) {
                 list($email, ) = explode(' ', $item['accepterinfo'], 2);
                 // 移除执行人角色,我执行标签
                 if (!empty($to) && !array_key_exists($email, $to) && $daoTudu->getChildrenCount($tudu->tuduId, $item['uniqueid']) <= 0) {
                     $daoTudu->removeAccepter($tudu->tuduId, $item['uniqueid']);
                     $daoTudu->deleteLabel($tudu->tuduId, $item['uniqueid'], '^a');
                 }
             }
         }
         require_once 'Model/Tudu/Compose/Send.php';
         $modelSend = new Model_Tudu_Compose_Send();
         $modelSend->send($tudu);
         // 执行人自动接受图度
         $lastUpdateTime = null;
         if ($stepId != '^break' && $stepId != '^head' && isset($steps[$stepId]) && $steps[$stepId]['type'] != Dao_Td_Tudu_Step::TYPE_EXAMINE) {
             if ($steps[$stepId]['type'] == Dao_Td_Tudu_Step::TYPE_EXECUTE) {
                 $users = $daoStep->getUsers($tudu->tuduId, $stepId);
                 foreach ($nextStepUsers as $item) {
                     $daoTudu->updateTuduUser($tudu->tuduId, $item['uniqueid'], array('accepttime' => time(), 'tudustatus' => Dao_Td_Tudu_Tudu::STATUS_DOING));
                     $lastUpdateTime = time();
                 }
                 $tudu->acceptMode = 0;
                 // 认领模式
             } else {
                 if ($steps[$stepId]['type'] == Dao_Td_Tudu_Step::TYPE_CLAIM) {
                     $tudu->acceptMode = 0;
                     $tudu->acceptTime = 0;
                 }
             }
         }
     }
     $tudu->stepId = $stepId;
     $attrs = $tudu->getStorageParams();
     unset($attrs['from'], $attrs['reviewer']);
     if (!empty($lastUpdateTime)) {
         $attrs['lastupdatetime'] = $lastUpdateTime;
     }
     $daoTudu->updateTudu($tudu->tuduId, $attrs);
 }
Пример #5
0
 /**
  * 格式化接收人(抄送,接收,审批等)参数
  *
  * @param $key
  * @param $suffix
  */
 private function _getReceiver($params, $name, $suffix = '')
 {
     $ret = array();
     if (isset($params[$name . 'idx' . $suffix]) && is_array($params[$name . 'idx' . $suffix])) {
         $recIdx = $params[$name . 'idx' . $suffix];
         $rec = array();
         foreach ($recIdx as $index) {
             $info = $params[$name . '-' . $index . $suffix];
             $arr = explode(' ', $info, 2);
             $item = array('truename' => $arr[1], 'email' => $arr[0]);
             if (isset($params[$name . '-percent-' . $index . $suffix])) {
                 $item['percent'] = (int) $params[$name . '-percent-' . $index . $suffix];
             }
             if (!$item['email']) {
                 $ret[] = $item;
             } else {
                 $ret[$item['email']] = $item;
             }
         }
     } else {
         if ($name == 'to' && $suffix) {
             $name = 'ch-' . $name;
         }
         if (isset($params[$name . $suffix])) {
             $ret = Tudu_Tudu_Storage::formatRecipients($params[$name . $suffix]);
         }
     }
     return $ret;
 }
Пример #6
0
 /**
  * 添加接收人
  */
 public function foreignAddAction()
 {
     $tuduId = $this->_request->getPost('tid');
     $to = $this->_request->getPost('to');
     $cc = $this->_request->getPost('cc');
     // 参数:图度ID必须存在
     if (!$tuduId) {
         return $this->json(false, $this->lang['invalid_tuduid']);
     }
     $fromTudu = $this->manager->getTuduById($tuduId, $this->_user->uniqueId);
     // 图度必须存在
     if (null === $fromTudu) {
         return $this->json(false, $this->lang['tudu_not_exists']);
     }
     // 必须是发起人才具备此操作
     if ($fromTudu->sender != $this->_user->userName) {
         return $this->json(false, $this->lang['perm_deny_add_foreign']);
     }
     // 检查外发用户email格式,外发用户是否存在,不存在则创建
     $address = array('to' => $this->_formatRecipients($to), 'cc' => $this->_formatRecipients($cc));
     $tuduAddr = array('to' => array(), 'cc' => array());
     $sendTo = array();
     foreach ($fromTudu->to as $k => $item) {
         $tuduAddr['to'][] = implode(' ', array(!is_numeric($k) ? $k : '', $item[0]));
     }
     foreach ($fromTudu->cc as $k => $item) {
         $tuduAddr['cc'][] = implode(' ', array(!is_int($k) ? $k : '', $item[0]));
     }
     /* @var $addressBook Tudu_AddressBook */
     $addressBook = Tudu_AddressBook::getInstance();
     $receivers = $this->manager->getTuduUsers($tuduId, array('isforeign' => 1));
     foreach ($address as $k => $arr) {
         foreach ($arr as $email => $name) {
             if (!$email && !$name) {
                 continue;
             }
             $email = preg_replace('/^#+/', '', $email);
             // 本系统用户不参与外发
             if (false !== strpos($email, '@') && null !== $addressBook->searchUser($this->_user->orgId, $email)) {
                 return $this->json(false, $this->lang['deny_add_user_to_foreign']);
             }
             // 新添加的外发用户是否已存在
             foreach ($receivers as $receiver) {
                 if ($email && $email == $receiver['email']) {
                     $display = $email ? $email : $name;
                     return $this->json(false, sprintf($this->lang['foreign_user_already_exists'], $display));
                 }
             }
             // 不存在联系人时创建
             if (!$addressBook->searchContact($this->_user->uniqueId, $email, $name)) {
                 $this->manager->createContact($this->_user->uniqueId, $email, $name);
             }
             $sendTo[] = $email;
             $tuduAddr[$k][] = implode(' ', array($email, $name));
         }
     }
     /* @var $deliver Tudu_Tudu_Deliver */
     $deliver = Tudu_Tudu_Deliver::getInstance();
     /* @var $storage Tudu_Tudu_Storage */
     $storage = Tudu_Tudu_Storage::getInstance();
     $tudu = $storage->prepareTudu(array('to' => $to, 'cc' => $cc), $fromTudu);
     $recipients = $deliver->prepareRecipients($this->_user->uniqueId, $this->_user->userId, $tudu);
     // 添加用户
     if (!$deliver->sendTudu($tudu, $recipients)) {
         return $this->json(false, $this->lang['add_foreign_failure']);
     }
     // 更新图度用户
     $this->manager->updateTudu($tuduId, array('to' => implode("\n", $tuduAddr['to']), 'cc' => implode("\n", $tuduAddr['cc'])));
     $config = $this->bootstrap->getOption('httpsqs');
     // 发送邮件
     $httpsqs = new Oray_Httpsqs($config['host'], $config['port'], $config['chartset'], $config['name']);
     // 发送外部邮件(如果有),处理联系人
     $data = implode(' ', array('send', 'tudu', '', http_build_query(array('tsid' => $this->_user->tsId, 'tuduid' => $tuduId, 'uniqueid' => $this->_user->uniqueId, 'to' => implode(',', $sendTo)))));
     $httpsqs->put($data, 'send');
     return $this->json(true, $this->lang['add_foreign_success']);
 }
Пример #7
0
 /**
  * 获取日志详细信息
  *
  * @param $tudu
  * @param $fromTudu
  */
 protected function _getLogDetails($params, $fromTudu)
 {
     if (null === $fromTudu || $fromTudu->isDraft) {
         $params['to'] = !empty($params['to']) ? Tudu_Tudu_Storage::formatReceiver($params['to']) : null;
         $params['cc'] = !empty($params['cc']) ? Tudu_Tudu_Storage::formatReceiver($params['cc']) : null;
         $params['bcc'] = !empty($params['bcc']) ? Tudu_Tudu_Storage::formatReceiver($params['bcc']) : null;
         //$params['reviewer'] = !empty($params['reviewer']) ? Tudu_Tudu_Storage::formatReceiver($params['reviewer']) : null;
         foreach ($params as $key => $val) {
             if (null === $val || '' === $val || $key == 'attach') {
                 unset($params[$key]);
             }
         }
         return $params;
     }
     $excepts = array('attach', 'uniqueid', 'status', 'poster', 'posterinfo', 'lastposter', 'issend');
     $tudu = $fromTudu->toArray();
     $ret = array();
     foreach ($params as $key => $val) {
         if (in_array($key, $excepts) || empty($val)) {
             continue;
         }
         if ($key == 'to') {
             if (count($params[$key]) != count($tudu['accepter'])) {
                 $val = Tudu_Tudu_Storage::formatReceiver($params[$key]);
             } else {
                 foreach ($params[$key] as $k => $val) {
                     if (!in_array($k, $tudu['accepter'])) {
                         $val = Tudu_Tudu_Storage::formatReceiver($params[$key]);
                     }
                 }
             }
             continue;
         }
         if ($key == 'cc' || $key == 'bcc') {
             $val = Tudu_Tudu_Storage::formatReceiver($params[$key]);
         }
         if (array_key_exists($key, $tudu) && $params[$key] != $tudu[$key]) {
             $ret[$key] = $val;
         }
     }
     return $ret;
 }
Пример #8
0
 /**
  *
  * @param string $params
  */
 public function createUser($params)
 {
     list($orgId, $address, $uniqueId, $truename) = explode(':', $params);
     $daoUser = Tudu_Dao_Manager::getDao('Dao_Md_User_User', Tudu_Dao_Manager::DB_MD);
     $user = $daoUser->getUser(array('uniqueid' => $uniqueId));
     $defaultTime = mktime(0, 0, 0, 11, 23, 2011);
     if ($user->createTime > $defaultTime) {
         $daoOrg = Tudu_Dao_Manager::getDao('Dao_Md_Org_Org', Tudu_Dao_Manager::DB_MD);
         $org = $daoOrg->getOrg(array('orgid' => $orgId));
         $tsId = $org->tsid;
         Tudu_Dao_Manager::setDb(Tudu_Dao_Manager::DB_TS, $this->_tsDbs['ts' . $tsId]);
         $manager = Tudu_Tudu_Manager::getInstance(Tudu_Dao_Manager::getDb(Tudu_Dao_Manager::DB_TS));
         // 系统欢迎公告ID
         $tuduId = md5($orgId . '-welcome');
         // 查看系统欢迎公告是否存在
         $tudu = $manager->getTuduById($tuduId, $uniqueId);
         if (null === $tudu) {
             $manager->addRecipient($tuduId, $uniqueId);
             $manager->addLabel($tuduId, $uniqueId, '^all');
             $manager->addLabel($tuduId, $uniqueId, '^i');
             $manager->addLabel($tuduId, $uniqueId, '^n');
             $this->getLogger()->debug("System Welcome Notice Tudu id:{$tuduId} done");
         }
         // 查看图度新手任务是否存在
         $newbieTuduId = 'newbie-' . $uniqueId;
         $newbieTudu = $manager->getTuduById($newbieTuduId, $uniqueId);
         if (null === $newbieTudu) {
             $content = file_get_contents($this->_options['data']['path'] . '/templates/tudu/newbie_tudu_task.tpl');
             if ($content) {
                 $tudu = array('orgid' => $orgId, 'tuduid' => $newbieTuduId, 'boardid' => '^system', 'uniqueid' => $this->_unId, 'type' => 'task', 'subject' => '图度新手任务', 'email' => '*****@*****.**', 'from' => $this->_unId . ' ' . $this->_unName, 'to' => $address . ' ' . $truename, 'cc' => null, 'priority' => 0, 'privacy' => 0, 'issend' => 1, 'needconfirm' => 0, 'status' => Dao_Td_Tudu_Tudu::STATUS_UNSTART, 'content' => $content, 'starttime' => strtotime(date('Y-m-d', time())), 'endtime' => null, 'totaltime' => 3 * 3600, 'poster' => $this->_unName, 'posterinfo' => '', 'lastposter' => $this->_unName, 'lastposttime' => time(), 'createtime' => time(), 'attachment' => array());
                 $tudu = new Tudu_Tudu_Storage_Tudu($tudu);
                 $storage = Tudu_Tudu_Storage::getInstance(Tudu_Dao_Manager::getDb(Tudu_Dao_Manager::DB_TS));
                 $deliver = Tudu_Tudu_Deliver::getInstance();
                 // 创建新手任务
                 $tuduId = $storage->createTudu($tudu);
                 if (!$tuduId) {
                     $this->getLogger()->warn("Create newbie Tudu failed id:{$newbieTuduId}");
                     return;
                 }
                 // 发送新手任务
                 $ret = $deliver->sendTudu($tudu, array());
                 if (!$ret) {
                     $this->getLogger()->warn("Send newbie Tudu failed id:{$newbieTuduId}");
                     return;
                 }
                 $manager->addRecipient($tuduId, $uniqueId, array('role' => 'to'));
                 $manager->addLabel($tuduId, $uniqueId, '^all');
                 $manager->addLabel($tuduId, $uniqueId, '^i');
                 $manager->addLabel($tuduId, $uniqueId, '^a');
                 $this->getLogger()->debug("Newbie Tudu id:{$tuduId} done");
             }
         }
     }
 }
Пример #9
0
 /**
  * 生成周期图度
  *
  * @param $params
  */
 public function cycle($params)
 {
     if (empty($params['tuduid']) || empty($params['cycleid']) || empty($params['tsid'])) {
         return;
     }
     $tuduId = $params['tuduid'];
     $cycleId = $params['cycleid'];
     $tsId = $params['tsid'];
     $daoUser = Tudu_Dao_Manager::getDao('Dao_Md_User_User', Tudu_Dao_Manager::DB_MD);
     $daoCycle = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Cycle', Tudu_Dao_Manager::DB_TS);
     $manager = Tudu_Tudu_Manager::getInstance(Tudu_Dao_Manager::getDb(Tudu_Dao_Manager::DB_TS));
     $tudu = $manager->getTuduById($tuduId, $this->_unId);
     $fromTuduId = $tudu->tuduId;
     $acceptMode = $tudu->acceptMode;
     $isAuth = $tudu->isAuth;
     if (null === $tudu) {
         $this->getLogger()->warn("Tudu id: {$tuduId} is not exists");
         return;
     }
     $cycle = $daoCycle->getCycle(array('cycleid' => $cycleId));
     if (null === $cycle) {
         $this->getLogger()->warn("Tudu Cycle id: {$cycleId} is not exists");
         return;
     }
     // 已经失效的周期设置
     if ($cycle->isValid == 0) {
         return;
     }
     if (Dao_Td_Tudu_Cycle::END_TYPE_COUNT == $cycle->endType && $cycle->count >= $cycle->endCount) {
         $daoCycle->deleteCycle($cycle->cycleId);
         return;
     }
     if (Dao_Td_Tudu_Cycle::END_TYPE_DATE == $cycle->endType && time() >= $cycle->endDate) {
         $daoCycle->deleteCycle($cycle->cycleId);
         return;
     }
     $time = $daoCycle->getCycleTime($cycle, $tudu->startTime, $tudu->endTime);
     $recipients = array();
     $to = array();
     $fromUnId = null;
     $u = $daoUser->getUserByAddress($tudu->sender);
     if ($u) {
         $recipients[$u->uniqueId] = array('uniqueid' => $u->uniqueId, 'role' => 'from');
         $fromUnId = $u->uniqueId;
     }
     if (!$acceptMode) {
         $accepters = $manager->getTuduAccepters($tudu->tuduId);
         foreach ($accepters as $a) {
             $recipients[$a['uniqueid']] = array('accepterinfo' => $a['accepterinfo'], 'uniqueid' => $a['uniqueid'], 'role' => Dao_Td_Tudu_Tudu::ROLE_ACCEPTER, 'tudustatus' => Dao_Td_Tudu_Tudu::STATUS_UNSTART, 'isforeign' => (int) $a['isforeign'], 'percent' => 0, 'authcode' => (int) $a['isforeign'] && $tudu->isAuth ? Oray_Function::randKeys(4) : null);
             if ($tudu->isAuth) {
                 $recipients[$a['uniqueid']]['authcode'] = $a['authcode'];
             }
             $to[] = $a['accepterinfo'];
         }
     }
     // 公共周期任务图度数据
     $params = $this->getCycleTuduParams($tudu, $cycle, $to, $fromUnId, $time);
     // 抄送
     if (!empty($tudu->cc)) {
         $cc = array();
         $sendCc = array();
         foreach ($tudu->cc as $userName => $item) {
             $cc[] = $userName . ' ' . $item[0];
         }
         $params['cc'] = implode("\n", $cc);
         $sendCc = $this->formatRecipients($params['cc']);
         $addressBook = Tudu_AddressBook::getInstance();
         foreach ($sendCc as $key => $item) {
             if (isset($item['groupid'])) {
                 if (0 === strpos($item['groupid'], 'XG')) {
                     $users = $addressBook->getGroupContacts($tudu->orgId, $fromUnId, $item['groupid']);
                 } else {
                     $users = $addressBook->getGroupUsers($tudu->orgId, $item['groupid']);
                 }
                 $recipients = array_merge($users, $recipients);
             } else {
                 $user = $addressBook->searchUser($tudu->orgId, $item['email']);
                 if (null === $user) {
                     $user = $addressBook->searchContact($fromUnId, $item['email'], $item['truename']);
                     if (null === $user) {
                         $user = $addressBook->prepareContact($item['email'], $item['truename']);
                     }
                 }
                 if (!isset($recipients[$user['uniqueid']])) {
                     $recipients[$user['uniqueid']] = $user;
                 }
             }
         }
     }
     // 密送
     if (!empty($tudu->bcc)) {
         $bcc = array();
         $sendBcc = array();
         foreach ($tudu->bcc as $userName => $item) {
             $bcc[] = $userName . ' ' . $item[0];
         }
         $params['bcc'] = implode("\n", $bcc);
         $sendBcc = $this->formatRecipients($params['bcc']);
         $addressBook = Tudu_AddressBook::getInstance();
         foreach ($sendBcc as $key => $item) {
             if (isset($item['groupid'])) {
                 if (0 === strpos($item['groupid'], 'XG')) {
                     $users = $addressBook->getGroupContacts($tudu->orgId, $fromUnId, $item['groupid']);
                 } else {
                     $users = $addressBook->getGroupUsers($tudu->orgId, $item['groupid']);
                 }
                 $recipients = array_merge($users, $recipients);
             } else {
                 $user = $addressBook->searchUser($tudu->orgId, $item['email']);
                 if (null === $user) {
                     $user = $addressBook->searchContact($fromUnId, $item['email'], $item['truename']);
                     if (null === $user) {
                         $user = $addressBook->prepareContact($item['email'], $item['truename']);
                     }
                 }
                 if (!isset($recipients[$user['uniqueid']])) {
                     $recipients[$user['uniqueid']] = $user;
                 }
             }
         }
     }
     // 会议数据
     if ($tudu->type == 'meeting') {
         $daoMeeting = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Meeting', Tudu_Dao_Manager::DB_TS);
         $meeting = $daoMeeting->getMeeting(array('tuduid' => $tudu->tuduId));
         if ($meeting) {
             $params['meeting'] = array('notifytype' => $meeting->notifyType, 'location' => $meeting->location, 'isallday' => $meeting->isAllday);
             $params['meeting']['notifytime'] = Dao_Td_Tudu_Meeting::calNotifyTime($params['starttime'], $meeting->notifyType);
         }
     }
     // 保留周期任务的附件
     if ($cycle->isKeepAttach) {
         $daoAttach = Tudu_Dao_Manager::getDao('Dao_Td_Attachment_File', Tudu_Dao_Manager::DB_TS);
         $attaches = $daoAttach->getFiles(array('tuduid' => $tudu->tuduId, 'postid' => $tudu->postId))->toArray();
         $attachNum = 0;
         foreach ($attaches as $attach) {
             if ($attach['isattach']) {
                 $params['attachment'][] = $attach['fileid'];
             } else {
                 $params['file'][] = $attach['fielid'];
             }
         }
     }
     $stepId = $params['stepid'];
     $tudu = new Tudu_Tudu_Storage_Tudu($params);
     $storage = Tudu_Tudu_Storage::getInstance(Tudu_Dao_Manager::getDb(Tudu_Dao_Manager::DB_TS));
     $deliver = Tudu_Tudu_Deliver::getInstance();
     $tuduId = $storage->createTudu($tudu);
     if (!$tuduId) {
         $this->getLogger()->warn("Create Cycle Tudu failed id:{$tuduId}");
         return;
     }
     if ($params['type'] == 'task' && $tuduId) {
         $daoFlow = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Flow', Tudu_Dao_Manager::DB_TS);
         $flow = $daoFlow->getFlow(array('tuduid' => $fromTuduId));
         $steps = $flow->steps;
         $step = reset($steps);
         $modelFlow = new Model_Tudu_Extension_Flow(array('orgid' => $tudu->orgId, 'tuduid' => $tuduId));
         /*$step = $daoStep->getStep(array('tuduid' => $fromTuduId, 'prevstepid' => '^head'));
           $orderNum   = 1;*/
         $prevStepId = '^head';
         $addressBook = Tudu_AddressBook::getInstance();
         // 认领
         if ($step && $step['type'] == Dao_Td_Tudu_Step::TYPE_CLAIM) {
             $modelFlow->addStep(array('stepid' => $step['stepid'], 'prev' => $step['prev'], 'next' => '^end', 'type' => $step['type']));
             $acceptMode = true;
             $to = array();
             foreach ($step['section'] as $idx => $sec) {
                 $section = array();
                 foreach ($sec as $user) {
                     $section[] = array('uniqueid' => $user['uniqueid'], 'username' => $user['username'], 'truename' => $user['truename']);
                     if ($idx == 0) {
                         $to[] = $user['username'] . ' ' . $user['truename'];
                         $recipient = array('uniqueid' => $user['uniqueid'], 'userinfo' => $user['username'] . ' ' . $user['truename'], 'role' => Dao_Td_Tudu_Tudu::ROLE_ACCEPTER, 'tudustatus' => Dao_Td_Tudu_Tudu::STATUS_UNSTART, 'percent' => 0);
                         $u = $addressBook->searchUser($fromUnId, $user['username']);
                         if (!$u) {
                             $recipient['isforeign'] = 1;
                             if ($isAuth) {
                                 $recipient['auth'] = Oray_Function::randKeys(4);
                             }
                         }
                         $recipients[$recipient['uniqueid']] = $recipient;
                     }
                 }
                 $modelFlow->addStepSection($step['stepid'], $sec);
             }
             $modelFlow->stepNum = 1;
             $modelFlow->flowTo($step['stepid']);
             $daoFlow->createFlow($modelFlow->toArray());
             // 更新to字段
             $manager->updateTudu($tuduId, array('to' => implode("\n", $to), 'acceptmode' => 1, 'accepttime' => null));
         } else {
             // 审批
             $nextId = $step['next'];
             $modelFlow->addStep(array('stepid' => $step['stepid'], 'prev' => $step['prev'], 'next' => $step['next'], 'type' => $step['type']));
             foreach ($step['section'] as $idx => $sec) {
                 $section = array();
                 foreach ($sec as $user) {
                     $section[] = array('uniqueid' => $user['uniqueid'], 'username' => $user['username'], 'truename' => $user['truename']);
                     if ($idx == 0) {
                         $to[] = $user['username'] . ' ' . $user['truename'];
                         $recipient = array('uniqueid' => $user['uniqueid'], 'userinfo' => $user['username'] . ' ' . $user['truename'], 'role' => isset($recipients[$user['uniqueid']]) ? $recipients[$user['uniqueid']]['role'] : null, 'isreview' => true, 'tudustatus' => Dao_Td_Tudu_Tudu::STATUS_UNSTART);
                         $recipients[$recipient['uniqueid']] = $recipient;
                     }
                 }
                 $modelFlow->addStepSection($step['stepid'], $sec);
             }
             if (isset($flow->steps[$nextId])) {
                 $next = $flow->steps[$nextId];
                 $modelFlow->addStep(array('stepid' => $next['stepid'], 'prev' => $next['prev'], 'next' => '^end', 'type' => $next['type']));
                 foreach ($next['section'] as $idx => $sec) {
                     $section = array();
                     foreach ($sec as $user) {
                         $section[] = array('uniqueid' => $user['uniqueid'], 'username' => $user['username'], 'truename' => $user['truename']);
                     }
                     $modelFlow->addStepSection($next['stepid'], $sec);
                 }
             }
             $modelFlow->stepNum = count($modelFlow->steps);
             $modelFlow->flowTo($step['stepid']);
             $daoFlow->createFlow($modelFlow->toArray());
         }
     }
     $sendParams = array();
     if ($tudu->type == 'meeting') {
         $sendParams['meeting'] = true;
     }
     if (empty($reviewer)) {
         $ret = $deliver->sendTudu($tudu, $recipients, $sendParams);
         if (!$ret) {
             $this->getLogger()->warn("Send Tudu failed id:{$tuduId}");
             return;
         }
         if (!$acceptMode) {
             foreach ($recipients as $unId => $recipient) {
                 if (isset($recipient['role']) && $recipient['role'] == Dao_Td_Tudu_Tudu::ROLE_ACCEPTER) {
                     $manager->acceptTudu($tuduId, $unId, null);
                 }
             }
         }
     } else {
         $rev = array_shift($reviewer);
         $ret = $deliver->sendTudu($tudu, array($rev['uniqueid'] => array('tuduid' => $tuduId, 'uniqueid' => $rev['uniqueid']), $fromUnId => array('tuduid' => $tuduId, 'uniqueid' => $fromUnId)), null);
         if (!$ret) {
             $this->getLogger()->warn("Send Tudu failed id:{$tuduId}");
             return;
         }
         $manager->addLabel($tuduId, $rev['uniqueid'], '^e');
     }
     // 发起人的
     if (null !== $fromUnId) {
         $manager->addLabel($tuduId, $fromUnId, '^f');
         $manager->addLabel($tuduId, $fromUnId, '^i');
     }
     $daoCycle->increment($cycle->cycleId);
     // 收发规则过滤
     $data = implode(' ', array('tudu', 'filter', '', http_build_query(array('tsid' => $tsId, 'tuduid' => $tuduId))));
     $this->_httpsqs->put($data, $this->_options['httpsqs']['names']['tudu']);
     // 外发请求
     $data = implode(' ', array('send', 'tudu', '', http_build_query(array('tsid' => $tsId, 'tuduid' => $tuduId, 'uniqueid' => $fromUnId, 'to' => ''))));
     $this->_httpsqs->put($data, $this->_options['httpsqs']['names']['send']);
     $this->getLogger()->debug("Tudu id:{$tuduId} done");
 }
Пример #10
0
 /**
  *
  * @param $tudu
  */
 public function preflowRejectUsers(Tudu_Tudu_Storage_Tudu &$tudu)
 {
     if ($tudu->stepId == '^head' || $tudu->stepId == '^break') {
         $tudu->to = Tudu_Tudu_Storage::formatRecipients($tudu->from);
     } else {
         $users = $this->getStepUsers($tudu->tuduId, $tudu->stepId);
         $to = array();
         foreach ($users as $item) {
             $to[] = $item['userinfo'];
         }
         $tudu->to = Tudu_Tudu_Storage::formatRecipients(implode("\n", $to));
     }
     return true;
 }
Пример #11
0
 /**
  * 设置字段数据
  *
  * @param $name
  * @param $value
  */
 public function setAttribute($name, $value)
 {
     $name = strtolower($name);
     if (in_array($name, array('to', 'cc', 'bcc', 'reviewer')) && is_string($value)) {
         $value = Tudu_Tudu_Storage::formatRecipients($value);
     }
     $this->_attrs[$name] = $value;
 }
Пример #12
0
 /**
  * 执行部同意流程
  * @param Tudu_Model_Tudu_Entity_Tudu $tudu
  */
 protected function _disAgree(Tudu_Model_Tudu_Entity_Tudu $tudu)
 {
     $daoStep = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Step', Tudu_Dao_Manager::DB_TS);
     if ($tudu->flowId) {
         //return $this->flowReviewReject($tudu);
         return;
     }
     $daoStep->updateUser($tudu->tuduId, $tudu->stepId, $tudu->uniqueId, array('status' => 3));
     $steps = $daoStep->getSteps(array('tuduid' => $tudu->tuduId))->toArray('stepid');
     if (!isset($steps[$tudu->stepId])) {
         return false;
     }
     $step = $steps[$tudu->stepId];
     $prevId = $step['prevstepid'];
     $toStepId = $prevId;
     do {
         if (!isset($steps[$prevId])) {
             $prevId = '^head';
             break;
         }
         $prev = $steps[$prevId];
         if ($prev['type'] == 0) {
             break;
         }
         $prevId = $prev['prevstepid'];
         $toStepId = $prev['stepid'];
         if ($prevId == '^head') {
             break;
         }
     } while ($prev['type'] == 0);
     $tudu->stepId = $toStepId;
     if ($toStepId == '^head' || $toStepId == '^trunk') {
         $tudu->to = Tudu_Tudu_Storage::formatRecipients($tudu->from);
     } else {
         $users = $daoStep->getUsers($tudu->tuduId, $toStepId);
         $to = array();
         foreach ($users as $item) {
             $to[] = $item['userinfo'];
         }
         $tudu->to = Tudu_Tudu_Storage::formatRecipients(implode("\n", $to));
     }
 }