示例#1
0
 /**
  * 获取对象实例
  *
  * @param Zend_Db_Adapter_Abstract $db
  * @return Tudu_Tudu_Manager
  */
 public static function getInstance()
 {
     if (null === self::$_instance) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
 public function init()
 {
     parent::init();
     if (!$this->_user->isLogined()) {
         return $this->json(false, $this->lang['login_timeout']);
     }
     Tudu_AddressBook::getInstance()->setCache($this->cache);
     $this->lang = Tudu_Lang::getInstance()->load(array('common', 'tudu'));
     Tudu_Dao_Manager::setDbs(array(Tudu_Dao_Manager::DB_MD => $this->multidb->getDefaultDb(), Tudu_Dao_Manager::DB_TS => $this->getTsDb()));
     $resourceManager = new Tudu_Model_ResourceManager_Registry();
     $resourceManager->setResource(Tudu_Model::RESOURCE_CONFIG, $this->bootstrap->getOptions());
     Tudu_Model::setResourceManager($resourceManager);
 }
示例#3
0
 /**
  *
  * @param Model_Tudu_Tudu $tudu
  */
 public function filter(Model_Tudu_Tudu &$tudu)
 {
     $apply = $tudu->getExtension('Model_App_Attend_Tudu_Apply');
     if (!$apply) {
         return;
     }
     /* @var $daoApply Dao_App_Attend_Apply */
     $daoApply = Tudu_Dao_Manager::getDao('Dao_App_Attend_Apply', Tudu_Dao_Manager::DB_APP);
     if ($tudu->tuduId) {
         $this->_fromApply = $daoApply->getApply(array('tuduid' => $tudu->tuduId));
         if ($this->_fromApply) {
             $apply->applyId = $this->_fromApply->applyId;
             if ($tudu->operation == 'review') {
                 $apply->setAttributes($this->_fromApply->toArray());
             }
         }
     }
     // 创建审批流程
     if ($tudu->operation == 'send' || $tudu->operation == 'save') {
         $error = null;
         $issend = $tudu->operation == 'send';
         do {
             if (!$apply->categoryId) {
                 $error = 'Invalid Category id for attend apply';
                 break;
             }
             if ($issend && (!$apply->startTime && $apply->categoryId != '^checkin')) {
                 $error = 'Invalid Starttime for attend apply';
                 break;
             }
             if ($issend && (!$apply->endTime && $apply->categoryId != '^checkin')) {
                 $error = 'Invalid Endtime for attend apply';
                 break;
             }
         } while (false);
         // 参数错误
         if (null != $error) {
             require_once 'Model/App/Attend/Exception.php';
             $code = false !== strpos($error, 'Category') ? Model_App_Attend_Exception::APPLY_MISSING_CATEGORYID : Model_App_Attend_Exception::APPLY_INVALID_TIME;
             throw new Model_App_Attend_Exception($error, $code);
         }
         /* @var $daoCategory Dao_App_Attend_Category */
         $daoCategory = Tudu_Dao_Manager::getDao('Dao_App_Attend_Category', Tudu_Dao_Manager::DB_APP);
         $category = $daoCategory->getCategory(array('categoryid' => $apply->categoryId, 'orgid' => $apply->orgId));
         if (null === $category) {
             require_once 'Model/App/Attend/Exception.php';
             throw new Model_App_Attend_Exception('Category id: [' . $apply->categoryId . '] is not exists', Model_App_Attend_Exception::CATEGORY_NOT_EXISTS);
         }
         $tudu->subject = $category->categoryName;
         // 创建图度工作流
         if ($tudu->operation == 'send' && ($apply->status == 0 || $apply->status == 3) && !$this->_fromApply) {
             require_once 'Model/Tudu/Extension/Flow.php';
             $flow = new Model_Tudu_Extension_Flow(array('orgid' => $tudu->orgId));
             $steps = $category->flowSteps;
             $stepIds = array();
             foreach ($steps as $item) {
                 $stepId = isset($item['stepid']) ? $item['stepid'] : Dao_Td_Tudu_Flow::getStepId(null);
                 $stepIds[] = $stepId;
                 $flow->addStep(array('stepid' => $stepId, 'prev' => !empty($item['prev']) ? $item['prev'] : '^head', 'next' => !empty($item['next']) ? $item['next'] : '^end', 'type' => 1, 'description' => isset($item['description']) ? $item['description'] : null, 'subject' => isset($item['subject']) ? $item['subject'] : null));
                 if (is_array($item['sections'])) {
                     foreach ($item['sections'] as $section) {
                         $flow->addStepSection($stepId, $section);
                     }
                 } else {
                     $flow->addStepSection($stepId, $item['sections'], $tudu);
                 }
             }
             $flow->flowTo($stepIds[0]);
             $users = $flow->getCurrentUser();
             $flow->isPrepared = true;
             $tudu->reviewer = $users;
             $tudu->setExtension($flow);
         }
         // 新建的
         if (!$this->_fromApply) {
             if ($apply->target) {
                 list($userName, $trueName) = explode(' ', $apply->target);
                 $addressBook = Tudu_AddressBook::getInstance();
                 $user = $addressBook->searchUser($userName);
                 if ($user) {
                     $apply->uniqueId = $user['uniqueid'];
                     $apply->userInfo = $userName . ' ' . $trueName;
                     $tudu->bcc = array(array('uniqueid' => $user['uniqueid'], 'username' => $user['username'], 'truename' => $user['truename']));
                 }
             } else {
                 $apply->uniqueId = $apply->senderId;
                 $apply->userInfo = $tudu->poster . ' ' . $tudu->email;
             }
         }
     }
 }
示例#4
0
 /**
  *
  * @param $orgId
  * @param $uniqueId
  * @param $users
  */
 private function _prepareStepRecipients($orgId, $uniqueId, array $users)
 {
     $addressBook = Tudu_AddressBook::getInstance();
     $recipients = array();
     foreach ($users as $key => $item) {
         $user = $addressBook->searchUser($orgId, $item['email']);
         if (null === $user) {
             $user = $addressBook->searchContact($uniqueId, $item['email'], $item['truename']);
             if (null === $user) {
                 $user = $addressBook->prepareContact($item['email'], $item['truename']);
             }
         }
         $user['accepterinfo'] = $user['email'] . ' ' . $user['truename'];
         $user['percent'] = isset($item['percent']) ? (int) $item['percent'] : 0;
         if (isset($item['processindex'])) {
             $user['processindex'] = (int) $item['processindex'];
         }
         if (isset($item['stepstatus'])) {
             $user['stepstatus'] = (int) $item['stepstatus'];
         }
         $recipients[$user['uniqueid']] = $user;
     }
     return $recipients;
 }
示例#5
0
 /**
  * 获取指定上级人员
  *
  * @param string $userName
  */
 private function _getUpper($userName)
 {
     list($userId, ) = explode('@', $userName, 2);
     $depts = $this->_getDepartments($this->_user->orgId);
     $addressBook = Tudu_AddressBook::getInstance();
     $user = $addressBook->searchUser($this->_user->orgId, $userName);
     if (empty($user['deptid'])) {
         $user['deptid'] = '^root';
     }
     if (empty($depts[$user['deptid']])) {
         return null;
     }
     $dept = $depts[$user['deptid']];
     // 是当前部门负责人
     if (in_array($userId, $dept['moderators']) && $user['deptid'] != '^root') {
         $dept = $depts[$dept['parentid']];
     }
     $ret = array();
     foreach ($dept['moderators'] as $m) {
         $u = $addressBook->searchUser($this->_user->orgId, $m . '@' . $this->_user->orgId);
         if (!$u) {
             return null;
         }
         $ret[$u['email']] = $u;
     }
     return $ret;
 }
示例#6
0
 /**
  * /compose/reply
  *
  * 回覆
  */
 public function replyAction()
 {
     $tuduId = $this->_request->getPost('tid');
     $action = $this->_request->getPost('action');
     $type = $this->_request->getPost('type');
     $post = $this->_request->getPost();
     $uniqueId = $this->_user->uniqueId;
     $fromPost = null;
     $fromPostId = trim($this->_request->getPost('fpid'));
     $isDoneTudu = false;
     /* @var $manager Tudu_Tudu_Manager */
     $manager = Tudu_Tudu_Manager::getInstance();
     /* @var $storage Tudu_Tudu_Storage */
     $storage = Tudu_Tudu_Storage::getInstance();
     $tudu = $manager->getTuduById($tuduId, $uniqueId);
     if (null === $tudu) {
         return $this->json(false, $this->lang['tudu_not_exists']);
     }
     // 编辑回复的权限判断
     if ($this->_user->orgId != $tudu->orgId) {
         return $this->json(false, $this->lang['tudu_not_exists']);
     }
     // 已确认图度
     if ($tudu->isDone) {
         return $this->json(false, $this->lang['tudu_is_done']);
     }
     if ($fromPostId) {
         $fromPost = $manager->getPostById($tuduId, $fromPostId);
     }
     $isReceiver = $this->_user->uniqueId == $tudu->uniqueId && count($tudu->labels);
     $isAccepter = in_array($this->_user->userName, $tudu->accepter, true);
     $isSender = in_array($tudu->sender, array($this->_user->address, $this->_user->account));
     $sendParam = array();
     if ('modify' == $action) {
         if (null == $fromPost) {
             return $this->json(false, $this->lang['post_not_exists']);
         }
         // 编辑回复的权限判断
         if (!$this->_user->getAccess()->isAllowed(Tudu_Access::PERM_UPDATE_POST) && $fromPost->isSend) {
             return $this->json(false, $this->lang['perm_deny_update_post']);
         }
         // 非回复者时,需要判断版主的权限
         if ($fromPost->uniqueId != $this->_user->uniqueId) {
             $boards = $this->getBoards(false);
             $board = $boards[$tudu->boardId];
             $isModerators = array_key_exists($this->_user->userId, $board['moderators']);
             if (!$isModerators) {
                 return $this->json(false, $this->lang['perm_deny_update_post']);
             }
         }
         if (!$fromPost->isSend) {
             $sendParam['remind'] = true;
         }
     } else {
         // 发表回复的权限判断 - 参与人员或回复权限
         if (!$isReceiver && !$this->_user->getAccess()->isAllowed(Tudu_Access::PERM_CREATE_POST)) {
             return $this->json(false, $this->lang['perm_deny_create_post']);
         }
         // 需要发送提醒
         $sendParam['remind'] = true;
     }
     // 空内容
     if ($type != 'save' && empty($post['content'])) {
         return $this->json(false, $this->lang['missing_content']);
     }
     // 构造参数
     $params = array('orgid' => $tudu->orgId, 'boardid' => $tudu->boardId, 'tuduid' => $tudu->tuduId, 'uniqueid' => $uniqueId, 'email' => $this->_user->userName, 'poster' => $this->_user->trueName, 'posterinfo' => $this->_user->position, 'content' => $post['content'], 'attachment' => !empty($post['attach']) ? array_unique((array) $post['attach']) : array(), 'file' => !empty($post['file']) ? array_unique((array) $post['file']) : array());
     $elapsedtime = round((double) $this->_request->getPost('elapsedtime'), 2) * 3600;
     $percent = min(100, (int) $this->_request->getPost('percent'));
     if ($fromPost && $fromPost->isSend) {
         $isLog = $fromPost->isLog;
         $params['elapsedtime'] = $fromPost->elapsedtime;
         $params['percent'] = $fromPost->percent;
     } else {
         if (isset($post['percent'])) {
             $isLog = $percent != $tudu->selfPercent || $elapsedtime > 0;
         } else {
             $isLog = $elapsedtime > 0;
         }
     }
     $params['islog'] = $isLog;
     if ($isLog && $tudu->selfPercent < 100) {
         $params['elapsedtime'] = $elapsedtime;
         $params['percent'] = $percent;
     }
     // 处理网盘附件
     if (!empty($post['nd-attach'])) {
         $params['attachment'] = array_diff($params['attachment'], $post['nd-attach']);
         $daoNdFile = $this->getDao('Dao_Td_Netdisk_File');
         $daoAttachment = $this->getDao('Dao_Td_Attachment_File');
         foreach ($post['nd-attach'] as $ndfileId) {
             $fileId = $ndfileId;
             $attach = $daoAttachment->getFile(array('fileid' => $fileId));
             if (null !== $attach) {
                 $params['attachment'][] = $fileId;
                 continue;
             }
             $file = $daoNdFile->getFile(array('uniqueid' => $this->_user->uniqueId, 'fileid' => $ndfileId));
             if ($file->fromFileId) {
                 $fileId = $file->fromFileId;
             }
             if ($file->attachFileId) {
                 $fileId = $file->attachFileId;
             }
             $ret = $daoAttachment->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) {
                 $params['attachment'][] = $fileId;
             }
         }
     }
     if (!$fromPost) {
         $postId = $storage->createPost($params);
         if (!$postId) {
             return $this->json(false, $this->lang['post_send_failure']);
         }
         // 添加操作日志
         $this->_writeLog(Dao_Td_Log_Log::TYPE_POST, $postId, Dao_Td_Log_Log::ACTION_CREATE, $params);
     } else {
         $postId = $fromPost->postId;
         // 增加最后编辑信息
         if ($fromPost->isSend) {
             $params['lastmodify'] = implode(chr(9), array($uniqueId, $this->_timestamp, $this->_user->trueName));
         } else {
             $params['createtime'] = time();
         }
         $storage->updatePost($tuduId, $postId, $params);
         // 记录更新内容
         $arrFromPost = $fromPost->toArray();
         $updates = array();
         foreach ($params as $key => $val) {
             if (in_array($key, array('file', 'attachment'))) {
                 continue;
             }
             if ($val != $arrFromPost[$key]) {
                 $updates[$key] = $val;
             }
         }
         // 添加操作日志
         $this->_writeLog(Dao_Td_Log_Log::TYPE_POST, $postId, Dao_Td_Log_Log::ACTION_CREATE, $updates);
     }
     if ($type != 'save') {
         // 未读
         if (!$fromPost || !$fromPost->isSend) {
             $manager->markAllUnread($tudu->tuduId);
         }
         // 标记已经读
         // 加入了批量更新和回复,所以在更新时就需要标示已读
         if ($tudu->isRead) {
             $manager->markRead($tudu->tuduId, $this->_user->uniqueId, true);
         }
         $config = $this->bootstrap->getOption('httpsqs');
         // 插入消息队列
         $httpsqs = new Oray_Httpsqs($config['host'], $config['port'], $config['chartset'], $config['name']);
         $tuduPercent = $tudu->percent;
         $flowPercent = null;
         if ($isLog && $tudu->selfPercent < 100) {
             if ($tudu->flowId) {
                 $tuduPercent = $manager->updateFlowProgress($tudu->tuduId, $tudu->uniqueId, $tudu->stepId, (int) $params['percent'], $flowPercent);
             } else {
                 $tuduPercent = $manager->updateProgress($tudu->tuduId, $tudu->uniqueId, (int) $params['percent']);
             }
             if (!$fromPost || !$fromPost->isSend) {
                 // 添加操作日志
                 $this->_writeLog(Dao_Td_Log_Log::TYPE_TUDU, $tudu->tuduId, Dao_Td_Log_Log::ACTION_TUDU_PROGRESS, array('percent' => $params['percent'], 'elapsedtime' => $tudu->elapsedTime + (int) $post['elapsedtime']));
             }
         }
         // 自动确认
         if ($isLog && $tuduPercent == 100 && null === $flowPercent || $isLog && $flowPercent == 100) {
             if ($isSender && $isAccepter || !$tudu->needConfirm) {
                 $isDoneTudu = true;
                 $doneParams = array('tuduid' => $tudu->tuduId, 'percent' => $params['percent'], 'elapsedtime' => $tudu->elapsedTime + (int) $post['elapsedtime']);
                 // 添加到发起人图度箱 -- 待确认中
             } else {
                 /* @var $addressBook Tudu_AddressBook */
                 $addressBook = Tudu_AddressBook::getInstance();
                 $sender = $addressBook->searchUser($this->_user->orgId, $tudu->sender);
                 $manager->addLabel($tudu->tuduId, $sender['uniqueid'], '^i');
             }
         }
         // 计算父级图度进度  及 图度组达到100%时,确认
         if ($tudu->parentId) {
             $parentPercent = $manager->calParentsProgress($tudu->parentId);
             if ($parentPercent >= 100) {
                 $sendParam['confirm'] = true;
             }
         }
         // 发送回复
         $manager->sendPost($tuduId, $postId);
         // 统计时间
         if ($isLog) {
             $manager->calcElapsedTime($tuduId);
         }
         // 周期任务
         if ($isLog && $tudu->cycleId && $tuduPercent >= 100) {
             $daoCycle = $this->getDao('Dao_Td_Tudu_Cycle');
             $cycle = $daoCycle->getCycle(array('cycleid' => $tudu->cycleId));
             if ($cycle->count == $tudu->cycleNum) {
                 $sendParam['cycle'] = true;
             }
         }
         $sendParam['tuduid'] = $tudu->tuduId;
         $sendParam['from'] = $this->_user->userName;
         $sendParam['sender'] = $this->_user->trueName;
         $sendParam['uniqueid'] = $this->_user->uniqueId;
         $sendParam['postid'] = $postId;
         $sendParam['tsid'] = $this->_user->tsId;
         $sendParam['server'] = $this->_request->getServer('HTTP_HOST');
         // 处理工作流
         // 处理流程发送过程
         if ($tudu->type == 'task' && $percent >= 100) {
             /* @var $daoFlow Dao_Td_Tudu_Flow */
             $daoFlow = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Flow', Tudu_Dao_Manager::DB_TS);
             $flowData = $daoFlow->getFlow(array('tuduid' => $tudu->tuduId));
             if (null !== $flowData) {
                 /* @var $flow Model_Tudu_Extension_Flow */
                 $flow = new Model_Tudu_Extension_Flow($flowData->toArray());
                 $isCurrentUser = $flow->isCurrentUser($this->_user->uniqueId);
                 $isComplete = false;
                 if ($isCurrentUser) {
                     $flow->complete($this->_user->uniqueId);
                     if ($flow->isStepComplete()) {
                         $isComplete = true;
                         $flow->flowTo();
                     }
                 }
                 $modelFlow = $flow->getHandler($flow->getHandlerClass());
                 $modelFlow->updateFlow($flow);
                 if ($flow->currentStepId != '^end') {
                     $isDoneTudu = false;
                 }
                 // 发送下一步
                 if (false === strpos($flow->currentStepId, '^') && $isComplete) {
                     $section = $flow->getStepSection($flow->currentStepId);
                     $tuduParams = array('tuduid' => $tudu->tuduId, 'type' => $tudu->type, 'fromtudu' => $tudu);
                     $users = array();
                     foreach ($section as $sec) {
                         $users[$sec['username']] = array('uniqueid' => $sec['uniqueid'], 'truename' => $sec['truename'], 'username' => $sec['username'], 'email' => $sec['username']);
                     }
                     $step = $flow->getStep($flow->currentStepId);
                     if ($step['type'] == 1) {
                         $tuduParams['reviewer'] = $users;
                     } else {
                         $tuduParams['to'] = $users;
                         if ($step['type'] == 2) {
                             $tuduParams['acceptmode'] = 1;
                         }
                     }
                     $sendTudu = new Model_Tudu_Tudu($tuduParams);
                     $daoTudu = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Tudu', Tudu_Dao_Manager::DB_TS);
                     $params = $sendTudu->getStorageParams();
                     if (!empty($params['to'])) {
                         $accepters = $daoTudu->getAccepters($tudu->tuduId);
                         foreach ($accepters as $item) {
                             $daoTudu->removeAccepter($tudu->tuduId, $item['uniqueid']);
                         }
                     }
                     $daoTudu->updateTudu($tudu->tuduId, $params);
                     $modelTudu = new Model_Tudu_Send_Common();
                     $modelTudu->send($sendTudu);
                     // 更新进度
                     $manager->updateProgress($tudu->tuduId, $this->_user->uniqueId);
                     if ($tudu->parentId) {
                         $manager->calParentsProgress($tudu->parentId);
                     }
                 }
             }
         }
         // 自动确认
         if ($isDoneTudu && isset($doneParams)) {
             $manager->doneTudu($doneParams['tuduid'], true, 0);
             // 添加操作日志
             $this->_writeLog(Dao_Td_Log_Log::TYPE_TUDU, $doneParams['tuduid'], Dao_Td_Log_Log::ACTION_TUDU_DONE, array('percent' => $doneParams['percent'], 'elapsedtime' => $doneParams['elapsedtime']), false, true);
         }
         // 回复消息
         $data = implode(' ', array('tudu', 'reply', '', http_build_query($sendParam)));
         $httpsqs->put($data, 'tudu');
     }
     return $this->json(true, $this->lang['post_send_success'], array('postid' => $postId));
 }
示例#7
0
 /**
  *
  * @return Tudu_AddressBook
  */
 public function getAddressBook()
 {
     if (null === $this->_addressBook) {
         $this->_addressBook = Tudu_AddressBook::getInstance();
     }
     return $this->_addressBook;
 }
示例#8
0
 /**
  * 合并到图度组
  */
 public function mergeGroupAction()
 {
     $tuduId = $this->_request->getPost('tid');
     $targetId = $this->_request->getPost('targetid');
     // 目标图度组ID 图度ID
     if (!$targetId || !$tuduId) {
         return $this->json(false, $this->lang['invalid_tuduid']);
     }
     $targetTudu = $this->manager->getTuduById($targetId, $this->_user->uniqueId);
     // 目标图度组必须存在
     if (null == $targetTudu) {
         return $this->json(false, $this->lang['target_tudugroup_not_exists']);
     }
     $tudu = $this->manager->getTuduById($tuduId, $this->_user->uniqueId);
     // 图度必须存在
     if (null == $tudu) {
         return $this->json(false, $this->lang['tudu_not_exists']);
     }
     // 当前图度发起人是否为目标的图度组的执行人
     $isAccepter = in_array($tudu->sender, $targetTudu->accepter, true);
     /* @var $addressBook Tudu_AddressBook */
     $addressBook = Tudu_AddressBook::getInstance();
     $user = $addressBook->searchUser($this->_user->orgId, $tudu->sender);
     if (!$isAccepter) {
         $ret = $this->manager->addRecipient($targetId, $user['uniqueid'], array('role' => 'to', 'accepterinfo' => $user['email'] . ' ' . $user['truename'], 'tudustatus' => 1));
         if (!$ret) {
             return $this->json(true, $this->lang['append_tudu_group_failed']);
         }
         $this->manager->acceptTudu($targetId, $user['uniqueid'], null);
         $to = array_merge($targetTudu->accepter, (array) $tudu->sender);
         $this->manager->updateTudu($targetId, array('to' => implode("\n", $to)));
         $stepUser = array(array('uniqueid' => $user['uniqueid'], 'accepterinfo' => $user['email'] . ' ' . $user['truename'], 'processindex' => 0, 'stepstatus' => 0, 'percent' => 0));
         $this->manager->addStepUsers($targetId, $targetTudu->stepId, $stepUser);
         $this->manager->addLabel($targetId, $user['uniqueid'], '^all');
         $this->manager->addLabel($targetId, $user['uniqueid'], '^i');
         $this->manager->addLabel($targetId, $user['uniqueid'], '^a');
     }
     /* @var $daoGroup Dao_Td_Tudu_Group */
     $daoGroup = $this->getDao('Dao_Td_Tudu_Group');
     $ret = $daoGroup->createNode(array('tuduid' => $tuduId, 'parentid' => $targetId, 'uniqueid' => $user['uniqueid'], 'rootid' => !empty($targetTudu->rootId) ? $targetTudu->rootId : null, 'type' => Dao_Td_Tudu_Group::TYPE_LEAF));
     if (!$ret) {
         return $this->json(true, $this->lang['append_tudu_group_failed']);
     }
     // 计算图度组进度
     $this->manager->calParentsProgress($targetId);
     // 标记所有为未读
     $this->manager->markAllUnRead($targetId);
     return $this->json(true, $this->lang['append_tudu_group_success']);
 }
示例#9
0
文件: Tudu.php 项目: bjtenao/tudu-web
 /**
  * 生成周期图度
  *
  * @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 Model_Tudu_Tudu $tudu
  * @return array
  */
 protected function _getRecipients(Model_Tudu_Tudu &$tudu)
 {
     $uniqueId = $this->_user->uniqueId;
     $orgId = $this->_user->orgId;
     require_once 'Tudu/AddressBook.php';
     /* @var $addressBook Tudu_AddressBook */
     $addressBook = Tudu_AddressBook::getInstance();
     $recipients = array();
     if ($tudu->reviewer) {
         foreach ($tudu->reviewer as $item) {
             if (!isset($item['email']) && !isset($item['username'])) {
                 continue;
             }
             $userName = isset($item['email']) ? $item['email'] : $item['username'];
             if (empty($item['uniqueid'])) {
                 $user = $addressBook->searchUser($orgId, $userName);
                 if (null === $user) {
                     $user = $addressBook->searchContact($uniqueId, $userName, $item['truename']);
                     if (null === $user) {
                         $user = $addressBook->prepareContact($userName, $item['truename']);
                     }
                 }
             } else {
                 $user = $item;
             }
             $user['accepterinfo'] = $userName . ' ' . $user['truename'];
             $user['isreview'] = true;
             $recipients[$user['uniqueid']] = $user;
         }
         // 接收人
     } elseif ($tudu->to) {
         $arrayTo = $tudu->to;
         foreach ($arrayTo as $key => $item) {
             if (isset($item['groupid']) && $tudu->type == 'meeting') {
                 if (0 === strpos($item['groupid'], 'XG')) {
                     $users = $addressBook->getGroupContacts($orgId, $uniqueId, $item['groupid']);
                 } else {
                     $users = $addressBook->getGroupUsers($orgId, $item['groupid']);
                 }
                 $to = array();
                 foreach ($users as $key => $user) {
                     $users[$key]['role'] = 'to';
                     $users[$key]['accepterinfo'] = $users[$key]['email'] . ' ' . $users[$key]['truename'];
                     $users[$key]['issender'] = $users[$key]['email'] == $tudu->sender;
                     $to[] = $users[$key]['accepterinfo'];
                     $recipients[$key] = $users[$key];
                 }
                 $tudu->to = implode("\n", $to);
             } else {
                 if (empty($item['uniqueid'])) {
                     if (empty($item['email']) && empty($item['username'])) {
                         continue;
                     }
                     $email = isset($item['email']) ? $item['email'] : $item['username'];
                     $user = $addressBook->searchUser($orgId, $email);
                     if (null === $user) {
                         $trueName = isset($item['truename']) ? $item['truename'] : $email;
                         $user = $addressBook->searchContact($uniqueId, $email, $item['truename']);
                         if (null === $user) {
                             $user = $addressBook->prepareContact($email, $item['truename']);
                         }
                     }
                 } else {
                     $user = $item;
                 }
                 $userName = isset($user['username']) ? $user['username'] : $user['email'];
                 $user['role'] = 'to';
                 $user['accepterinfo'] = $userName . ' ' . $user['truename'];
                 $user['issender'] = $userName == $tudu->sender;
                 $percent = isset($item['percent']) ? (int) $item['percent'] : 0;
                 $user['percent'] = $percent;
                 $user['tudustatus'] = $percent >= 100 ? 2 : ($percent == 0 ? 0 : 1);
                 $recipients[$user['uniqueid']] = $user;
             }
         }
     }
     // 有审批人的公告
     if ($tudu->type == 'notice' && $tudu->reviewer) {
         return $recipients;
     }
     if ($tudu->cc) {
         foreach ($tudu->cc as $key => $item) {
             if (isset($item['groupid'])) {
                 if (is_int($item['groupid']) || empty($item['groupid'])) {
                     continue;
                 }
                 if (0 === strpos($item['groupid'], 'XG')) {
                     $users = $addressBook->getGroupContacts($orgId, $uniqueId, $item['groupid']);
                 } else {
                     $users = $addressBook->getGroupUsers($orgId, $item['groupid']);
                 }
                 $recipients = array_merge($users, $recipients);
             } else {
                 $userName = isset($item['username']) ? $item['username'] : $item['email'];
                 $user = $addressBook->searchUser($orgId, $userName);
                 if (null === $user) {
                     $user = $addressBook->searchContact($uniqueId, $userName, $item['truename']);
                     if (null === $user) {
                         $user = $addressBook->prepareContact($userName, $item['truename']);
                     }
                 }
                 if (!isset($recipients[$user['uniqueid']])) {
                     $recipients[$user['uniqueid']] = $user;
                 }
             }
         }
     }
     if ($tudu->bcc) {
         foreach ($tudu->bcc as $key => $item) {
             if (isset($item['groupid'])) {
                 if (is_int($item['groupid']) || empty($item['groupid'])) {
                     continue;
                 }
                 if (0 === strpos($item['groupid'], 'XG')) {
                     $users = $addressBook->getGroupContacts($orgId, $uniqueId, $item['groupid']);
                 } else {
                     $users = $addressBook->getGroupUsers($orgId, $item['groupid']);
                 }
                 $recipients = array_merge($users, $recipients);
             } else {
                 $userName = isset($item['username']) ? $item['username'] : $item['email'];
                 $user = $addressBook->searchUser($orgId, $userName);
                 if (null === $user) {
                     $user = $addressBook->searchContact($uniqueId, $userName, $item['truename']);
                     if (null === $user) {
                         $user = $addressBook->prepareContact($userName, $item['truename']);
                     }
                 }
                 if (!isset($recipients[$user['uniqueid']])) {
                     $recipients[$user['uniqueid']] = $user;
                 }
             }
         }
     }
     return $recipients;
 }
示例#11
0
 /**
  * 保存工作日调整
  */
 public function saveadjustAction()
 {
     // 权限验证
     $role = $this->getRoles();
     if (empty($role['admin'])) {
         Oray_Function::alert('您没有创建或修改工作日调整的权限', '/app/attend/schedule/index');
     }
     $adjustId = $this->_request->getPost('adjustid');
     $post = $this->_request->getPost();
     $users = $this->_request->getPost('user');
     if (!is_array($users) || empty($users)) {
         return $this->json(false, $this->lang['param_user_null']);
     }
     $startTime = strtotime($post['starttime']);
     $endTime = strtotime($post['endtime']);
     $params = array('subject' => $post['subject'], 'starttime' => $startTime, 'endtime' => $endTime, 'type' => $post['type']);
     $adjustDate = array('starttime' => $startTime, 'endtime' => $endTime);
     /* @var $daoAdjust Dao_App_Attend_Schedule_Adjust */
     $daoAdjust = Tudu_Dao_Manager::getDao('Dao_App_Attend_Schedule_Adjust', Tudu_Dao_Manager::DB_APP);
     if ($adjustId) {
         $adjust = $daoAdjust->getAdjust(array('adjustid' => $adjustId));
         // 不存在
         if (null === $adjust || $adjust->orgId != $this->_user->orgId) {
             return $this->json(false, $this->lang['adjust_not_exists']);
         }
         $daoAdjust->updateAdjust($adjustId, $params);
         $daoAdjust->removeUser($adjustId);
     } else {
         $params['orgid'] = $this->_user->orgId;
         $params['adjustid'] = Dao_App_Attend_Schedule_Adjust::getAdjustId();
         $params['createtime'] = time();
         $adjustId = $daoAdjust->createAdjust($params);
     }
     // 添加用户
     $addressBook = Tudu_AddressBook::getInstance();
     foreach ($users as $item) {
         // 帐号
         if (false !== strpos($item, '@')) {
             $members = array($addressBook->searchUser($this->_user->orgId, $item));
             // 群组
         } else {
             $members = $addressBook->getGroupUsers($this->_user->orgId, $item);
         }
         foreach ($members as $user) {
             // 添加用户关联
             $daoAdjust->addUser(array('orgid' => $this->_user->orgId, 'adjustid' => $adjustId, 'uniqueid' => $user['uniqueid'], 'createtime' => time()));
             $this->updateAdjustAttend($user['uniqueid'], $post['type'], $adjustDate);
         }
     }
     return $this->json(true, $this->lang['save_adjust_success']);
 }
示例#12
0
文件: Flow.php 项目: bjtenao/tudu-web
 /**
  * 整理工作步骤
  *
  * @param Tudu_Tudu_Storage_Tudu $tudu
  */
 public function onPrepareFlow(Tudu_Tudu_Storage_Tudu &$tudu)
 {
     $flow = $this->getFlowById($tudu->flowId);
     if (null !== $flow) {
         $flow = $flow->toArray();
         // 没有步骤
         if (count($flow['steps']) <= 0) {
             require_once 'Tudu/Tudu/Exception.php';
             throw new Tudu_Tudu_Exception('Flow has not any steps', Tudu_Tudu_Exception::CODE_FLOW_STEP_NULL);
         }
         // 整理抄送人
         if (!empty($flow['cc'])) {
             $cc = array();
             foreach ($flow['cc'] as $key => $item) {
                 if (false !== strpos($key, '@')) {
                     $cc[$key] = array('email' => $key, 'truename' => $item[0]);
                 } else {
                     $cc[$key] = array('groupid' => $key, 'truename' => $item[0]);
                 }
             }
             $tudu->cc = array_merge($tudu->cc, $cc);
         }
         // 第一步骤ID
         $steps = $flow['steps'];
         $prevUsers = array(array('email' => $tudu->email));
         $prevType = 0;
         $addressBook = Tudu_AddressBook::getInstance();
         $depts = $this->_getDepartments($tudu->orgId);
         $tuduSteps = array();
         $orderNum = 1;
         foreach ($steps as $key => $step) {
             $stepId = $step['id'];
             if ($step['type'] == 1) {
                 // 上级审批
                 if ($step['users'] == '^upper') {
                     // 上一步是审批
                     $reviewerIds = array();
                     if ($prevType == 1) {
                         foreach ($prevUsers as $item) {
                             foreach ($item as $user) {
                                 $user = $addressBook->searchUser($tudu->orgId, $user['email']);
                                 if (!$user) {
                                     require_once 'Tudu/Tudu/Exception.php';
                                     throw new Tudu_Tudu_Exception('User is not exists', Tudu_Tudu_Exception::CODE_NOT_EXISTS_USER);
                                 }
                                 $moderatorIds = $this->_getUpper($user['email'], $tudu->orgId, $user['deptid']);
                                 foreach ($moderatorIds as $uid) {
                                     $reviewerIds[] = $uid;
                                 }
                             }
                         }
                     } else {
                         foreach ($prevUsers as $user) {
                             $user = $addressBook->searchUser($tudu->orgId, $user['email']);
                             if (!$user) {
                                 require_once 'Tudu/Tudu/Exception.php';
                                 throw new Tudu_Tudu_Exception('User is not exists', Tudu_Tudu_Exception::CODE_NOT_EXISTS_USER);
                             }
                             $moderatorIds = $this->_getUpper($user['email'], $tudu->orgId, $user['deptid']);
                             foreach ($moderatorIds as $uid) {
                                 $reviewerIds[] = $uid;
                             }
                         }
                     }
                     if (empty($reviewerIds)) {
                         require_once 'Tudu/Tudu/Exception.php';
                         throw new Tudu_Tudu_Exception('Upper is not exists', Tudu_Tudu_Exception::CODE_NOT_EXISTS_UPPER);
                     }
                     $reviewers = array();
                     $reviewerIds = array_unique($reviewerIds);
                     foreach ($reviewerIds as $uId) {
                         $user = $addressBook->searchUser($tudu->orgId, $uId . '@' . $tudu->orgId);
                         if (empty($user)) {
                             require_once 'Tudu/Tudu/Exception.php';
                             throw new Tudu_Tudu_Exception('User is not exists', Tudu_Tudu_Exception::CODE_NOT_EXISTS_USER);
                         }
                         $reviewers[] = $user;
                     }
                     $users = array($reviewers);
                     $prevUsers = $users;
                     // 指定
                 } else {
                     $prevUsers = $users = Tudu_Tudu_Storage::formatReviewer($step['users']);
                     foreach ($users as $item) {
                         foreach ($item as $u) {
                             $user = $addressBook->searchUser($tudu->orgId, $u['email']);
                             if (!$user) {
                                 require_once 'Tudu/Tudu/Exception.php';
                                 throw new Tudu_Tudu_Exception('User is not exists', Tudu_Tudu_Exception::CODE_NOT_EXISTS_USER);
                             }
                         }
                     }
                 }
                 $recipients = array();
                 $processIndex = 1;
                 foreach ($users as $item) {
                     foreach ($item as $user) {
                         $recipients[] = array('email' => $user['email'], 'truename' => $user['truename'], 'processindex' => $processIndex, 'stepstatus' => $processIndex == 1 ? 1 : 0);
                     }
                     $processIndex++;
                 }
                 $tuduSteps[$stepId] = array('orgid' => $tudu->orgId, 'tuduid' => $tudu->tuduId, 'uniqueid' => $tudu->uniqueId, 'stepid' => $stepId, 'type' => Dao_Td_Tudu_Step::TYPE_EXAMINE, 'prevstepid' => $step['prev'], 'nextstepid' => $step['next'], 'users' => $recipients, 'ordernum' => $orderNum++, 'createtime' => time());
             } else {
                 $prevUsers = $users = Tudu_Tudu_Storage::formatRecipients($step['users']);
                 foreach ($prevUsers as $u) {
                     $user = $addressBook->searchUser($tudu->orgId, $u['email']);
                     if (!$user) {
                         require_once 'Tudu/Tudu/Exception.php';
                         throw new Tudu_Tudu_Exception('User is not exists', Tudu_Tudu_Exception::CODE_NOT_EXISTS_USER);
                     }
                 }
                 $tuduSteps[$stepId] = array('orgid' => $tudu->orgId, 'tuduid' => $tudu->tuduId, 'uniqueid' => $tudu->uniqueId, 'stepid' => $stepId, 'type' => $step['type'] == 2 ? Dao_Td_Tudu_Step::TYPE_CLAIM : Dao_Td_Tudu_Step::TYPE_EXECUTE, 'prevstepid' => $step['prev'], 'nextstepid' => $step['next'], 'users' => $users, 'ordernum' => $orderNum++, 'createtime' => time());
             }
             $prevType = $step['type'];
         }
         $tudu->steps = $tuduSteps;
         // 第一步骤ID
         $firstStep = reset($tuduSteps);
         $tudu->stepId = $firstStep['stepid'];
         if ($firstStep['type'] == 1) {
             $users = $firstStep['users'];
             $reviewers = array();
             foreach ($users as $user) {
                 if ($user['processindex'] == 1) {
                     $reviewers[] = $user;
                 }
             }
             $tudu->reviewer = array($reviewers);
         } else {
             $tudu->to = $firstStep['users'];
         }
         $tudu->status = Dao_Td_Tudu_Tudu::STATUS_DOING;
     }
 }
示例#13
0
 /**
  *
  * @param Model_Tudu_Post $post
  */
 public function send(Model_Tudu_Post &$post)
 {
     if (!$post->content) {
         require 'Model/Tudu/Exception.php';
         throw new Model_Tudu_Exception('Missing parameter "content" for post', Model_Tudu_Exception::MISSING_PARAMETER);
     }
     $this->save($post);
     /* @var $daoTudu Dao_Td_Tudu_Tudu */
     $daoTudu = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Tudu', Tudu_Dao_Manager::DB_TS);
     /* @var $daoTudu Dao_Td_Tudu_Post */
     $daoPost = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Post', Tudu_Dao_Manager::DB_TS);
     // 未读
     if (!$this->_fromPost || !$this->_fromPost->isSend) {
         $daoTudu->markAllUnread($this->_tudu->tuduId);
     }
     if ($this->_tudu->isRead) {
         $daoTudu->markRead($this->_tudu->tuduId, $this->_user->uniqueId, true);
     }
     /* @var $daoLog Dao_Td_Log_Log */
     $daoLog = Tudu_Dao_Manager::getDao('Dao_Td_Log_Log', Tudu_Dao_Manager::DB_TS);
     $tuduPercent = null;
     $flowPercent = null;
     if ($post->percent > 0 && $this->_tudu->selfPercent < 100) {
         if ($this->_tudu->flowId) {
             $tuduPercent = $daoTudu->updateFlowProgress($this->_tudu->tuduId, $this->_tudu->uniqueId, $this->_tudu->stepId, $post->percent, $flowPercent);
         } else {
             $tuduPercent = $daoTudu->updateProgress($this->_tudu->tuduId, $this->_tudu->uniqueId, $post->percent);
         }
         if (!$this->_fromPost || !$this->_fromPost->isSend || $this->_fromTudu->selfPercent != $post->percent) {
             // 添加操作日志
             $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_TUDU, 'targetid' => $this->_tudu->tuduId, 'action' => Dao_Td_Log_Log::ACTION_TUDU_PROGRESS, 'detail' => serialize(array('percent' => $tuduPercent, 'elapsedtime' => $this->_tudu->elapsedTime + (int) $post->elapsedtime)), 'privacy' => 0));
         }
     }
     // 自动完成
     if ($post->percent && ($tuduPercent >= 100 && null === $flowPercent || $flowPercent >= 100)) {
         if (in_array($this->_tudu->sender, array($this->_user->userName, $this->_user->account)) || !$this->_tudu->needConfirm) {
             $daoTudu->doneTudu($this->_tudu->tuduId, true, 0);
             // 添加操作日志
             $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_TUDU, 'targetid' => $this->_tudu->tuduId, 'action' => Dao_Td_Log_Log::ACTION_TUDU_PROGRESS, 'detail' => serialize(array('percent' => $tuduPercent, 'elapsedtime' => $this->_tudu->elapsedTime + (int) $post->elapsedTime)), 'privacy' => 0));
             // 添加到发起人图度箱 -- 待确认中
         } else {
             /* @var $addressBook Tudu_AddressBook */
             $addressBook = Tudu_AddressBook::getInstance();
             $sender = $addressBook->searchUser($this->_user->orgId, $this->_tudu->sender);
             $daoTudu->addLabel($this->_tudu->tuduId, $sender['uniqueid'], '^i');
         }
     }
     // 计算父级图度进度  及 图度组达到100%时,确认
     if ($this->_tudu->parentId) {
         $parentPercent = $daoTudu->calParentsProgress($this->_tudu->parentId);
         if ($parentPercent >= 100) {
             $sendParam['confirm'] = true;
         }
     }
     // 发送回复
     $daoPost->sendPost($this->_tudu->tuduId, $post->postId);
     // 统计时间
     if ($post->percent) {
         $daoTudu->calcElapsedTime($this->_tudu->tuduId);
     }
     // 周期任务
     if ($post->percent && $this->_tudu->cycleId && $tuduPercent >= 100) {
         $daoCycle = $this->getDao('Dao_Td_Tudu_Cycle');
         $cycle = $daoCycle->getCycle(array('cycleid' => $this->_tudu->cycleId));
         if ($cycle->count == $this->_tudu->cycleNum) {
             $sendParam['cycle'] = true;
         }
     }
     if ($this->_tudu->flowId && $tuduPercent >= 100) {
         $this->addAction('send', array($this, 'tuduFlowStepDone'), 1);
     }
 }
示例#14
0
文件: Flow.php 项目: bjtenao/tudu-web
 /**
  *
  * @param Tudu_Model_Tudu_Entity_Step $step
  */
 public function createStep(Tudu_Model_Tudu_Entity_Step $step)
 {
     /* @var $daoStep Dao_Td_Tudu_Step */
     $daoStep = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Step', Tudu_Dao_Manager::DB_TS);
     $addressBook = Tudu_AddressBook::getInstance();
     $attrs = $step->getAttributes();
     if (!$daoStep->createStep($attrs)) {
         require_once 'Tudu/Model/Tudu/Exception.php';
         throw new Tudu_Model_Exception('Save tudu step failure');
     }
     $sec = $step->getSections();
     $processIndex = 1;
     foreach ($sec as $users) {
         $recipients = array();
         foreach ($users as $key => $item) {
             $user = $addressBook->searchUser($step->orgId, $item['email']);
             if (null === $user) {
                 $user = $addressBook->searchContact($step->uniqueId, $item['email'], $item['truename']);
                 if (null === $user) {
                     $user = $addressBook->prepareContact($item['email'], $item['truename']);
                 }
             }
             $daoStep->addUser(array('tuduid' => $step->tuduId, 'stepid' => $step->stepId, 'uniqueid' => $user['uniqueid'], 'userinfo' => $user['email'] . ' ' . $user['truename'], 'status' => $processIndex == 1 ? 1 : 0, 'processindex' => $processIndex));
         }
         $processIndex++;
     }
 }