コード例 #1
0
ファイル: Manager.php プロジェクト: bjtenao/tudu-web
 /**
  * 获取对象实例
  *
  * @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
ファイル: Notice.php プロジェクト: bjtenao/tudu-web
 /**
  * 执行讨论数据处理
  */
 public function run()
 {
     foreach ($this->_dbs as $key => $db) {
         // 清理过期置顶公告
         $sql = 'SELECT tudu_id FROM td_tudu WHERE type = \'notice\' AND end_time IS NOT NULL AND is_top = 1 ' . 'AND end_time < ' . strtotime('today');
         Tudu_Dao_Manager::setDb(Tudu_Dao_Manager::DB_TS, $db, true);
         $manager = Tudu_Tudu_Manager::getInstance();
         $array = $db->fetchAll($sql);
         foreach ($array as $item) {
             if ($manager->updateTudu($item['tudu_id'], array('istop' => 0))) {
                 $users = $manager->getTuduUsers($item['tudu_id']);
                 foreach ($users as $user) {
                     if (!$user['isread']) {
                         continue;
                     }
                     $manager->deleteLabel($item['tudu_id'], $user['uniqueid'], '^i');
                 }
                 $this->getLogger()->info("Notice id:{$item['tudu_id']} update success");
                 continue;
             }
             $this->getLogger()->warn("Notice id:{$item['tudu_id']} update failed");
         }
         $this->getLogger()->info("Ts db:({$key}) process complete");
     }
 }
コード例 #3
0
ファイル: Foreign.php プロジェクト: bjtenao/tudu-web
 /**
  * 初始化
  */
 public function init()
 {
     $this->_bootstrap = $this->getInvokeArg('bootstrap');
     $this->_multidb = $this->_bootstrap->getResource('multidb');
     $this->_options = $this->_bootstrap->getOptions();
     $this->_helper->viewRenderer->view->setBasePath(APPLICATION_PATH . '/modules/foreign/views');
     $this->_helper->viewRenderer->setViewScriptPathSpec(':module#:controller#:action.:suffix');
     $this->_tsId = $this->_request->getParam('ts');
     $tuduId = $this->_request->getParam('tid');
     $unId = $this->_request->getParam('fid');
     if (!$this->_tsId || !$tuduId || !$unId) {
         $this->getResponse()->setHttpResponseCode(404);
         $this->getResponse()->sendResponse();
         return;
     }
     Tudu_Dao_Manager::setDbs(array(Tudu_Dao_Manager::DB_TS => $this->getTsDb($this->_tsId)));
     $this->_manager = Tudu_Tudu_Manager::getInstance();
     $this->_deliver = new Tudu_Deliver($this->getTsDb($this->_tsId));
     $this->_tudu = $this->_manager->getTuduById($tuduId, $unId);
     $this->_user = $this->_manager->getUser($tuduId, $unId);
     if (null !== $this->_user) {
         // 用户请求语言
         $language = $this->_request->getHeader('ACCEPT_LANGUAGE');
         if (strpos($language, 'zh') !== false) {
             if (strpos($language, 'hk') !== false || strpos($language, 'tw') !== false) {
                 $language = 'zh_TW';
             } else {
                 $language = 'zh_CN';
             }
         } else {
             $language = 'en_US';
         }
         $this->_user['option'] = array('language' => $language);
         if (null !== $this->_tudu) {
             $this->_session = new Zend_Session_Namespace(self::SESSION_NAMESPACE, true);
             $this->_sessionId = Zend_Session::getId();
             //
             /*if (isset($this->_session->foreign['uniqueid']) && $this->_session->foreign['uniqueid'] != $this->_user['uniqueid']) {
                   $this->_destroySession();
               }*/
             $this->_session->foreign['uniqueid'] = $this->_user['uniqueid'];
             $this->_session->foreign['address'] = $this->_user['email'] ? $this->_user['email'] : $this->_user['uniqueid'];
             $this->_session->foreign['truename'] = $this->_user['truename'];
             $this->_session->foreign['logintime'] = time();
             $this->_session->foreign['orgid'] = $this->_tudu->orgId;
             $this->_session->foreign['tsid'] = $this->_tsId;
             $this->_session->foreign['lasttime'] = time();
             if (empty($this->_session->auth)) {
                 $this->_session->auth = array('uniqueid' => $this->_user['uniqueid'], 'address' => $this->_session->foreign['address'], 'logintime' => $this->_session->foreign['logintime']);
             }
         }
         $this->_timestamp = time();
         $this->view->options = $this->_options;
         $this->view->tsid = $this->_tsId;
         $this->view->user = $this->_user;
     }
 }
コード例 #4
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']);
 }
コード例 #5
0
ファイル: Discuss.php プロジェクト: bjtenao/tudu-web
 /**
  * 执行讨论数据处理
  */
 public function run()
 {
     foreach ($this->_dbs as $key => $db) {
         // 清理过期讨论
         $sql = 'SELECT tudu_id, org_id FROM td_tudu WHERE type = \'discuss\' AND end_time IS NOT NULL ' . 'AND is_draft = 0 AND is_done = 0 AND end_time < ' . strtotime('today');
         Tudu_Dao_Manager::setDb(Tudu_Dao_Manager::DB_TS, $db, true);
         $manager = Tudu_Tudu_Manager::getInstance();
         $daoLog = Tudu_Dao_Manager::getDao('Dao_Td_Log_Log', Tudu_Dao_Manager::DB_TS);
         $array = $db->fetchAll($sql);
         foreach ($array as $item) {
             if ($manager->closeTudu($item['tudu_id'], true)) {
                 $this->getLogger()->info("Discuss id:({$item['tudu_id']}) close success");
                 // 成功记录操作日志
                 $daoLog->createLog(array('orgid' => $item['org_id'], 'targettype' => Dao_Td_Log_Log::TYPE_TUDU, 'targetid' => $item['tudu_id'], 'uniqueid' => '^system', 'action' => Dao_Td_Log_Log::ACTION_CLOSE, 'detail' => serialize(array('isdone' => true)), 'logtime' => time()));
                 continue;
             }
             $this->getLogger()->warn("Discuss id:{$item['tudu_id']} close failure");
         }
         $this->getLogger()->info("Ts db:({$key}) process complete");
     }
 }
コード例 #6
0
ファイル: Send.php プロジェクト: bjtenao/tudu-web
 /**
  * 外发会议
  *
  * @param array $params
  */
 public function sendMeeting($params)
 {
     if (empty($params['tuduid']) || empty($params['tsid']) || empty($params['uniqueid']) || empty($params['from']) || empty($params['content']) || empty($params['location'])) {
         return;
     }
     $tuduId = $params['tuduid'];
     $uniqueId = $params['uniqueid'];
     $tsId = $params['tsid'];
     $to = !empty($params['to']) ? explode(',', $params['to']) : null;
     $sender = $params['from'];
     $content = $params['content'];
     $location = $params['location'];
     /* @var $manager Tudu_Tudu_Manager */
     $manager = Tudu_Tudu_Manager::getInstance(Tudu_Dao_Manager::getDb(Tudu_Dao_Manager::DB_TS));
     $tudu = $manager->getTuduById($tuduId, $uniqueId);
     if (null == $tudu) {
         $this->getLogger()->warn("Tudu id:{$tuduId} is not exists");
         return;
     }
     // 获取接收人
     $receivers = $manager->getTuduUsers($tudu->tuduId);
     $emails = array();
     /* @var $daoContact Dao_Td_Contact_Contact */
     $daoContact = Tudu_Dao_Manager::getDao('Dao_Td_Contact_Contact', Tudu_Dao_Manager::DB_TS);
     // 处理接收人数据
     foreach ($receivers as $receiver) {
         $info = explode(' ', $receiver['accepterinfo'], 3);
         $email = $info[0];
         $name = !empty($info[1]) ? $info[1] : null;
         $contactId = isset($info[2]) ? $info[2] : null;
         if ($name == null && $email) {
             $arr = explode('@', $email);
             $name = array_shift($arr);
         }
         if (!$email && !$name) {
             continue;
         }
         if (!empty($to) && !in_array($email, $to)) {
             continue;
         }
         if ($receiver['isforeign']) {
             $auth = $receiver['authcode'];
             if (Oray_Function::isEmail($email) && $uniqueId != $receiver['uniqueid']) {
                 $array = array('address' => $email, 'name' => $name, 'authinfo' => '', 'url' => 'http://' . $tudu->orgId . '.com/foreign/tudu?ts=' . $tsId . '&tid=' . $tudu->tuduId . '&fid=' . $receiver['uniqueid']);
                 if ($auth) {
                     $array['authinfo'] = '<p style="margin:10px 0">打开任务链接后需要输入以下验证码:<strong style="color:#f00">' . $auth . '</strong></p>';
                 }
                 $emails[] = $array;
             }
         }
     }
     // 执行外发
     $tpl = $this->_options['data']['path'] . '/templates/tudu/mail_meeting_notify.tpl';
     if (!file_exists($tpl) || !is_readable($tpl)) {
         $this->getLogger()->warn("Tpl file:\"mail_meeting_notify.tpl\" is not exists");
         return;
     }
     // 公用信息
     $common = array('subject' => $tudu->subject, 'sender' => $sender, 'lastupdate' => date('Y-m-d H:i:s', $tudu->lastPostTime), 'content' => mb_substr(strip_tags($content), 0, 20, 'utf-8'), 'type' => $this->_typeNames[$tudu->type]);
     $mailTransport = $this->getMailTransport($this->_balancer->select());
     $template = $this->_assignTpl(file_get_contents($tpl), $common);
     foreach ($emails as $email) {
         try {
             $mail = new Zend_Mail('utf-8');
             $mail->setFrom($this->_options['smtp']['from']['alert'], urldecode($this->_options['smtp']['fromname']));
             $mail->addTo($email['address'], $email['name']);
             $mail->addHeader('tid', $tudu->tuduId);
             $mail->setSubject("图度{$this->_typeNames[$tudu->type]}——" . $tudu->subject . '[会议提醒]');
             $mail->setBodyHtml($this->_assignTpl($template, $email));
             $mail->send($mailTransport);
         } catch (Zend_Mail_Exception $ex) {
             $this->getLogger()->warn("[Failed] Email send type:{$this->_typeNames[$tudu->type]} TuduId:{$tuduId} retry\n{$ex}");
             continue;
         }
     }
     $this->getLogger()->debug("Send Meeting id:{$tuduId} done");
 }
コード例 #7
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));
 }
コード例 #8
0
ファイル: Tudu.php プロジェクト: bjtenao/tudu-web
 /**
  * @return Tudu_Tudu_Manager
  */
 public function getManager()
 {
     /**
      * @see Tudu_Tudu_Manager
      */
     require_once 'Tudu/Tudu/Manager.php';
     $manager = Tudu_Tudu_Manager::getInstance();
     return $manager;
 }
コード例 #9
0
ファイル: Apply.php プロジェクト: bjtenao/tudu-web
 /**
  *
  */
 public function cancelAction()
 {
     $applyId = $this->_request->getPost('applyid');
     $daoApply = Tudu_Dao_Manager::getDao('Dao_App_Attend_Apply', Tudu_Dao_Manager::DB_APP);
     $apply = $daoApply->getApply(array('applyid' => $applyId));
     if (null == $apply && $apply->senderId !== $this->_user->uniqueId && $apply->uniqueId !== $this->_user->uniqueId) {
         return $this->json(false, $this->lang['apply_not_exists']);
     }
     $ret = $daoApply->updateApply($applyId, array('status' => 4));
     if (!$ret) {
         return $this->json(fasle, $this->lang['apply_cancel_failure']);
     }
     // 取消图度
     $manager = Tudu_Tudu_Manager::getInstance();
     $tudu = $manager->getTuduById($apply->tuduId, $this->_user->uniqueId);
     if (null !== $tudu) {
         // 执行终止(取消)操作
         $ret = $manager->cancelTudu($apply->tuduId, true, '', $tudu->parentId);
         if ($ret) {
             $daoLog = Tudu_Dao_Manager::getDao('Dao_Td_Log_Log', Tudu_Dao_Manager::DB_TS);
             $daoLog->createLog(array('orgid' => $this->_user->orgId, 'uniqueid' => $this->_user->uniqueId, 'operator' => $this->_user->userName . ' ' . $this->_user->trueName, 'logtime' => time(), 'targettype' => Dao_Td_Log_Log::TYPE_TUDU, 'targetid' => $apply->tuduId, 'action' => Dao_Td_Log_Log::ACTION_TUDU_CANCEL, 'detail' => serialize(array('accepttime' => null, 'status' => Dao_Td_Tudu_Tudu::STATUS_CANCEL, 'isdone' => true, 'score' => '')), 'privacy' => 0));
         }
     }
     return $this->json(true, $this->lang['apply_cancel_success']);
 }
コード例 #10
0
ファイル: Admin.php プロジェクト: bjtenao/tudu-web
 /**
  *
  * @param string $params
  */
 public function deleteUser($params)
 {
     list($orgId, $uniqueIds) = explode(':', $params);
     $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));
     $daoTudu = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Tudu', Tudu_Dao_Manager::DB_TS);
     $uniqueIds = explode(',', $uniqueIds);
     foreach ($uniqueIds as $uniqueId) {
         $tudus = $daoTudu->getUserTudus(array('uniqueid' => $uniqueId, 'type' => 'task'));
         if (count($tudus)) {
             foreach ($tudus as $tudu) {
                 // 确认图度
                 if ($tudu['role'] == 'from' && $tudu['needconfirm'] && $tudu['percent'] == 100) {
                     $ret = $manager->doneTudu($tudu['tuduid'], true, 0);
                     if (!$ret) {
                         $this->getLogger()->warn("Done Tudu failed id:{$tudu['tuduid']}");
                     }
                 }
                 // 取消(终止)
                 if ($tudu['role'] == 'from' && $tudu['from'] == $tudu['to']) {
                     $params = array('status' => Dao_Td_Tudu_Tudu::STATUS_CANCEL, 'isdone' => 1);
                     // 更新图度
                     $ret = $manager->updateTudu($tudu['tuduid'], $params);
                     if (!$ret) {
                         $data = serialize($params);
                         $this->getLogger()->warn("Update Tudu failed id:{$tudu['tuduid']} data:{$data}");
                     }
                     // 完结图度
                     $ret = $manager->doneTudu($tudu['tuduid'], true, 0);
                     if (!$ret) {
                         $this->getLogger()->warn("Done Tudu failed id:{$tudu['tuduid']}");
                     }
                 }
                 // 图度执行人待定
                 if ($tudu['role'] == 'to') {
                     // 移除执行信息
                     $ret = $daoTudu->removeAccepter($tudu['tuduid'], $uniqueId);
                     if (!$ret) {
                         $this->getLogger()->warn("Remove Accepter failed Tudu id:{$tudu['tuduid']} uid:{$uniqueId}");
                     }
                     if ($tudu['to'] == $tudu['accepterinfo']) {
                         // 更新to字段
                         $ret = $manager->updateTudu($tudu['tuduid'], array('to' => ''));
                         if (!$ret) {
                             $this->getLogger()->warn("Update Tudu failed id:{$tudu['tuduid']} to:[clear]");
                         }
                     } else {
                         $newto = array();
                         $to = explode("\n", $tudu['to']);
                         for ($i = 0; $i < count($to); $i++) {
                             if ($to[$i] != $tudu['accepterinfo']) {
                                 $newto[] = $to[$i];
                             }
                         }
                         // 更新to字段
                         $ret = $manager->updateTudu($tudu['tuduid'], array('to' => implode("\n", $newto)));
                         if (!$ret) {
                             $this->getLogger()->warn("Update Tudu failed id:{$tudu['tuduid']} to:[clear-{$tudu['accepterinfo']}]");
                         }
                     }
                 }
             }
         }
         $this->getLogger()->debug("Delete User Update Tudu On Uniqueid:{$uniqueId} done");
     }
 }
コード例 #11
0
ファイル: Tudu.php プロジェクト: bjtenao/tudu-web
 /**
  * 更新图度规则
  * @param $params
  */
 public function updateRules($params)
 {
     if (empty($params['ruleid']) || empty($params['tsid'])) {
         return;
     }
     $ruleId = $params['ruleid'];
     $manager = Tudu_Tudu_Manager::getInstance(Tudu_Dao_Manager::getDb(Tudu_Dao_Manager::DB_TS));
     /** @var $daoRule Dao_Td_Rule_Rule */
     $daoRule = Tudu_Dao_Manager::getDao('Dao_Td_Rule_Rule', Tudu_Dao_Manager::DB_TS);
     $rule = $daoRule->getRuleById($ruleId);
     if ($rule == null) {
         $this->getLogger()->warn("Tudu Rule id: {$ruleId} is not exists");
         return;
     }
     $uniqueId = $rule->uniqueId;
     $filters = $rule->getFilters()->toArray();
     if (count($filters) <= 0) {
         $this->getLogger()->warn("Tudu Rule->getFilters() null ruleid: {$ruleId} is not exists");
         return;
     }
     $subject = null;
     $subjectType = ' LIKE ';
     foreach ($filters as $key => $filter) {
         if ($filter['what'] == 'subject') {
             $subject = $filter['value'];
             if ($filter['type'] != 'contain') {
                 $subjectType = ' NOT LIKE ';
             }
             unset($filters[$key]);
             break;
         }
     }
     $tsdb = Tudu_Dao_Manager::getDb(Tudu_Dao_Manager::DB_TS);
     // 过滤现有tudu
     if ($rule->isValid) {
         $sql = 'SELECT t.tudu_id AS tuduid, `from`, `to`, `cc`, `subject` FROM td_tudu t ' . 'LEFT JOIN td_tudu_user tu ON t.tudu_id = tu.tudu_id ' . 'WHERE tu.unique_id = ' . $tsdb->quote($uniqueId) . ' AND tu.labels IS NOT NULL ';
         if ($subject) {
             $sql .= ' AND t.subject ' . $subjectType . $tsdb->quote('%' . $subject . '%');
         }
         $query = $tsdb->query($sql);
         while ($row = $query->fetch()) {
             $match = false;
             if (count($filters)) {
                 $filterCount = count($filters);
                 $matchCount = 0;
                 // 检查发送人,接收人,抄送人
                 foreach ($filters as $filter) {
                     $contain = false;
                     if (in_array($filter['what'], array('from', 'to', 'cc'))) {
                         if (is_array($filter['value'])) {
                             $vc = count($filter['value']);
                             $mc = 0;
                             $arr = explode("\n", $row[$filter['what']]);
                             $users = array();
                             foreach ($arr as $item) {
                                 $item = explode(' ', $item);
                                 $users[$item[0]] = $item[1];
                             }
                             foreach ($filter['value'] as $value) {
                                 $value = str_replace(array('oray.com', 'tudu.com'), array('oray', ''), $value);
                                 if (isset($users[$value])) {
                                     if ($filter['what'] == 'from' && $filter['type'] == 'contain') {
                                         $matchCount++;
                                         continue 2;
                                     }
                                     $mc++;
                                 }
                             }
                             if ($vc == $mc) {
                                 $contain = true;
                             }
                         }
                     } elseif ($filter['what'] == 'subject') {
                         $contain = false !== strpos($tudu['subject'], $filter->value);
                     }
                     if ($contain && $filter['type'] == 'contain' || !$contain && $filter['type'] == 'exclusive') {
                         $matchCount++;
                     }
                 }
                 if ($filterCount == $matchCount && $matchCount > 0) {
                     $match = true;
                 }
             } else {
                 $match = true;
             }
             // 匹配过滤条件,执行规则操作
             if ($match) {
                 // 标签
                 if ($rule->operation == 'label') {
                     $manager->addLabel($row['tuduid'], $uniqueId, $rule->value);
                     // 忽略
                 } elseif ($rule->operation == 'ignore') {
                     $manager->deleteLabel($row['tuduid'], $uniqueId, '^i');
                     $manager->addLabel($row['tuduid'], $uniqueId, '^g');
                     // 星标
                 } elseif ($rule->operation == 'starred') {
                     $manager->addLabel($row['tuduid'], $uniqueId, '^t');
                 }
             }
         }
     }
     $this->getLogger()->debug("Rule id:{$ruleId} done");
 }
コード例 #12
0
ファイル: Meeting.php プロジェクト: bjtenao/tudu-web
 /**
  * 执行讨论数据处理
  */
 public function run()
 {
     $today = date('Y-m-d');
     foreach ($this->_dbs as $key => $db) {
         $tsId = (int) str_replace('ts', '', $key);
         // 会议提醒
         $sql = 'SELECT T.tudu_id, T.org_id, T.subject, T.from, T.start_time, M.is_allday, M.location FROM td_tudu AS T ' . 'LEFT JOIN td_tudu_meeting M ON T.tudu_id = M.tudu_id ' . 'WHERE type = \'meeting\' ' . 'AND T.is_draft = 0 ' . 'AND T.is_done = 0 ' . 'AND M.notify_time >= UNIX_TIMESTAMP() - 120 ' . 'AND M.notify_time <= UNIX_TIMESTAMP() + 60 ' . 'AND is_notified = 0';
         Tudu_Dao_Manager::setDb(Tudu_Dao_Manager::DB_TS, $db, true);
         $manager = Tudu_Tudu_Manager::getInstance();
         $meetings = $db->fetchAll($sql);
         $daoLog = Tudu_Dao_Manager::getDao('Dao_Td_Log_Log', Tudu_Dao_Manager::DB_TS);
         foreach ($meetings as $item) {
             $tuduId = $item['tudu_id'];
             $users = $db->fetchAll("SELECT accepter_info, role, is_foreign FROM td_tudu_user WHERE tudu_id = '{$tuduId}' AND role = 'to' AND tudu_status < 3");
             $flag = true;
             // 记录提醒人员
             $notifyTo = array();
             $mailTo = array();
             foreach ($users as $row) {
                 list($email, ) = explode(' ', $row['accepter_info']);
                 if (!$row['is_foreign']) {
                     $notifyTo[] = $email;
                 } else {
                     if (Oray_Function::isEmail($email)) {
                         $mailTo[] = $email;
                     }
                 }
             }
             // 发送talk提醒
             if (count($notifyTo)) {
                 $this->sendNotify($item, $notifyTo);
             }
             // 发送外部提醒(Email)
             if (count($mailTo)) {
                 $this->sendMail($tsId, $item, $mailTo);
             }
             $db->query("UPDATE td_tudu_meeting SET is_notified = 1 WHERE tudu_id = '{$tuduId}'");
             $this->getLogger()->info("Meeting id:({$tuduId}) notify success");
         }
         // 过期会议自动结束
         $sql = 'SELECT T.tudu_id, T.org_id, T.cycle_id, M.is_allday, T.end_time FROM td_tudu AS T ' . 'LEFT JOIN td_tudu_meeting M ON T.tudu_id = M.tudu_id ' . 'WHERE type = \'meeting\' ' . 'AND is_draft = 0 ' . 'AND is_done  = 0 ' . 'AND (end_time < UNIX_TIMESTAMP() OR end_time IS NULL)';
         $records = $db->fetchAll($sql);
         foreach ($records as $record) {
             $orgId = $record['org_id'];
             $tuduId = $record['tudu_id'];
             $endTime = (int) $record['end_time'];
             if ($record['is_allday'] && date('Y-m-d', $endTime) == $today) {
                 continue;
             }
             if (!$manager->updateTudu($tuduId, array('isdone' => true))) {
                 $this->getLogger()->info("Meeting id:({$tuduId}) done failure");
                 continue;
             }
             // 成功记录操作日志
             $daoLog->createLog(array('orgid' => $orgId, 'targettype' => Dao_Td_Log_Log::TYPE_TUDU, 'targetid' => $tuduId, 'uniqueid' => '^system', 'action' => Dao_Td_Log_Log::ACTION_TUDU_DONE, 'detail' => serialize(array('isdone' => true)), 'logtime' => time()));
             $users = $manager->getTuduUsers($tuduId);
             foreach ($users as $user) {
                 // 移出图度箱
                 $ret = $manager->deleteLabel($tuduId, $user['uniqueid'], '^i');
                 $ret = $manager->deleteLabel($tuduId, $user['uniqueid'], '^a');
             }
             // 周期任务
             if (!empty($record['cycle_id'])) {
                 if (!$this->cycle($tsId, $tuduId, $record['cycle_id'])) {
                     $this->getLogger()->warn("Meeting id:({$tuduId}) cycle failure");
                 }
             }
             $this->getLogger()->info("Meeting id:({$tuduId}) done success");
         }
         $this->getLogger()->info("Ts db:({$key}) process complete");
     }
 }
コード例 #13
0
ファイル: Flow.php プロジェクト: bjtenao/tudu-web
 /**
  * 工作流审批拒绝操作
  *
  * @param Tudu_Tudu_Storage_Tudu $tudu
  */
 public function flowReviewReject(Tudu_Tudu_Storage_Tudu &$tudu)
 {
     // 取得步骤
     $steps = $this->getSteps($tudu->tuduId)->toArray('stepid');
     $this->updateStepUser($tudu->tuduId, $tudu->stepId, $tudu->uniqueId, array('status' => 3));
     // 当前步骤不存在,则终止流程
     if (!isset($steps[$tudu->stepId])) {
         $tudu->stepId = self::NODE_BREAK;
         $this->preflowRejectUsers($tudu);
         return true;
     }
     $step = $steps[$tudu->stepId];
     $prevId = $step['prevstepid'];
     // 当前步骤的上一步骤是终止流程
     if ($prevId == self::NODE_BREAK) {
         $tudu->stepId = self::NODE_BREAK;
         $this->preflowRejectUsers($tudu);
         return true;
     }
     // 打回到开始
     if ($prevId == self::NODE_HEAD) {
         $tudu->stepId = self::NODE_HEAD;
         $this->preflowRejectUsers($tudu);
         return true;
     }
     // 打回, 步骤不存在,则终止流程
     if (!isset($steps[$prevId])) {
         $tudu->stepId = self::NODE_BREAK;
         $this->preflowRejectUsers($tudu);
         return true;
     }
     // 取得打回步骤信息
     $prev = $steps[$prevId];
     $updateStatus = false;
     $nextIndex = null;
     $users = $this->getStepUsers($tudu->tuduId, $prev['stepid']);
     if ($prev['type'] == Dao_Td_Tudu_Step::TYPE_EXAMINE) {
         $reviewer = array();
         foreach ($users 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;
                 $this->updateStepUser($tudu->tuduId, $prev['stepid'], $item['uniqueid'], array('status' => 1));
             }
         }
         $tudu->reviewer = array($reviewer);
     } else {
         $to = array();
         foreach ($users as $item) {
             list($email, $trueName) = explode(' ', $item['userinfo']);
             $to[$email] = array('email' => $email, 'truename' => $trueName, 'percent' => (int) $item['percent']);
             if ($item['status'] > 1) {
                 $this->updateStepUser($tudu->tuduId, $prev['stepid'], $item['uniqueid'], array('status' => 1));
                 $manager = Tudu_Tudu_Manager::getInstance();
                 $manager->updateProgress($tudu->tuduId, $item['uniqueid'], 0);
                 if ($tudu->parentId) {
                     $manager->calParentsProgress($tudu->parentId);
                 }
                 $updateStatus = true;
             }
         }
         $tudu->reviewer = null;
         $tudu->to = Tudu_Tudu_Storage::formatRecipients($to);
     }
     if ($updateStatus) {
         $this->updateStep($tudu->tuduId, $prev['stepid'], array('status' => 0));
     }
     $tudu->stepId = $prev['stepid'];
     $this->preflowRejectUsers($tudu);
     return true;
 }
コード例 #14
0
ファイル: Apply.php プロジェクト: bjtenao/tudu-web
 /**
  *
  * @param Tudu_Model_Tudu_Entity_Tudu $tudu
  * @param Tudu_Model_Tudu_Entity_Extension_Abstract $data
  */
 public function updateCheckinApply(Tudu_Model_Tudu_Entity_Tudu $tudu, Tudu_Model_Tudu_Entity_Extension_Abstract $data)
 {
     $data = $data->getAttributes();
     /* @var $daoApply Dao_App_Attend_Apply */
     $daoApply = Tudu_Dao_Manager::getDao('Dao_App_Attend_Apply', Tudu_Dao_Manager::DB_APP);
     /* @var $daoDate Dao_App_Attend_Date */
     $daoDate = Tudu_Dao_Manager::getDao('Dao_App_Attend_Date', Tudu_Dao_Manager::DB_APP);
     /* @var $daoMonth Dao_App_Attend_Month */
     $daoMonth = Tudu_Dao_Manager::getDao('Dao_App_Attend_Month', Tudu_Dao_Manager::DB_APP);
     /* @var $daoTotal Dao_App_Attend_Total */
     $daoTotal = Tudu_Dao_Manager::getDao('Dao_App_Attend_Total', Tudu_Dao_Manager::DB_APP);
     /* @var $daoCheckin Dao_App_Attend_Checkin */
     $daoCheckin = Tudu_Dao_Manager::getDao('Dao_App_Attend_Checkin', Tudu_Dao_Manager::DB_APP);
     // 更新相关状态
     $daoApply->updateApply($data['applyid'], array('status' => 2));
     $daoApply->updateReviewer($data['applyid'], $tudu->uniqueId, array('status' => 1));
     // 签到
     if ($data['checkintype'] == 0) {
         $type = 0;
         $checkinTime = $data['starttime'];
         // 签退
     } elseif ($data['checkintype'] == 1) {
         $type = 1;
         $checkinTime = $data['endtime'];
     }
     $status = Dao_App_Attend_Checkin::STATUS_NORMAL;
     // 读取补签那天排班计划
     $applyDate = strtotime(date('Y-m-d', $checkinTime));
     $applyMonth = date('Ym', $applyDate);
     $plan = $this->getPlan($data['orgid'], $data['uniqueid'], $applyDate);
     if (!empty($plan) && $plan['scheduleid'] != '^off' && $plan['scheduleid'] != '^exemption') {
         // 上班签到
         if ($type == Dao_App_Attend_Checkin::TYPE_CHECKIN && $plan['checkintime']) {
             $setCheckinTime = $applyDate + $this->formatTimeToSec($plan['checkintime']);
             if (!empty($plan['latestandard'])) {
                 $setCheckinTime += $plan['latestandard'] * 60;
             }
             if ($checkinTime > $setCheckinTime) {
                 $status = Dao_App_Attend_Checkin::STATUS_LATE;
                 if (!empty($plan['latecheckin'])) {
                     $outworkTime = $plan['latecheckin'] * 60;
                     $setCheckinTime = $applyDate + $this->formatTimeToSec($plan['checkintime']);
                     if ($checkinTime - $setCheckinTime > $outworkTime) {
                         $status = Dao_App_Attend_Checkin::STATUS_WORK;
                     }
                 }
             }
             // 下班签退
         } elseif ($type == Dao_App_Attend_Checkin::TYPE_CHECKOUT && $plan['checkouttime']) {
             $setCheckoutTime = $applyDate + $this->formatTimeToSec($plan['checkouttime']);
             $calType = 0;
             $cinTime = 0;
             if ($plan['checkintime']) {
                 // 读取签到记录
                 $checkin = $daoCheckin->getCheckin(array('orgid' => $data['orgid'], 'uniqueid' => $data['uniqueid'], 'date' => $applyDate, 'type' => 0));
                 $calType = null === $checkin ? 0 : 1;
                 if (null !== $checkin) {
                     $cinTime = $this->formatTimeToSec(date('H:i', $checkin->createTime));
                     $planCinTime = $this->formatTimeToSec($plan['checkintime']);
                     if ($planCinTime > $cinTime) {
                         $cinTime = $planCinTime;
                     }
                 }
             }
             if ($cinTime == 0) {
                 $calType = 0;
             }
             switch ($calType) {
                 case 0:
                     if ($checkinTime < $setCheckoutTime) {
                         $status = Dao_App_Attend_Checkin::STATUS_LEAVE;
                         if (!empty($plan['leavecheckout'])) {
                             $outworkTime = $plan['leavecheckout'] * 60;
                             $setCheckoutTime = $applyDate + $this->formatTimeToSec($plan['checkouttime']);
                             if ($setCheckoutTime - $checkinTime > $outworkTime) {
                                 $status = Dao_App_Attend_Checkin::STATUS_WORK;
                             }
                         }
                     }
                     break;
                 case 1:
                     $planWorkTime = $this->formatTimeToSec($plan['checkouttime']) - $this->formatTimeToSec($plan['checkintime']);
                     $userWorkTime = $this->formatTimeToSec(date('H:i', $checkinTime)) - $cinTime;
                     if ($userWorkTime < $planWorkTime) {
                         $status = Dao_App_Attend_Checkin::STATUS_LEAVE;
                         if (!empty($plan['leavecheckout']) && $this->calculateTime($userWorkTime, $planWorkTime) > $plan['leavecheckout'] * 60) {
                             $status = Dao_App_Attend_Checkin::STATUS_WORK;
                         }
                     }
                     break;
             }
         }
     }
     // 考勤当天是否有考勤申请
     $isApply = $daoDate->isApply($data['uniqueid'], $applyDate);
     if ($isApply) {
         // 有考勤申请考勤状况为正常
         $status = Dao_App_Attend_Checkin::STATUS_NORMAL;
     }
     $checkin = $daoCheckin->getCheckin(array('orgid' => $data['orgid'], 'uniqueid' => $data['uniqueid'], 'date' => $applyDate, 'type' => $type));
     if (null === $checkin) {
         // 创建签到记录
         $checkinId = $daoCheckin->createCheckin(array('checkinid' => Dao_App_Attend_Checkin::getCheckinId(), 'orgid' => $data['orgid'], 'uniqueid' => $data['uniqueid'], 'date' => $applyDate, 'status' => $status, 'type' => $type, 'createtime' => $checkinTime));
     } else {
         if ($type == Dao_App_Attend_Checkin::TYPE_CHECKIN) {
             if ($checkin->createTime > $checkinTime) {
                 $checkinId = $daoCheckin->updateCheckin($checkin->checkinId, array('status' => $status, 'createtime' => $checkinTime));
             } else {
                 $checkinId = $checkin->checkinId;
             }
         } elseif ($type == Dao_App_Attend_Checkin::TYPE_CHECKOUT) {
             if ($checkin->createTime < $checkinTime) {
                 $checkinId = $daoCheckin->updateCheckin($checkin->checkinId, array('status' => $status, 'createtime' => $checkinTime));
             } else {
                 $checkinId = $checkin->checkinId;
             }
         }
     }
     if ($checkinId) {
         // 获取签到、签退状态
         $checkinStatus = 0;
         if (!$isApply && !empty($plan) && $plan['scheduleid'] != '^off' && $plan['scheduleid'] != '^exemption') {
             $checkinStatus = $this->getCheckinStatus($plan, $data['uniqueid'], $applyDate);
         }
         $attendDate = $daoDate->getAttendDate(array('uniqueid' => $data['uniqueid'], 'date' => $applyDate));
         if (!$attendDate) {
             $iswork = 1;
             if ($isApply || $plan !== null && !$plan['checkintime'] && !$plan['checkouttime'] || empty($plan) || !empty($plan) && ($plan['scheduleid'] == '^off' || $plan['scheduleid'] == '^exemption') || $type == 0 && $plan !== null && !$plan['checkouttime'] && $status != Dao_App_Attend_Checkin::STATUS_WORK) {
                 $iswork = 0;
             }
             $daoDate->create(array('orgid' => $data['orgid'], 'uniqueid' => $data['uniqueid'], 'date' => $applyDate, 'iswork' => $iswork, 'checkinstatus' => $checkinStatus, 'updatetime' => time()));
         } else {
             if ($attendDate->checkinStatus != $checkinStatus) {
                 $update = array('checkinstatus' => $checkinStatus);
                 if ($checkinStatus != 0) {
                     $update['iswork'] = 1;
                 }
                 $daoDate->update($data['uniqueid'], $applyDate, $update);
             }
         }
         // 判断月统计表是否已有当月的统计记录
         $exists = $daoMonth->existsRecord($data['uniqueid'], $applyMonth);
         if (!$exists) {
             $daoMonth->create(array('orgid' => $data['orgid'], 'uniqueid' => $data['uniqueid'], 'date' => $applyMonth, 'updatetime' => time()));
         }
     }
     $this->attendCount($plan, $data['uniqueid'], $applyDate, $isApply);
     $memo = array($data['categoryname'], $type, $type == 0 ? $data['starttime'] : $data['endtime']);
     $daoDate->addApply(array('orgid' => $data['orgid'], 'uniqueid' => $data['uniqueid'], 'date' => $applyDate, 'categoryid' => $data['categoryid'], 'memo' => implode('|', $memo)));
     // 统计考勤类型次数等
     if (!$daoTotal->existsRecord($data['categoryid'], $data['uniqueid'], $applyMonth)) {
         $daoTotal->create(array('orgid' => $data['orgid'], 'uniqueid' => $data['uniqueid'], 'categoryid' => $data['categoryid'], 'date' => $applyMonth, 'total' => 1, 'updatetime' => time()));
     } else {
         $daoTotal->updateTotal($data['categoryid'], $data['uniqueid'], $applyMonth);
     }
     $manager = Tudu_Tudu_Manager::getInstance();
     $manager->doneTudu($tudu->tuduId, 1, 0);
 }
コード例 #15
0
ファイル: Review.php プロジェクト: bjtenao/tudu-web
 /**
  * 执行同意流程
  * @param Tudu_Model_Tudu_Entity_Tudu $tudu
  */
 protected function _agree(Tudu_Model_Tudu_Entity_Tudu $tudu)
 {
     $daoStep = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Step', Tudu_Dao_Manager::DB_TS);
     $steps = $daoStep->getSteps(array('tuduid' => $tudu->tuduId))->toArray('stepid');
     if (!isset($steps[$tudu->stepId])) {
         return false;
     }
     $step = $steps[$tudu->stepId];
     $users = $daoStep->getUsers($tudu->tuduId, $tudu->stepId);
     // 当前审批人
     $nextUser = false;
     $nextStep = true;
     $nextIndex = null;
     $currIndex = null;
     $reviewer = array();
     $tudu->sameReview = false;
     //var_dump($users);
     foreach ($users as $user) {
         if ($user['uniqueid'] == $tudu->uniqueId) {
             $currentUser = $user;
             $currIndex = $user['processindex'];
             if (empty($reviewer)) {
                 $nextUser = true;
             }
             continue;
         }
         // 还有用户在审核中,跳过流程
         if ($user['status'] == 1) {
             list($userName, $trueName) = explode(' ', $user['userinfo']);
             $reviewer[] = array('email' => $userName, 'truename' => $trueName);
             $nextStep = false;
             $nextUser = false;
             $tudu->sameReview = true;
         }
         // 转到本步骤后续执行人
         if ($nextUser) {
             if (null === $nextIndex) {
                 $nextIndex = $user['processindex'];
             }
             if (null !== $nextIndex && $user['processindex'] != $nextIndex) {
                 break;
             }
             if (null !== $currIndex && $currIndex == $user['processindex']) {
                 break;
             }
             list($userName, $trueName) = explode(' ', $user['userinfo']);
             $reviewer[] = array('email' => $userName, 'truename' => $trueName);
             $daoStep->updateUser($tudu->tuduId, $tudu->stepId, $user['uniqueid'], array('status' => 1));
             $nextStep = false;
         }
     }
     if (count($reviewer)) {
         $tudu->reviewer = array($reviewer);
     }
     // 下一步骤
     if ($nextStep) {
         if ($step['nextstepid'] == '^end') {
             $tudu->stepId = $step['nextstepid'];
             return false;
         }
         if (!isset($steps[$step['nextstepid']])) {
             return false;
         }
         $tudu->stepId = $step['nextstepid'];
         $tudu->currentStepStatus = true;
         //当前步骤是否已完结
         $updateStatus = false;
         $nextStep = $steps[$step['nextstepid']];
         $nextIndex = null;
         $nextStepUsers = $daoStep->getUsers($tudu->tuduId, $tudu->stepId);
         // 下一步仍然是审批步骤
         if ($nextStep['type'] == Dao_Td_Tudu_Step::TYPE_EXAMINE) {
             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 ($tudu->flowId && $item['status'] > 1) {
                     $updateStatus = true;
                     $daoStep->updateUser($tudu->tuduId, $nextStep['stepid'], $item['uniqueid'], array('status' => 1));
                 }
             }
             $tudu->reviewer = array($reviewer);
             // 下一步是执行
         } else {
             $users = array();
             foreach ($nextStepUsers as $item) {
                 list($email, $trueName) = explode(' ', $item['userinfo']);
                 $users[$email] = array('email' => $email, 'truename' => $trueName, 'percent' => (int) $item['percent']);
                 if ($tudu->flowId && $item['status'] > 1) {
                     $updateStatus = true;
                     $manager = Tudu_Tudu_Manager::getInstance();
                     $manager->updateProgress($tudu->tuduId, $item['uniqueid'], 0);
                     if ($tudu->parentId) {
                         $manager->calParentsProgress($tudu->parentId);
                     }
                     $daoStep->updateUser($tudu->tuduId, $nextStep['stepid'], $item['uniqueid'], array('status' => 1));
                 }
             }
             $tudu->reviewer = null;
             $tudu->to = Tudu_Tudu_Storage::formatRecipients($users);
         }
         if ($tudu->flowId && $updateStatus) {
             $daoStep->updateStep($tudu->tuduId, $nextStep['stepid'], array('status' => 0));
         }
         $tudu->stepId = $step['nextstepid'];
     }
 }
コード例 #16
0
ファイル: Tudu.php プロジェクト: bjtenao/tudu-web
 /**
  * 清除过期回复
  */
 public function cleanAutoSavePost($db)
 {
     $cleanDays = 7;
     $date = $cleanDays > 0 ? strtotime('-' . $cleanDays . ' days') : strtotime('today');
     $sql = 'SELECT post_id, tudu_id FROM td_post WHERE is_first = 0 AND is_send = 0 AND create_time < ' . $date;
     $posts = $db->fetchAll($sql);
     Tudu_Dao_Manager::setDb(Tudu_Dao_Manager::DB_TS, $db, true);
     $manager = Tudu_Tudu_Manager::getInstance();
     foreach ($posts as $post) {
         $ret = $manager->deletePost($post['tudu_id'], $post['post_id']);
         if (!$ret) {
             $this->getLogger()->warn("Notice id:({$post['post_id']}) Delete Failured");
             continue;
         }
         $this->getLogger()->info("Post id:({$post['post_id']}) Delete success");
     }
 }