예제 #1
0
 /**
  * 获取图度参数
  */
 private function _formatTuduParams(array $set, $suffix = '')
 {
     $ret = array();
     $type = !empty($set['type' . $suffix]) ? $set['type' . $suffix] : 'task';
     foreach ($this->_tuduParams as $col => $name) {
         $key = $name . $suffix;
         switch ($col) {
             case 'subject':
             case 'boardid':
             case 'classid':
             case 'flowid':
             case 'content':
             case 'parentid':
             case 'prevtuduid':
             case 'file':
             case 'attachment':
                 if (isset($set[$key])) {
                     $ret[$col] = $set[$key];
                 }
                 break;
             case 'starttime':
             case 'endtime':
                 $ret[$col] = !empty($set[$key]) ? strtotime($set[$key]) : null;
                 break;
             case 'priority':
             case 'privacy':
             case 'notifyall':
             case 'cycle':
             case 'isauth':
             case 'needconfirm':
             case 'istop':
             case 'acceptmode':
                 $ret[$col] = !empty($set[$key]) ? 1 : 0;
                 break;
             case 'password':
                 if (empty($set['privacy' . $suffix]) || empty($set['open_pwd' . $suffix])) {
                     $ret[$col] = null;
                 } else {
                     $ret[$col] = !empty($set[$key]) ? $set[$key] : null;
                 }
                 break;
             case 'to':
                 if ($type == 'task') {
                     if ($suffix) {
                         $key = 'ch-' . $key;
                     }
                     if (!empty($set[$key])) {
                         $ret[$col] = $this->_formatReviewer($set[$key]);
                     }
                     if (isset($set[$name . 'idx' . $suffix]) && is_array($set[$name . 'idx' . $suffix])) {
                         $recIdx = $set[$name . 'idx' . $suffix];
                         $rec = array();
                         foreach ($recIdx as $index) {
                             $info = $set[$name . '-' . $index . $suffix];
                             $arr = explode(' ', $info, 2);
                             $item = array('truename' => $arr[1], 'email' => $arr[0]);
                             if (isset($set[$name . '-percent-' . $index . $suffix])) {
                                 $item['percent'] = (int) $set[$name . '-percent-' . $index . $suffix];
                             }
                             if (!$item['email']) {
                                 $rec[] = $item;
                             } else {
                                 $rec[$item['email']] = $item;
                             }
                         }
                     }
                     if (!empty($rec) && !empty($ret[$col])) {
                         $recKeys = array_keys($rec);
                         foreach ($ret[$col] as &$item) {
                             foreach ($item as &$to) {
                                 if (in_array($to['email'], $recKeys) && isset($rec[$to['email']]['percent'])) {
                                     $to['percent'] = $rec[$to['email']]['percent'];
                                 }
                             }
                         }
                     }
                 } else {
                     $ret[$col] = $this->_getReceiver($set, $name, $suffix);
                 }
                 break;
             case 'cc':
             case 'bcc':
                 $ret[$col] = $this->_getReceiver($set, $name, $suffix);
                 break;
             case 'reviewer':
                 if (!empty($set[$key])) {
                     $ret[$col] = $this->_formatReviewer($set[$key]);
                 }
                 break;
         }
     }
     if (!empty($set['nd-attach' . $suffix])) {
         $ret['attachment'] = array_diff($ret['attachment'], $set['nd-attach' . $suffix]);
         $daoNdFile = $this->getDao('Dao_Td_Netdisk_File');
         $daoAttachment = $this->getDao('Dao_Td_Attachment_File');
         foreach ($set['nd-attach' . $suffix] as $ndfileId) {
             $fileId = $ndfileId;
             $attach = $daoAttachment->getFile(array('fileid' => $fileId));
             if (null !== $attach) {
                 $ret['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;
             }
             $fid = $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 ($fid) {
                 $ret['attachment'][] = $fileId;
             }
         }
     }
     if ($type == 'notice') {
         $ret['istop'] = 0;
         if (!empty($ret['endtime']) && $ret['endtime'] >= strtotime('today')) {
             $ret['istop'] = 1;
         }
     }
     // 讨论,投票
     if ($type == 'discuss' && !empty($set['vote' . $suffix])) {
         $extVote = new Tudu_Tudu_Extension_Vote();
         if (!Tudu_Tudu_Extension::isRegistered('vote')) {
             $extVote = new Tudu_Tudu_Extension_Vote();
             Tudu_Tudu_Extension::registerExtension('vote', $extVote);
         }
         $ret['vote'] = Tudu_Tudu_Extension::getExtension('vote')->formatParams($set, $suffix);
         $ret['special'] = Dao_Td_Tudu_Tudu::SPECIAL_VOTE;
     }
     // 会议
     if ($type == 'meeting') {
         if (!Tudu_Tudu_Extension::isRegistered('meeting')) {
             $extMeeting = new Tudu_Tudu_Extension_Meeting();
             Tudu_Tudu_Extension::registerExtension('meeting', $extMeeting);
         }
         $extMeeting = new Tudu_Tudu_Extension_Meeting();
         $ret['meeting'] = Tudu_Tudu_Extension::getExtension('meeting')->formatParams($set, $suffix);
     }
     // 周期
     if (($type == 'task' || $type == 'meeting') && isset($set['cycle'])) {
         if (!Tudu_Tudu_Extension::isRegistered('cycle')) {
             $extCycle = new Tudu_Tudu_Extension_Cycle();
             Tudu_Tudu_Extension::registerExtension('cycle', $extCycle);
         }
         $ret['cycle'] = Tudu_Tudu_Extension::getExtension('cycle')->formatParams($set, $suffix);
         if ($ret['cycle']['endtype'] == Dao_Td_Tudu_Cycle::END_TYPE_COUNT && $ret['cycle']['endcount'] <= 0) {
             return $this->json(false, $this->lang['invalid_endcount']);
         }
         if ($ret['cycle']['endtype'] == Dao_Td_Tudu_Cycle::END_TYPE_DATE && !$ret['cycle']['enddate']) {
             return $this->json(false, $this->lang['invalid_enddate']);
         }
         $ret['special'] = Dao_Td_Tudu_Tudu::SPECIAL_CYCLE;
         $ret['cycleid'] = $ret['cycle']['cycleid'];
     }
     $ret['type'] = $type;
     $ret['uniqueid'] = $this->_user->uniqueId;
     $ret['orgid'] = $this->_user->orgId;
     $ret['status'] = Dao_Td_Tudu_Tudu::STATUS_UNSTART;
     $ret['poster'] = $this->_user->trueName;
     $ret['email'] = $this->_user->userName;
     $ret['posterinfo'] = $this->_user->position;
     $ret['lastposter'] = $this->_user->trueName;
     $ret['issend'] = 1;
     return $ret;
 }
예제 #2
0
 /**
  * 注销所有注册扩展
  */
 public static function unRegisterAll()
 {
     foreach (self::$_extensions as $key => $obj) {
         unset(self::$_extensions[$key]);
     }
     self::$_extensions = array();
 }
예제 #3
0
 /**
  * 发送图度
  *
  * @param Tudu_Tudu_Storage_Tudu $tudu
  * @param array $recipients
  * @return boolean
  */
 public function sendTudu($tudu, $recipients, $action = Tudu_Tudu_Manager::ACTION_SEND)
 {
     //list($userId, $domainName) = explode('@', $email);
     //$recipients = $this->prepareRecipients($uniqueId, $userId, $tudu);
     /* @var $daoTudu Dao_Td_Tudu_Tudu */
     $daoTudu = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Tudu', Tudu_Dao_Manager::DB_TS);
     // 移除原有审批
     if (!$tudu->isDraft && !$tudu->flowId) {
         $reviewers = $daoTudu->getUsers($tudu->tuduId, array('labelid' => '^e'));
         foreach ($reviewers as $reviewer) {
             $daoTudu->deleteLabel($tudu->tuduId, $reviewer['uniqueid'], '^e');
         }
     }
     $to = array();
     foreach ($recipients as $unId => $recipient) {
         if (!isset($recipient['accepterinfo']) && isset($recipient['email']) && isset($recipient['truename'])) {
             $recipient['accepterinfo'] = $recipient['email'] . ' ' . $recipient['truename'];
         }
         $params = $recipient;
         if (array_key_exists('percent', $params) || !empty($params['role']) && $params['role'] == 'to') {
             $params['percent'] = isset($params['percent']) ? (int) $params['percent'] : 0;
         }
         $labels = $daoTudu->addUser($tudu->tuduId, $recipient['uniqueid'], $params);
         if (false !== $labels) {
             if (is_string($labels) && !empty($recipient)) {
                 $daoTudu->updateTuduUser($tudu->tuduId, $recipient['uniqueid'], $recipient);
             }
             if (!empty($recipient['role']) && $recipient['role'] === 'to') {
                 $to[] = $unId;
             }
             if (is_string($labels)) {
                 $labels = explode(',', $labels);
             } else {
                 $labels = array();
             }
             // 所有图度标签
             if (!in_array('^all', $labels)) {
                 $daoTudu->addLabel($tudu->tuduId, $recipient['uniqueid'], '^all');
             }
             // 图度箱
             if (!in_array('^i', $labels) && !in_array('^g', $labels)) {
                 $daoTudu->addLabel($tudu->tuduId, $recipient['uniqueid'], '^i');
             }
             // 相关
             if (empty($recipient['role']) || $tudu->uniqueId != $recipient['uniqueid']) {
                 $daoTudu->addLabel($tudu->tuduId, $recipient['uniqueid'], '^c');
             } else {
                 if ($tudu->type == 'task' && in_array('^c', $labels)) {
                     $daoTudu->deleteLabel($tudu->tuduId, $recipient['uniqueid'], '^c');
                 }
             }
             // 待办
             if (!empty($recipient['role']) && empty($recipient['accepttime']) || $tudu->uqnieuId == $recipient['uniqueid'] && !$tudu->acceptTime) {
                 $daoTudu->addLabel($tudu->tuduId, $recipient['uniqueid'], '^td');
             }
             // 我执行
             if (!empty($recipient['role']) && $recipient['role'] === 'to' && !in_array('^a', $labels) && $tudu->type == 'task') {
                 $daoTudu->addLabel($tudu->tuduId, $recipient['uniqueid'], '^a');
             }
             // 已发送
             if ($tudu->uniqueId == $recipient['uniqueid'] && !in_array('^f', $labels)) {
                 $daoTudu->addLabel($tudu->tuduId, $recipient['uniqueid'], '^f');
             }
             // 审批
             if (!empty($recipient['isreview']) && !in_array('^e', $labels)) {
                 $daoTudu->addLabel($tudu->tuduId, $recipient['uniqueid'], '^e');
             }
             if (isset($this->_typeLabels[$tudu->type])) {
                 $labelId = $this->_typeLabels[$tudu->type];
                 if (!in_array($labelId, $labels)) {
                     $daoTudu->addLabel($tudu->tuduId, $recipient['uniqueid'], $labelId);
                 }
             }
         }
     }
     $ret = $daoTudu->sendTudu($tudu->tuduId);
     $extensions = Tudu_Tudu_Extension::getRegisteredExtensions();
     foreach ($extensions as $key) {
         Tudu_Tudu_Extension::getExtension($key)->onSend($tudu);
     }
     return $ret;
 }
예제 #4
0
 /**
  * 审批图度(同意/不同意)
  *
  * @param $tudu
  */
 public function reviewTudu(Tudu_Tudu_Storage_Tudu $tudu, $isAgree)
 {
     $extensions = Tudu_Tudu_Extension::getRegisteredExtensions();
     foreach ($extensions as $key) {
         Tudu_Tudu_Extension::getExtension($key)->onReview($tudu, $isAgree);
     }
     $attrs = $tudu->getAttributes();
     /* @var $tuduDao Dao_Td_Tudu_Tudu */
     $daoTudu = $this->getDao('Dao_Td_Tudu_Tudu');
     $params['to'] = isset($attrs['to']) ? self::formatReceiver($attrs['to']) : null;
     $params['cc'] = isset($attrs['cc']) ? self::formatReceiver($attrs['cc']) : null;
     $params['stepid'] = $attrs['stepid'];
     $ret = $daoTudu->updateTudu($tudu->tuduId, $params);
     if (!$ret) {
         return false;
     }
     $header = array('action' => 'review', 'tudu-act-value' => $isAgree ? 1 : 0);
     $headerKey = $tudu->reviewer ? 'tudu-reviewer' : 'tudu-to';
     $items = $tudu->reviewer ? $tudu->reviewer : $tudu->to;
     $val = array();
     if ($tudu->reviewer) {
         $items = $tudu->reviewer;
         $items = array_shift($items);
     } else {
         $items = $tudu->to;
     }
     foreach ($items as $item) {
         if (!empty($attrs['samereview'])) {
             break;
         }
         $val[] = $item['truename'];
     }
     if (!empty($val)) {
         $header[$headerKey] = implode(',', $val);
     }
     if ($tudu->type == 'notice' && empty($val)) {
         unset($header[$headerKey]);
     }
     $postParams = array('orgid' => $tudu->orgId, 'boardid' => $tudu->boardId, 'tuduid' => $tudu->tuduId, 'header' => $header, 'content' => isset($attrs['content']) ? $attrs['content'] : '', 'poster' => $tudu->poster, 'postinfo' => $tudu->posterInfo, 'email' => $attrs['email'], 'uniqueid' => $tudu->uniqueId, 'attachment' => !empty($attrs['attachment']) ? (array) $attrs['attachment'] : array(), 'file' => !empty($attrs['file']) ? (array) $attrs['file'] : array());
     $postId = $this->createPost($postParams);
     $this->sendPost($tudu->tuduId, $postId);
     return true;
 }