/** * 格式化投票参数 * * @param array $params * @param string $suffix * @return array */ public function formatParams($params, $suffix = '') { $meeting = array('notifytype' => !empty($params['remindbefore' . $suffix]) && isset($params['notifytype' . $suffix]) ? (int) $params['notifytype' . $suffix] : null, 'isallday' => !empty($params['allday' . $suffix]) ? 1 : 0); if (isset($params['location'])) { $meeting['location'] = $params['location' . $suffix]; } if ($meeting['notifytype']) { $meeting['notifytime'] = Dao_Td_Tudu_Meeting::calNotifyTime(strtotime($params['starttime' . $suffix]), $meeting['notifytype' . $suffix]); } else { $meeting['notifytime'] = null; } return $meeting; }
/** * * @param Model_Tudu_Tudu $tudu */ public function action(Model_Tudu_Tudu &$tudu) { $meeting = $tudu->getExtension('Model_Tudu_Extension_Meeting'); /* @var $daoMeeting Dao_Td_Tudu_Meeting */ $daoMeeting = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Meeting', Tudu_Dao_Manager::DB_TS); $params = $meeting->getAttributes(); if ($params['notifytype']) { $params['notifytime'] = Dao_Td_Tudu_Meeting::calNotifyTime(strtotime($tudu->starttime), $params['notifytype']); } else { $params['notifytime'] = null; } if ($daoMeeting->existsMeeting($tudu->tuduId)) { $daoMeeting->updateMeeting($tudu->tuduId, $params); } else { $params['tuduid'] = $tudu->tuduId; $daoMeeting->createMeeting($params); } }
/** * 生成周期图度 * * @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"); }