Пример #1
0
 /**
  * 发送操作
  */
 public function sendAction()
 {
     $post = $this->_request->getPost();
     $action = self::ACTION_SEND;
     $time = time();
     if (!empty($post['action']) && $post['action'] == 'save') {
         $action = self::ACTION_SAVE;
     }
     if (!empty($post['forward'])) {
         $action = self::ACTION_FORWARD;
     } elseif (!empty($post['divide'])) {
         $action = self::ACTION_DIVIDE;
     } elseif (!empty($post['review'])) {
         $action = self::ACTION_REVIEW;
     } elseif (!empty($post['apply'])) {
         $action = self::ACTION_APPLY;
     } elseif (!empty($post['invite'])) {
         $action = self::ACTION_INVITE;
     }
     /**
      * @see Model_Tudu_Tudu
      */
     require_once 'Model/Tudu/Tudu.php';
     $tudu = new Model_Tudu_Tudu();
     $this->_formatParams($tudu, $post);
     $tudu->setAttributes(array('orgid' => $this->_user->orgId, 'uniqueid' => $this->_user->uniqueId, 'email' => $this->_user->userName, 'from' => $this->_user->userName . ' ' . $this->_user->trueName, 'poster' => $this->_user->trueName, 'createtime' => $time, 'lastupdatetime' => $time, 'operation' => $action));
     // 发送对象
     $config = $this->bootstrap->getOption('httpsqs');
     $tuduconf = $this->bootstrap->getOption('tudu');
     $sendType = isset($tuduconf['send']) ? ucfirst($tuduconf['send']['class']) : 'Common';
     $sendClass = 'Model_Tudu_Send_' . $sendType;
     if (!empty($tuduconf['send']['params'])) {
         $params = $tuduconf['send']['params'];
     } elseif ($sendType == 'Common') {
         $params = array('httpsqs' => $config);
     }
     $modelSend = new $sendClass($params);
     $className = 'Model_Tudu_Compose_' . ucfirst($action);
     $model = new $className();
     // 添加图度工作流相关流程
     if ($tudu->type == 'task' || $tudu->type == 'notice' || in_array($action, array(self::ACTION_REVIEW, self::ACTION_FORWARD))) {
         $tudu->setExtension(new Model_Tudu_Extension_Flow());
     }
     // 周期任务
     if (in_array($action, array(self::ACTION_SAVE, self::ACTION_SEND)) && ($tudu->type == 'task' || $tudu->type == 'meeting')) {
         if ($tudu->cycle) {
             $tudu->setExtension(new Model_Tudu_Extension_Cycle($this->_getCycleParams($post)));
         }
     }
     // 处理投票
     if ($tudu->type == 'discuss' && !empty($post['vote'])) {
         $this->_prepareVoteParams($tudu, $post);
     }
     // 图度组支持
     if ($tudu->type == 'task' && !empty($post['chidx']) || $action == self::ACTION_DIVIDE && !empty($post['chidx'])) {
         $group = new Model_Tudu_Extension_Group();
         foreach ($post['chidx'] as $suffix) {
             $suffix = '-' . $suffix;
             $child = new Model_Tudu_Tudu();
             $this->_formatParams($child, $post, $suffix);
             $child->setExtension(new Model_Tudu_Extension_Flow());
             if ($child->cycle) {
                 $child->setExtension(new Model_Tudu_Extension_Cycle($this->_getCycleParams($post, $suffix)));
             }
             $group->appendChild($child);
         }
         Model_Tudu_Extension_Handler_Group::setSendModel($modelSend);
         $tudu->setExtension($group);
     }
     // 处理会议
     if ($tudu->type == 'meeting' && $action != self::ACTION_INVITE) {
         $meeting = new Model_Tudu_Extension_Meeting(array('orgid' => $this->_user->orgId, 'notifytime' => $this->_request->getPost('notifytime'), 'notifytype' => $this->_request->getPost('notifytype'), 'location' => $this->_request->getPost('location'), 'isallday' => $this->_request->getPost('isallday')));
         $tudu->setExtension($meeting);
     }
     $params = array(&$tudu);
     try {
         $model->execute('compose', $params);
         // 保存后添加发送操作
         if ($action != self::ACTION_SAVE) {
             $modelSend->send($tudu);
         }
         // 考勤流程
         if ($action == self::ACTION_REVIEW && $tudu->fromTudu->appId == 'attend') {
             $flow = $tudu->getExtension('Model_Tudu_Extension_Flow');
             if ($flow->currentStepId == '^end' || $flow->currentStepId == '^break') {
                 $tudu->stepId = $flow->currentStepId;
                 $mtudu = new Tudu_Model_Tudu_Entity_Tudu($tudu->getAttributes());
                 Tudu_Dao_Manager::setDbs(array(Tudu_Dao_Manager::DB_APP => $this->multidb->getDb('app')));
                 $daoApply = Tudu_Dao_Manager::getDao('Dao_App_Attend_Apply', Tudu_Dao_Manager::DB_APP);
                 $apply = $daoApply->getApply(array('tuduid' => $tudu->tuduId));
                 if (null !== $apply) {
                     $mapply = new Tudu_Model_App_Attend_Tudu_Apply($apply->toArray());
                     $model = new Tudu_Model_App_Attend_Tudu_Extension_Apply();
                     $model->onReview($mtudu, $mapply);
                 }
             }
         }
         // 捕获流程异常返回错误信息
     } catch (Model_Tudu_Exception $e) {
         $error = null;
         switch ($e->getCode()) {
             case Model_Tudu_Exception::TUDU_NOTEXISTS:
                 // 图度不存在
                 $error = $this->lang['tudu_not_exists'];
                 break;
             case Model_Tudu_Exception::BOARD_NOTEXISTS:
                 $error = $this->lang['board_not_exists_or_deny'];
                 break;
             case Model_Tudu_Exception::FLOW_USER_NOT_EXISTS:
                 $error = $this->lang['missing_flow_steps_receiver'];
                 break;
             case Model_Tudu_Exception::FLOW_NOT_EXISTS:
                 $error = $this->lang['missing_flow_steps'];
                 break;
             case Model_Tudu_Exception::INVALID_USER:
             case Model_Tudu_Exception::PERMISSION_DENIED:
                 $error = $this->lang['permission_denied_for_tudu'];
                 break;
             default:
                 $error = $action !== self::ACTION_SAVE ? $this->lang['send_failure'] : $this->lang['save_failure'];
                 if ($action == self::ACTION_REVIEW) {
                     $error = $this->lang['review_failure'];
                 }
                 break;
         }
         $this->json(false, $error);
     }
     $returnData = array('tuduid' => $tudu->tuduId);
     // 返回图度组
     if (null !== ($group = $tudu->getExtension('Model_Tudu_Extension_Group'))) {
         $returnData['children'] = array();
         $children = $group->getChildren();
         foreach ($children as $item) {
             $returnData['children'][] = $item->tuduId;
         }
     }
     $message = $action !== self::ACTION_SAVE ? $this->lang['send_success'] : $this->lang['save_success'];
     $this->json(true, $message, $returnData);
 }
Пример #2
0
 /**
  * 审批
  */
 public function reviewAction()
 {
     $post = $this->_request->getParams();
     require_once 'Model/Tudu/Tudu.php';
     $tudu = new Model_Tudu_Tudu();
     $this->_formatParams($tudu, $post);
     $tudu->setAttributes(array('orgid' => $this->_user->orgId, 'uniqueid' => $this->_user->uniqueId, 'poster' => $this->_user->trueName, 'isagree' => $this->_request->getParam('agree', true), 'operation' => 'review'));
     try {
         /* @var $modelCompose Model_Tudu_Compose_Forward */
         $modelCompose = Tudu_Model::factory('Model_Tudu_Compose_Review');
         $params = array(&$tudu);
         $modelCompose->execute('compose', $params);
         // 考勤流程
         if ($tudu->fromTudu->appId == 'attend' && $tudu->stepId == '^end') {
             $mtudu = new Tudu_Model_Tudu_Entity_Tudu($tudu->getAttributes());
             Tudu_Dao_Manager::setDbs(array(Tudu_Dao_Manager::DB_APP => $this->_bootstrap->multidb->getDb('app')));
             $daoApply = Tudu_Dao_Manager::getDao('Dao_App_Attend_Apply', Tudu_Dao_Manager::DB_APP);
             $apply = $daoApply->getApply(array('tuduid' => $tudu->tuduId));
             if (null !== $apply) {
                 $mapply = new Tudu_Model_App_Attend_Tudu_Apply($apply->toArray());
                 $model = new Tudu_Model_App_Attend_Tudu_Extension_Apply();
                 $model->onReview($mtudu, $mapply);
             }
         }
         $config = $this->_bootstrap->getOption('httpsqs');
         $tuduconf = $this->_bootstrap->getOption('tudu');
         $sendType = isset($tuduconf['send']) ? ucfirst($tuduconf['send']['class']) : 'Common';
         $sendClass = 'Model_Tudu_Send_' . $sendType;
         $modelSend = new $sendClass(array('httpsqs' => $config));
         $modelSend->send(&$tudu);
         /*$config  = $this->_bootstrap->getOption('httpsqs');
                     $httpsqs = new Oray_Httpsqs($config['host'], $config['port'], $config['chartset'], $config['name']);
         
                     $action = 'review';
                     $sqsParam = array(
                         'tsid'        => $this->_user->tsId,
                         'tuduid'      => $tudu->tuduId,
                         'from'        => $this->_user->userName,
                         'uniqueid'    => $this->_user->uniqueId,
                         'server'      => $this->_request->getServer('HTTP_HOST'),
                         'type'        => $tudu->type,
                         'stepid'      => $tudu->fromTudu->stepId,
                         'stepstatus'  => $tudu->stepId  && $tudu->fromTudu->stepId != $tudu->stepId && 0 !== strpos($tudu->stepId, '^'),
                         'nstepid'     => $tudu->stepId,
                         'flowid'      => $tudu->flowId,
                         'agree'       => $this->_request->getParam('agree', true),
                         'ischangedCc' => ($action == 'update' && $tudu->cc) ? (boolean) $tudu->cc : false
                     );
         
                     $httpsqs->put(implode(' ', array(
                         'tudu',
                         $action,
                         '',
                         http_build_query($sqsParam)
                     )), 'tudu');*/
     } catch (Model_Tudu_Exception $e) {
         throw new TuduX_OpenApi_Exception('Tudu review failed', TuduX_OpenApi_ResponseCode::TUDU_SEND_FAILED);
     }
     $this->view->tuduid = $tudu->tuduId;
     $this->view->code = TuduX_OpenApi_ResponseCode::SUCCESS;
 }