コード例 #1
0
ファイル: Flow.php プロジェクト: bjtenao/tudu-web
 /**
  * 更新图度后续步骤
  *
  * @param $tudu
  */
 public function updateTuduSteps(Tudu_Tudu_Storage_Tudu &$tudu, $cancelCurrent = true)
 {
     // 草稿
     if ($tudu->isDraft() || $tudu->stepId == self::NODE_HEAD || $tudu->stepId == self::NODE_BREAK) {
         $this->deleteAllSteps($tudu->tuduId);
         if ($tudu->flowId) {
             $this->onPrepareFlow($tudu);
             if ($tudu->isChange('to')) {
                 $manager = Tudu_Tudu_Manager::getInstance();
                 $to = $tudu->getAttribute('to');
                 $to = isset($to) ? Tudu_Tudu_Storage::formatReceiver($to) : null;
                 $manager->updateTudu($tudu->tuduId, array('to' => $to));
             }
             return $this->createFlowSteps($tudu);
         } else {
             return $this->createTuduSteps($tudu);
         }
     }
     if ($tudu->flowId) {
         return true;
         //return $this->updateFlowSteps($tudu);
     }
     $steps = $this->getSteps($tudu->tuduId)->toArray('stepid');
     if ($tudu->stepId && false === strpos($tudu->stepId, '^')) {
         $currentStep = $steps[$tudu->stepId];
     } else {
         foreach ($steps as $step) {
             if ($step['stepstatus'] != 4) {
                 $currentStep = $step;
                 break;
             }
         }
     }
     //$currentStep = $tudu->stepId && false === strpos($tudu->stepId, '^') ? $steps[$tudu->stepId] : array_pop($steps);
     // 当前为审批步骤
     $stepNum = count($steps);
     $newSteps = array();
     $updatePrevStepId = null;
     if (isset($currentStep) && $currentStep['type'] == Dao_Td_Tudu_Step::TYPE_EXAMINE) {
         $nextStepId = $currentStep['stepid'];
         $execStepId = Dao_Td_Tudu_Step::getStepId();
         if ($tudu->reviewer) {
             $reviewers = $tudu->reviewer;
             $users = array();
             $processIndex = 1;
             foreach ($reviewers as $item) {
                 foreach ($item as $reviewer) {
                     $users[] = array('email' => $reviewer['email'], 'truename' => $reviewer['truename'], 'processindex' => $processIndex, 'stepstatus' => $processIndex == 1 ? 1 : 0);
                 }
                 $processIndex++;
             }
             // 更新审批步骤审批人
             $this->updateStepUsers($tudu, $currentStep['stepid'], $users);
             $updatePrevStepId = $prevStepId = $currentStep['stepid'];
             $tudu->stepId = $currentStep['stepid'];
         } else {
             // 审批步骤作废
             //$this->cancelStep($tudu, $currentStep['stepid']);
             $this->updateStepUsers($tudu, $currentStep['stepid'], array());
             $updatePrevStepId = $prevStepId = $currentStep['prevstepid'];
             $tudu->stepId = $execStepId;
         }
         if ($tudu->type != 'notice') {
             $updateNextStepId = $stepId = $execStepId;
             if ($tudu->stepto) {
                 $countTo = count($tudu->stepto);
                 $i = 0;
                 $orderNum = $currentStep['ordernum'];
                 foreach ($tudu->stepto as $item) {
                     $i++;
                     $users = array();
                     foreach ($item as $to) {
                         $users[] = array('email' => $to['email'], 'truename' => $to['truename']);
                     }
                     $nextStepId = Dao_Td_Tudu_Step::getStepId();
                     $newSteps[] = array('orgid' => $tudu->orgId, 'tuduid' => $tudu->tuduId, 'uniqueid' => $tudu->uniqueId, 'stepid' => $stepId, 'type' => $tudu->acceptMode ? Dao_Td_Tudu_Step::TYPE_CLAIM : Dao_Td_Tudu_Step::TYPE_EXECUTE, 'prevstepid' => $prevStepId, 'nextstepid' => $countTo == $i ? self::NODE_END : $nextStepId, 'users' => $users, 'ordernum' => ++$orderNum, 'createtime' => time());
                     $prevStepId = $stepId;
                     $stepId = $nextStepId;
                 }
             }
             $nextStepId = $stepId;
         } else {
             $updateNextStepId = $nextStepId = self::NODE_END;
         }
         // 其他
     } else {
         $isChangeTo = false;
         // 比较图度执行人
         $stepUsers = $this->getTuduStepUsers($tudu->tuduId);
         $stepTo = array();
         //修改前的步骤执行人
         $stepSize = 0;
         //修改前的步骤个数
         $tempStepId = null;
         foreach ($stepUsers as &$u) {
             if ($tudu->stepId == $u['stepid'] && $u['type'] == Dao_Td_Tudu_Step::TYPE_EXECUTE && $u['stepstatus'] != 4) {
                 if ($tempStepId != $u['stepid']) {
                     $stepSize++;
                 }
                 $tempStepId = $u['stepid'];
                 $info = explode(' ', $u['userinfo']);
                 $u['email'] = $info[0];
                 $u['truename'] = $info[1];
                 $stepTo[$u['email']] = $u;
             }
         }
         $currentTo = array();
         //当前修改后的执行人
         $currentStepSize = 0;
         //当前修改后步骤个数
         foreach ($tudu->stepto as $item) {
             foreach ($item as $to) {
                 $currentTo[$to['email']] = $to;
             }
             $currentStepSize++;
         }
         $src = array_keys($stepTo);
         $cur = array_keys($currentTo);
         $srcCount = count($src);
         $isChangeTo = $stepSize != $currentStepSize || count($cur) != $srcCount || count(array_uintersect($src, $cur, "strcasecmp")) != $srcCount;
         // 步骤作废
         if ($isChangeTo || $tudu->isChange('acceptmode')) {
             if ($cancelCurrent) {
                 $this->updateStep($tudu->tuduId, $currentStep['stepid'], array('status' => 4));
                 $updatePrevStepId = $prevStepId = $currentStep['prevstepid'];
             } else {
                 $updatePrevStepId = $prevStepId = $currentStep['stepid'];
             }
         } else {
             $updatePrevStepId = $prevStepId = $currentStep['stepid'];
             $tudu->stepId = $prevStepId;
         }
         $updateNextStepId = $nextStepId = null;
         $prevId = $prevStepId;
         $orderNum = $currentStep['ordernum'];
         if ($tudu->reviewer) {
             // 前一步骤作废
             if ($cancelCurrent) {
                 $this->updateStep($tudu->tuduId, $prevId, array('status' => 4));
             }
             $reviewers = $tudu->reviewer;
             $users = array();
             $processIndex = 1;
             foreach ($reviewers as $item) {
                 foreach ($item as $reviewer) {
                     $users[] = array('email' => $reviewer['email'], 'truename' => $reviewer['truename'], 'processindex' => $processIndex);
                 }
                 $processIndex++;
             }
             $stepId = Dao_Td_Tudu_Step::getStepId();
             /*插入修改人
                             $nextStepId = Dao_Td_Tudu_Step::getStepId();
             
                             $newSteps[$stepId] = array(
                                 'orgid'  => $tudu->orgId,
                                 'tuduid'     => $tudu->tuduId,
                                 'stepid'     => $stepId,
                                 'uniqueid'   => $tudu->uniqueId,
                                 'prevstepid' => $prevId,
                                 'nextstepid' => $nextStepId,
                                 'type'       => Dao_Td_Tudu_Step::TYPE_EXECUTE,
                                 'ordernum'   => ++$orderNum,
                                 'createtime' => time(),
                                 'users'      => array(0 => array('email' => $tudu->email, 'truename' => $tudu->poster))
                             );
             
                             $prevId = $stepId;
                             $stepId = $nextStepId;
             */
             $newSteps[$stepId] = array('orgid' => $tudu->orgId, 'tuduid' => $tudu->tuduId, 'stepid' => $stepId, 'uniqueid' => $tudu->uniqueId, 'prevstepid' => $prevId, 'nextstepid' => '^end', 'type' => Dao_Td_Tudu_Step::TYPE_EXAMINE, 'ordernum' => ++$orderNum, 'createtime' => time(), 'users' => $users);
             $prevId = $stepId;
             if (!$nextStepId) {
                 $updateNextStepId = $nextStepId = $stepId;
             }
         }
         if ($isChangeTo || count($newSteps) || $tudu->isChange('acceptmode')) {
             $stepId = Dao_Td_Tudu_Step::getStepId();
             if (!$nextStepId) {
                 $updateNextStepId = $nextStepId = $stepId;
             }
             if (isset($newSteps[$prevId])) {
                 $newSteps[$prevId]['nextstepid'] = $stepId;
             }
             // 转发
             if ($tudu->action == 'forward') {
                 $newSteps[$stepId] = array('orgid' => $tudu->orgId, 'tuduid' => $tudu->tuduId, 'stepid' => $stepId, 'uniqueid' => $tudu->uniqueId, 'prevstepid' => $prevId, 'nextstepid' => '^end', 'type' => $tudu->acceptMode ? Dao_Td_Tudu_Step::TYPE_CLAIM : Dao_Td_Tudu_Step::TYPE_EXECUTE, 'ordernum' => ++$orderNum, 'createtime' => time(), 'users' => $tudu->to);
             } else {
                 // 修改
                 if ($tudu->stepto) {
                     $countTo = count($tudu->stepto);
                     $i = 0;
                     foreach ($tudu->stepto as $item) {
                         $i++;
                         $users = array();
                         foreach ($item as $to) {
                             $users[] = array('email' => $to['email'], 'truename' => $to['truename']);
                         }
                         $nextId = Dao_Td_Tudu_Step::getStepId();
                         $newSteps[$stepId] = array('orgid' => $tudu->orgId, 'tuduid' => $tudu->tuduId, 'uniqueid' => $tudu->uniqueId, 'stepid' => $stepId, 'type' => $tudu->acceptMode ? Dao_Td_Tudu_Step::TYPE_CLAIM : Dao_Td_Tudu_Step::TYPE_EXECUTE, 'prevstepid' => $prevId, 'nextstepid' => $countTo == $i ? self::NODE_END : $nextId, 'users' => $users, 'ordernum' => ++$orderNum, 'createtime' => time());
                         $prevId = $stepId;
                         $stepId = $nextId;
                     }
                 }
             }
         }
         if ($nextStepId) {
             $tudu->stepId = $updateNextStepId;
         }
     }
     if (!empty($newSteps)) {
         // 移除后随未开始执行的步骤
         foreach ($steps as $step) {
             if ($step['ordernum'] > $currentStep['ordernum']) {
                 $this->deleteStep($tudu->tuduId, $step['stepid']);
                 $stepNum--;
             }
         }
         foreach ($newSteps as $step) {
             if ($this->createStep($step)) {
                 $recipients = $this->prepareRecipients($tudu->orgId, $tudu->uniqueId, $step['users']);
                 $processIndex = $step['type'] == Dao_Td_Tudu_Step::TYPE_EXAMINE ? 0 : null;
                 $this->addStepUsers($tudu->tuduId, $step['stepid'], $recipients, $processIndex);
                 $stepNum++;
             }
         }
         $this->updateStep($tudu->tuduId, $updatePrevStepId, array('nextstepid' => $updateNextStepId));
     }
     $tudu->stepNum = $stepNum;
     /*return $this->getDao('Dao_Td_Tudu_Tudu')->updateTudu($tudu->tuduId,
           array(
               'stepid'  => $tudu->stepId,
               'stepnum' => $stepNum
           )
       );*/
 }
コード例 #2
0
ファイル: Storage.php プロジェクト: bjtenao/tudu-web
 /**
  * 申请审批
  *
  * @param $tudu
  */
 public function applyTudu(Tudu_Tudu_Storage_Tudu $tudu)
 {
     $attrs = $tudu->getAttributes();
     $params = array();
     if (isset($attrs['endtime'])) {
         $params['endtime'] = $attrs['endtime'];
     }
     if (!empty($attrs['cc'])) {
         $params['cc'] = $attrs['cc'];
     }
     $names = array();
     $count = 0;
     foreach ($attrs['reviewer'] as $k => $item) {
         if ($count >= 3) {
             $names[] = '...';
             break;
         }
         $names[] = $item['truename'];
     }
     /* @var $tuduDao Dao_Td_Tudu_Tudu */
     $daoTudu = $this->getDao('Dao_Td_Tudu_Tudu');
     if (!empty($params)) {
         $ret = $daoTudu->updateTudu($tudu->tuduId, $params);
         if (!$ret) {
             return false;
         }
     }
     $header = array('action' => 'apply', 'tudu-reviewer' => implode(',', $names));
     $postParams = array('orgid' => $tudu->orgId, 'boardid' => $tudu->boardId, 'tuduid' => $tudu->tuduId, 'header' => $header, 'content' => $attrs['content'], 'email' => $attrs['email'], 'poster' => $tudu->poster, 'postinfo' => $tudu->posterInfo, '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);
     $extensions = Tudu_Tudu_Extension::getRegisteredExtensions();
     foreach ($extensions as $key) {
         Tudu_Tudu_Extension::getExtension($key)->onApply($tudu);
     }
     return true;
 }