Esempio n. 1
0
 /**
  *
  * @param Model_Tudu_Tudu $tudu
  */
 public function saveGroup(Model_Tudu_Tudu &$tudu)
 {
     $group = $tudu->getExtension('Model_Tudu_Extension_Group');
     if (null == $group) {
         return;
     }
     $children = $group->getChildren();
     foreach ($children as $child) {
     }
 }
Esempio n. 2
0
 /**
  *
  * @param Model_Tudu_Tudu $tudu
  */
 public function saveTuduCycle(Model_Tudu_Tudu &$tudu)
 {
     $cycle = $tudu->getExtension('Model_Tudu_Extension_Cycle');
     /* @var $daoCycle Dao_Td_Tudu_Cycle */
     $daoCycle = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Cycle', Tudu_Dao_Manager::DB_TS);
     $params = $cycle->getAttributes();
     if (null !== $daoCycle->getCycle(array('cycleid' => $cycle->cycleId))) {
         $daoCycle->updateCycle($cycle->cycleId, $params);
     } else {
         $daoCycle->createCycle($params);
     }
 }
Esempio n. 3
0
 /**
  *
  * @param Model_Tudu_Tudu $tudu
  */
 public function action(Model_Tudu_Tudu &$tudu)
 {
     $remind = $tudu->getExtension('Model_Tudu_Extension_Remind');
     $params = $remind->getAttributes();
     /* @var $daoRemind Dao_Td_Tudu_Remind */
     $daoRemind = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Remind', Tudu_Dao_Manager::DB_TS);
     if ($params['action'] == 'update') {
         if (empty($params)) {
             $params['isvalid'] = 0;
         }
         $daoRemind->updateRemind($tudu->tuduId, $params);
     } else {
         if ($params['isvalid']) {
             $params['tuduid'] = $tudu->tuduId;
             $daoRemind->createRemind($params);
         }
     }
 }
Esempio n. 4
0
 /**
  *
  * @param Model_Tudu_Tudu $tudu
  */
 public function action(Model_Tudu_Tudu &$tudu)
 {
     $meeting = $tudu->getExtension('Model_Tudu_Extension_Meeting');
     /* @var $daoMeeting Dao_Td_Tudu_Meeting */
     $daoMeeting = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Meeting', Tudu_Dao_Manager::DB_TS);
     $params = $meeting->getAttributes();
     if ($params['notifytype']) {
         $params['notifytime'] = Dao_Td_Tudu_Meeting::calNotifyTime(strtotime($tudu->starttime), $params['notifytype']);
     } else {
         $params['notifytime'] = null;
     }
     if ($daoMeeting->existsMeeting($tudu->tuduId)) {
         $daoMeeting->updateMeeting($tudu->tuduId, $params);
     } else {
         $params['tuduid'] = $tudu->tuduId;
         $daoMeeting->createMeeting($params);
     }
 }
Esempio n. 5
0
 /**
  *
  * @param Model_Tudu_Tudu $tudu
  */
 public function filter(Model_Tudu_Tudu &$tudu)
 {
     $cycle = $tudu->getExtension('Model_Tudu_Extension_Cycle');
     if (null !== $cycle) {
         $tudu->cycleId = $cycle->cycleId;
         $tudu->special = 1;
     }
     /* @var $daoCycle Dao_Td_Tudu_Cycle */
     $daoCycle = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Cycle', Tudu_Dao_Manager::DB_TS);
     $params = $cycle->getAttributes();
     if (null !== $daoCycle->getCycle(array('cycleid' => $cycle->cycleId))) {
         $ret = $daoCycle->updateCycle($cycle->cycleId, $params);
     } else {
         $ret = $daoCycle->createCycle($params);
     }
     if (!$ret) {
         $tudu->cycleId = null;
         $tudu->special = 0;
     }
 }
Esempio n. 6
0
 /**
  * (non-PHPdoc)
  * @see Model_Tudu_Compose_Abstract::compose()
  */
 public function compose(Model_Tudu_Tudu &$tudu)
 {
     /* @var $daoTudu Dao_Td_Tudu_Tudu */
     $daoTudu = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Tudu', Tudu_Dao_Manager::DB_TS);
     $attrs = $tudu->getStorageParams();
     $params = array('to' => $attrs['to']);
     if (!empty($attrs['cc'])) {
         $params['cc'] = $attrs['cc'];
     }
     if (!empty($attrs['bcc'])) {
         $params['bcc'] = $attrs['bcc'];
     }
     if (!$daoTudu->updateTudu($tudu->tuduId, $params)) {
         require_once 'Model/Tudu/Exception.php';
         throw new Model_Tudu_Exception('Tudu save failed', Model_Tudu_Exception::SAVE_FAILED);
     }
     /* @var $daoPost Dao_Td_Tudu_Post */
     $daoPost = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Post', Tudu_Dao_Manager::DB_TS);
     /* @var $daoFile Dao_Td_Attachment_File */
     $daoFile = Tudu_Dao_Manager::getDao('Dao_Td_Attachment_File', Tudu_Dao_Manager::DB_TS);
     $toArr = array();
     foreach ($tudu->to as $sec) {
         foreach ($sec as $item) {
             $toArr[] = array('username' => $item['username'], 'truename' => $item['truename']);
         }
         break;
     }
     $header = array('action' => 'forward', 'to' => $toArr);
     if ($tudu->reviewer) {
         $header['reviewer'] = array();
         foreach ($tudu->reviewer as $sec) {
             foreach ($sec as $item) {
                 $header['reviewer'][] = array('username' => $item['username'], 'truename' => $item['truename']);
             }
         }
     }
     $postParams = array('orgid' => $tudu->orgId, 'tuduid' => $tudu->tuduId, 'boardid' => $tudu->boardId, 'postid' => Dao_Td_Tudu_Post::getPostId($tudu->tuduId), 'uniqueid' => $this->_user->uniqueId, 'poster' => $this->_user->trueName, 'email' => $this->_user->userName, 'content' => $tudu->content, 'createtime' => time(), 'header' => $header);
     $postId = $daoPost->createPost($postParams);
     $daoPost->sendPost($tudu->tuduId, $postId);
     $attachments = $tudu->getAttachments();
     foreach ($attachments as $id => $attach) {
         $daoFile->addPost($tudu->tuduId, $postId, $attach['attachid'], $attach['isattachment']);
     }
     $this->_tuduLog('forward', $tudu);
 }
Esempio n. 7
0
 /**
  * (non-PHPdoc)
  * @see Model_Tudu_Compose_Abstract::compose()
  */
 public function compose(Model_Tudu_Tudu &$tudu)
 {
     /* @var $daoTudu Dao_Td_Tudu_Tudu */
     $daoTudu = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Tudu', Tudu_Dao_Manager::DB_TS);
     $attrs = $tudu->getStorageParams();
     $params = array();
     if (!empty($attrs['to'])) {
         $params['to'] = $attrs['to'];
     }
     if (!empty($attrs['cc'])) {
         $params['cc'] = $attrs['cc'];
     }
     if (isset($attrs['acceptmode'])) {
         $params['acceptmode'] = $attrs['acceptmode'];
     }
     if (!empty($params)) {
         if (!$daoTudu->updateTudu($tudu->tuduId, $params)) {
             require_once '/Model/Tudu/Exception.php';
             throw new Model_Tudu_Exception('Review failed', Model_Tudu_Exception::SAVE_FAILED);
         }
     }
     // 发送回复
     /* @var $daoPost Dao_Td_Tudu_Post */
     $daoPost = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Post', Tudu_Dao_Manager::DB_TS);
     /* @var $daoFile Dao_Td_Attachment_File */
     $daoFile = Tudu_Dao_Manager::getDao('Dao_Td_Attachment_File', Tudu_Dao_Manager::DB_TS);
     $header = array('action' => 'review', 'tudu-act-value' => $tudu->agree ? 1 : 0);
     if ($this->_fromTudu->type != 'notice') {
         $headerKey = $tudu->reviewer ? 'tudu-reviewer' : 'tudu-to';
         $items = $tudu->reviewer ? $tudu->reviewer : $tudu->to;
         if ($items) {
             $val = array();
             foreach ($items as $item) {
                 $val[] = $item['truename'];
             }
             $header[$headerKey] = implode(',', $val);
         }
     }
     $postParams = array('orgid' => $this->_fromTudu->orgId, 'tuduid' => $this->_fromTudu->tuduId, 'boardid' => $this->_fromTudu->boardId, 'uniqueid' => $this->_user->uniqueId, 'postid' => Dao_Td_Tudu_Post::getPostId($this->_fromTudu->tuduId), 'poster' => $this->_user->trueName, 'posterinfo' => $this->_user->position, 'email' => $this->_user->userName, 'content' => $tudu->content, 'header' => $header, 'createtime' => time());
     $postId = $daoPost->createPost($postParams);
     $daoPost->sendPost($tudu->tuduId, $postId);
     $attachments = $tudu->getAttachments();
     foreach ($attachments as $id => $attach) {
         $daoFile->addPost($tudu->tuduId, $postId, $attach['attachid'], $attach['isattachment']);
     }
     $this->_tuduLog('review', $tudu);
 }
Esempio n. 8
0
 /**
  *
  */
 private function _formatParams(Model_Tudu_Tudu &$tudu, array $params, $suffix = '')
 {
     $keys = array('tid' => array('type' => 'string', 'column' => 'tuduid'), 'ftid' => array('type' => 'string', 'column' => 'tuduid'), 'tuduid' => array('type' => 'string'), 'acceptmode' => array('type' => 'boolean'), 'subject' => array('type' => 'string'), 'content' => array('type' => 'html'), 'cc' => array('type' => 'receiver'), 'bcc' => array('type' => 'receiver'));
     $time = time();
     $attributes = array('orgid' => $this->_user->orgId, 'type' => 'task', 'boardid' => '^app-attend', 'appid' => 'attend', 'classid' => '^attend');
     foreach ($keys as $k => $item) {
         if ($k == 'to' && !empty($suffix)) {
             $val = $params['ch-' . $k . $suffix];
         } else {
             if (!isset($params[$k . $suffix])) {
                 continue;
             }
             $val = $params[$k . $suffix];
         }
         // 有依赖关系字段
         if (isset($item['depend']) && empty($params[$item['depend'] . $suffix])) {
             continue;
         }
         $col = isset($item['column']) ? $item['column'] : $k;
         switch ($item['type']) {
             case 'date':
                 $attributes[$col] = is_numeric($val) ? (int) $val : strtotime($val);
                 break;
             case 'boolean':
                 $attributes[$col] = (bool) $val;
                 break;
             case 'html':
                 $t = strip_tags($val, 'img');
                 $attributes[$col] = empty($t) ? '' : $val;
                 break;
             case 'receiver':
                 if (!empty($val)) {
                     $attributes[$col] = $this->_formatReceiver($val, in_array($col, array('to', 'reviewer')));
                 }
                 break;
             case 'string':
             default:
                 $attributes[$col] = trim($val);
                 break;
         }
     }
     if (isset($attributes['type']) && $attributes['type'] == 'notice') {
         $attributes['istop'] = 0;
         if (!empty($attributes['endtime']) && $attributes['endtime'] >= strtotime('today')) {
             $attributes['istop'] = 1;
         }
     }
     $attachments = array();
     if (!empty($params['nd-attach' . $suffix])) {
         $ret['attachment'] = array_diff($ret['attachment'], $params['nd-attach' . $suffix]);
         $daoNdFile = Tudu_Dao_Manager::getDao('Dao_Td_Netdisk_File', Tudu_Dao_Manager::DB_TS);
         $daoAttachment = Tudu_Dao_Manager::getDao('Dao_Td_Attachment_File', Tudu_Dao_Manager::DB_TS);
         foreach ($params['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) {
                 $attachments[] = array('fileid' => $fileId, 'isattachment' => true, 'isnetdisk' => true);
             }
         }
     }
     if (isset($params['attach' . $suffix]) && is_array($params['attach' . $suffix])) {
         foreach ($params['attach' . $suffix] as $item) {
             $attachments[] = array('fileid' => $item, 'isattachment' => true, 'isnetdisk' => false);
         }
     }
     if (isset($params['file' . $suffix]) && is_array($params['file' . $suffix])) {
         foreach ($params['file' . $suffix] as $item) {
             $attachments[] = array('fileid' => $item, 'isattachment' => false, 'isnetdisk' => false);
         }
     }
     $tudu->setAttributes($attributes);
     if (!empty($attachments)) {
         foreach ($attachments as $item) {
             $tudu->addAttachment($item['fileid'], $item['isattachment'], $item['isnetdisk']);
         }
     }
 }
Esempio n. 9
0
 /**
  * 拒绝图度
  */
 public function rejectAction()
 {
     $tuduIds = explode(',', $this->_request->getParam('tid'));
     // 参数:图度ID必须存在
     if (!count($tuduIds)) {
         return $this->json(false, $this->lang['invalid_tuduid']);
     }
     /* @var $daoTudu Dao_Td_Tudu_Tudu */
     $daoTudu = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Tudu', Tudu_Dao_Manager::DB_TS);
     /* @var $daoFlow Dao_Td_Tudu_Flow */
     $daoFlow = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Flow', Tudu_Dao_Manager::DB_TS);
     /* @var $daoTudu Dao_Td_Tudu_Group */
     $daoTuduGroup = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Group', Tudu_Dao_Manager::DB_TS);
     $resourceManager = new Tudu_Model_ResourceManager_Registry();
     $resourceManager->setResource(Tudu_Model::RESOURCE_CONFIG, $this->bootstrap->getOptions());
     Tudu_Model::setResourceManager($resourceManager);
     $success = 0;
     //用于计数操作成功个数
     foreach ($tuduIds as $tuduId) {
         // 获得图度数据
         $tudu = $daoTudu->getTuduById($this->_user->uniqueId, $tuduId);
         // 图度必须存在
         if (null == $tudu) {
             continue;
         }
         // 图度不能是已确定状态
         if ($tudu->isDone) {
             continue;
         }
         // 图度不能是“已完成”,“已拒绝”, “已取消”状态
         if ($tudu->selfTuduStatus > Dao_Td_Tudu_Tudu::STATUS_DOING) {
             continue;
         }
         // 操作人必须为图度执行人
         $isAccepter = in_array($this->_user->userName, $tudu->accepter);
         // 会议执行人有群组
         if ($tudu->type == 'meeting') {
             foreach ($tudu->accepter as $item) {
                 if ($isAccepter) {
                     break;
                 }
                 if (strpos($item, '^') == 0) {
                     $isAccepter = in_array($item, $this->_user->groups, true);
                 }
             }
         }
         if (!$isAccepter) {
             continue;
         }
         $isFlow = !empty($tudu->flowId) ? true : false;
         $tuduStatus = $daoTudu->rejectTudu($tuduId, $this->_user->uniqueId, $isFlow);
         if (false !== $tuduStatus) {
             $success++;
             //记录次数
             $updateTudu = array();
             /*if ($tudu->type == 'task' && empty($tudu->flowId)) { //任务拒绝步骤的指向
                   $updateTudu = array('stepid' => '^head');
               }*/
             // 拒绝后任务状态为完成的,生成周期任务
             if ($tudu->cycleId && $tuduStatus >= Dao_Td_Tudu_Tudu::STATUS_DONE) {
                 $config = $this->bootstrap->getOption('httpsqs');
                 // 插入消息队列
                 $httpsqs = new Oray_Httpsqs($config['host'], $config['port'], $config['chartset'], $config['name']);
                 $updateTudu = array('cycleid' => null);
                 $data = implode(' ', array('tudu', 'cycle', '', http_build_query(array('tuduid' => $tudu->tuduId, 'tsid' => $this->_user->tsId, 'cycleid' => $tudu->cycleId))));
                 $httpsqs->put($data, 'tudu');
             }
             if (!empty($updateTudu)) {
                 $daoTudu->updateTudu($tuduId, $updateTudu);
             }
             $tudu = $tudu->toArray();
             // 工作流 拒绝 步骤就拒绝
             if ($tudu['flowid']) {
                 $tudu['cc'] = null;
                 $flowRecord = $daoFlow->getFlow(array('tuduid' => $tudu['tuduid']));
                 $flow = new Model_Tudu_Extension_Flow($flowRecord->toArray());
                 $composeTudu = new Model_Tudu_Tudu(array('tuduid' => $tudu['tuduid'], 'status' => 1, 'type' => $tudu['type'], 'flowid' => $tudu['flowid']));
                 if (isset($flow->steps[$flow->currentStepId])) {
                     $step = $flow->steps[$flow->currentStepId];
                     $prevId = $step['prev'];
                     $isFrowardStep = false;
                     // 工作流中转发的步骤
                     // 如果所有人拒绝,则删除
                     if (0 !== strpos($tudu['stepid'], 'F-')) {
                         $flow->deleteStep($flow->currentStepId);
                         $isFrowardStep = true;
                     } else {
                         // 更新当前步骤状态
                         $flow->reject($flow->currentStepId, $this->_user->userName);
                     }
                     if (isset($flow->steps[$prevId])) {
                         $prev = $flow->steps[$prevId];
                         $updateStatus = $isFrowardStep;
                         $nextIndex = null;
                         // 上一步骤系审批
                         if ($prev['type'] == Dao_Td_Tudu_Step::TYPE_EXAMINE) {
                             $reviewer = array();
                             $flow->resetStep($prevId);
                             foreach ($prev['section'] as $idx => $sec) {
                                 foreach ($sec as $i => $u) {
                                     if ($idx == 0) {
                                         $reviewer[$u['username']] = array('username' => $u['username'], 'truename' => $u['truename'], 'uniqueid' => $u['uniqueid']);
                                     }
                                 }
                             }
                             $composeTudu->reviewer = $reviewer;
                             // 上一步骤系执行
                         } else {
                             $to = array();
                             $flow->resetStep($prevId);
                             foreach ($prev['section'] as $idx => $sec) {
                                 foreach ($sec as $i => $u) {
                                     if ($idx == 0) {
                                         $to[$u['username']] = array('username' => $u['username'], 'truename' => $u['truename'], 'uniqueid' => $u['uniqueid']);
                                     }
                                 }
                             }
                             $composeTudu->reviewer = null;
                             $composeTudu->to = $to;
                         }
                         $stepId = $prev['stepid'];
                     } else {
                         $stepId = $prevId;
                     }
                 } else {
                     $stepId = '^break';
                 }
                 $flow->flowTo($stepId);
                 $composeTudu->stepId = $stepId;
                 if ($stepId == '^break' || $stepId == '^head') {
                     $composeTudu->to = array($tudu['from'][3] => array('username' => $tudu['from'][3], 'truename' => $tudu['from'][0]));
                 }
                 // 准备发送
                 //$modelCompose = new Model_Tudu_Compose_Save($tudu);
                 $modelSend = new Model_Tudu_Send_Common();
                 //$recipients = $deliver->prepareRecipients($this->_user->uniqueId, $this->_user->userId, $tudu);
                 // 移除原执行人
                 if ($composeTudu->to && !$composeTudu->reviewer) {
                     $accepters = $daoTudu->getAccepters($tudu['tuduid']);
                     $to = $composeTudu->to;
                     foreach ($accepters as $item) {
                         list($email, ) = explode(' ', $item['accepterinfo'], 2);
                         // 移除执行人角色,我执行标签
                         if (!empty($to) && !array_key_exists($email, $to) && $daoTuduGroup->getChildrenCount($tudu['tuduid'], $item['uniqueid']) <= 0) {
                             $daoTudu->removeAccepter($tudu['tuduid'], $item['uniqueid']);
                             $this->manager->deleteLabel($tudu['tuduid'], $item['uniqueid'], '^a');
                         }
                     }
                 }
                 // 执行人自动接受图度
                 $currentStep = $flow->getStep($flow->currentStepId);
                 if ($stepId != '^break' && $stepId != '^head' && isset($steps[$stepId]) && $currentStep['type'] != Dao_Td_Tudu_Step::TYPE_EXAMINE) {
                     if ($currentStep['type'] == Dao_Td_Tudu_Step::TYPE_EXECUTE) {
                         foreach ($currentStep['section'][0] as $item) {
                             $daoTudu->acceptTudu($tudu['tuduid'], $item['uniqueid'], null);
                         }
                         $updateParams['acceptmode'] = 0;
                     } else {
                         if ($currentStep['type'] == Dao_Td_Tudu_Step::TYPE_CLAIM) {
                             $composeTudu->acceptMode = 1;
                             $composeTudu->acceptTime = null;
                         }
                     }
                 }
                 //$this->manager->updateTudu($tudu->tuduId, $updateParams);
                 $daoFlow->updateFlow($flow->tuduId, $flow->toArray());
                 //$modelCompose->compose($composeTudu);
                 $params = $composeTudu->getStorageParams();
                 $daoTudu->updateTudu($tudu['tuduid'], $params);
                 $modelSend->send($composeTudu, true);
                 $daoTudu->markAllUnRead($tudu['tuduid']);
                 $daoTudu->updateFlowProgress($tudu['tuduid'], null, $flow->currentStepId);
                 // 不是自动工作流,回到发起
             } else {
                 $flowRecord = $daoFlow->getFlow(array('tuduid' => $tudu['tuduid']));
                 $flow = new Model_Tudu_Extension_Flow($flowRecord->toArray());
                 $flow->flowTo('^head');
                 $daoFlow->updateFlow($tudu['tuduid'], $flow->toArray());
             }
             if ($tudu['parentid']) {
                 $daoTudu->calParentsProgress($tudu['parentid']);
             }
             // 添加操作日志
             $this->_writeLog(Dao_Td_Log_Log::TYPE_TUDU, $tuduId, Dao_Td_Log_Log::ACTION_TUDU_DECLINE, array('selfstatus' => Dao_Td_Tudu_Tudu::STATUS_REJECT, 'status' => $tuduStatus));
         }
     }
     if ($success <= 0) {
         return $this->json(false, $this->lang['reject_failure']);
     }
     return $this->json(true, $this->lang['reject_success']);
 }
Esempio n. 10
0
 /**
  *
  * @param Model_Tudu_Tudu $tudu
  */
 protected function _save(Model_Tudu_Tudu &$tudu)
 {
     /* @var $apply Model_App_Attend_Tudu_Apply */
     $apply = $tudu->getExtension('Model_App_Attend_Tudu_Apply');
     /* @var $daoApply Dao_App_Attend_Apply */
     $daoApply = Tudu_Dao_Manager::getDao('Dao_App_Attend_Apply', Tudu_Dao_Manager::DB_APP);
     $params = $apply->getAttributes();
     $params['tuduid'] = $tudu->tuduId;
     if (null !== $this->_fromApply) {
         if ($apply->status > 2) {
             $params['status'] = 1;
         }
         $ret = $daoApply->updateApply($apply->applyId, $params);
         $applyId = $apply->applyId;
     } else {
         $applyId = Dao_App_Attend_Apply::getApplyId();
         $params['applyid'] = $applyId;
         $ret = $daoApply->createApply($params);
     }
     if (!$ret) {
         require_once 'Model/App/Attend/Exception.php';
         throw new Model_App_Attend_Exception('Save apply failure', Model_App_Attend_Exception::APPLY_SAVE_FAILED);
     }
     $tudu->applyId = $applyId;
 }
Esempio n. 11
0
 /**
  *
  * @param array  $params
  * @param string $suffix
  */
 private function _prepareVoteParams(Model_Tudu_Tudu &$tudu, array $params, $suffix = '')
 {
     $voteMember = 'votemember' . $suffix;
     if (!empty($params[$voteMember]) && is_array($params[$voteMember])) {
         $vote = new Model_Tudu_Extension_Vote();
         foreach ($params[$voteMember] as $item) {
             $p = array('title' => $params['title-' . $item . $suffix], 'maxchoices' => (int) $params['maxchoices-' . $item . $suffix], 'visible' => !empty($params['visible-' . $item . $suffix]) ? (int) $params['visible-' . $item . $suffix] : 0, 'anonymous' => !empty($params['anonymous-' . $item . $suffix]) ? (int) $params['anonymous-' . $item . $suffix] : 0, 'privacy' => !empty($params['privacy-' . $item . $suffix]) ? (int) $params['privacy-' . $item . $suffix] : 0, 'isreset' => !empty($params['isreset-' . $item . $suffix]) ? (int) $params['isreset-' . $item . $suffix] : 0, 'ordernum' => $params['voteorder-' . $item . $suffix], 'expiretime' => !empty($params['endtime']) ? strtotime($params['endtime']) : null);
             if (isset($params['voteid-' . $item . $suffix])) {
                 $p['voteid'] = $params['voteid-' . $item . $suffix];
             }
             $voteId = $vote->addVote($p);
             $optionMember = 'optionid-' . $item . $suffix;
             $newOptionMember = 'newoption-' . $item . $suffix;
             if (!empty($params[$optionMember]) && is_array($params[$optionMember])) {
                 foreach ($params[$optionMember] as $option) {
                     $opt = array('optionid' => $option, 'text' => $params['text-' . $item . '-' . $option . $suffix]);
                     if (isset($params['ordernum-' . $item . '-' . $option . $suffix])) {
                         $opt['ordernum'] = (int) $params['ordernum-' . $item . '-' . $option . $suffix];
                     }
                     $vote->addOption($voteId, $opt);
                 }
             }
             if (!empty($params[$newOptionMember]) && is_array($params[$newOptionMember])) {
                 foreach ($params[$newOptionMember] as $option) {
                     $opt = array('text' => $params['text-' . $item . '-' . $option . $suffix], 'ordernum' => (int) $params['ordernum-' . $item . '-' . $option . $suffix]);
                     $vote->addOption($voteId, $opt);
                 }
             }
         }
         $tudu->setExtension($vote);
     }
 }
Esempio n. 12
0
 /**
  *
  * @param Model_Tudu_Tudu $tudu
  */
 public function action(Model_Tudu_Tudu &$tudu)
 {
     $group = $tudu->getExtension('Model_Tudu_Extension_Group');
     /* @var $daoGroup Dao_Td_Tudu_Group */
     $daoGroup = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Group', Tudu_Dao_Manager::DB_TS);
     if (null == $group) {
         return;
     }
     if (!$tudu->fromTudu || !$tudu->fromTudu->nodeType) {
         $daoGroup->createNode(array('tuduid' => $tudu->tuduId, 'type' => $tudu->nodeType, 'uniqueid' => $tudu->uniqueId, 'rootid' => $tudu->rootId));
     } elseif ($tudu->fromTudu->nodeType == 'leaf') {
         $daoGroup->updateNode($tudu->tuduId, array('type' => count($group->getChildren()) > 0 ? 'node' : 'leaf'));
     }
     $children = $group->getChildren();
     $model = $this->getModel();
     foreach ($children as &$child) {
         if ($tudu->fromTudu && !$tudu->fromTudu->isDraft && !$child->isModified) {
             continue;
         }
         $params = array(&$child);
         $model->compose($child);
         if (!$child->fromTudu || !$child->fromTudu->nodeType) {
             $daoGroup->createNode(array('tuduid' => $child->tuduId, 'type' => $child->nodeType, 'parentid' => $tudu->tuduId, 'rootid' => $tudu->rootId, 'uniqueid' => $tudu->uniqueId));
         }
         $model->applyHooksFunc('compose', 'action', $params);
         if ($tudu->operation != 'save') {
             $this->getSendModel()->send($child);
         }
     }
 }
Esempio n. 13
0
 /**
  *
  * @param Model_Tudu_Tudu $tudu
  * @param array $params
  */
 protected function _formatParams(Model_Tudu_Tudu &$tudu, array $params)
 {
     $attributes = array();
     //$attachment = array();
     foreach ($params as $key => $value) {
         switch ($key) {
             case 'starttime':
             case 'endtime':
                 $attributes[$key] = is_numeric($value) ? (int) $value : strtotime($value);
                 break;
             case 'priority':
             case 'privacy':
             case 'notifyall':
             case 'cycle':
             case 'isauth':
             case 'needconfirm':
             case 'istop':
             case 'acceptmode':
                 $attributes[$key] = (bool) $value;
                 break;
             case 'to':
             case 'cc':
             case 'bcc':
                 if (!empty($value)) {
                     $attributes[$key] = $this->_formatReceiver($value, $key == 'to');
                 }
                 break;
             case 'reviewer':
                 break;
             case 'image':
                 break;
             case 'subject':
             case 'classid':
             case 'tuduid':
             case 'location':
             default:
                 $attributes[$key] = $value;
         }
     }
     // 处理附件图片
     $attributes['content'] = !empty($attributes['content']) ? nl2br($attributes['content']) : '';
     $attachments = array();
     if (isset($params['image'])) {
         $images = $params['image'];
         if (!is_array($params['image'])) {
             $images = explode(',', $images);
         }
         foreach ($images as $fileId) {
             if (!$fileId) {
                 continue;
             }
             if (false !== strpos($fileId, ',')) {
                 $arr = explode(',', $fileId);
                 foreach ($arr as $fid) {
                     $attachments[] = array('fileid' => $fid, 'isattachment' => false, 'isnetdisk' => false);
                     $fid = str_replace('AID:', '', $fid);
                     $attributes['content'] .= '<br /><img src="AID:' . $fid . '" _aid="' . $fid . '" />';
                 }
                 continue;
             }
             $attachments[] = array('fileid' => $fileId, 'isattachment' => false, 'isnetdisk' => false);
             $fileId = str_replace('AID:', '', $fileId);
             $attributes['content'] .= '<br /><img src="AID:' . $fileId . '" _aid="' . $fileId . '" />';
         }
     }
     $tudu->setAttributes($attributes);
     if (!empty($attachments)) {
         foreach ($attachments as $item) {
             $tudu->addAttachment($item['fileid'], $item['isattachment'], $item['isnetdisk']);
         }
     }
 }
Esempio n. 14
0
 /**
  * 发送图度操作
  *
  * @param Model_Tudu_Tudu $tudu
  */
 public function send(Model_Tudu_Tudu &$tudu)
 {
     $object = array('tuduid' => $tudu->tuduId, 'tsid' => $this->_user->tsId, 'uniqueid' => $this->_user->uniqueId, 'orgid' => $this->_user->orgId, 'from' => $this->_user->userName, 'type' => $tudu->type, 'host' => $_SERVER['HTTP_HOST'], 'action' => $tudu->operation, 'iscreate' => !$tudu->fromTudu || $tudu->fromTudu->isDraft, 'isflow' => !!$tudu->flowId, 'parentid' => $tudu->fromTudu ? $tudu->fromTudu->parentId : $tudu->parentId, 'operator' => array('uniqueid' => $this->_user->uniqueId, 'username' => $this->_user->userName, 'truename' => $this->_user->trueName));
     if ($tudu->operation == 'review') {
         $sqsAction = 'review';
         $object['stepid'] = $tudu->fromTudu->stepId;
         $object['agree'] = $tudu->agree;
         if ($tudu->flowId) {
             $flow = $tudu->getExtension('Model_Tudu_Extension_Flow');
             if ($flow) {
                 $object['flow']['nstepid'] = $flow->currentStepId;
                 $object['flow']['flowid'] = $tudu->flowId;
                 $object['flow']['stepstatus'] = $flow->currentStepId != $tudu->fromTudu->stepId ? 1 : 0;
             }
         }
         if ($tudu->type == 'notice' && $tudu->stepId == '^end') {
             $sqsAction = 'create';
         }
     }
     $receiver = array();
     if ($tudu->reviewer) {
         $reviewers = $tudu->reviewer;
         foreach ($reviewers as $reviewer) {
             $item = array('username' => $reviewer['username'], 'truename' => $reviewer['truename']);
             if (isset($reviewer['unqiueid'])) {
                 $item['uniqueid'] = $reviewer['uniqueid'];
             }
             $receiver['reviewer'][] = $item;
         }
     } elseif ($tudu->to) {
         $to = $tudu->to;
         foreach ($to as $u) {
             if (!Oray_Function::isEmail($u['username'])) {
                 $item = array('username' => $u['username'], 'truename' => $u['truename'], 'role' => 'to', 'percent' => isset($u['percent']) ? $u['percent'] : 0, 'status' => isset($u['status']) ? $u['status'] : (empty($u['percent']) || $u['percent'] < 0 ? 0 : ($u['percent'] >= 100 ? 2 : 1)));
             } else {
                 $item = array('email' => $u['username'], 'truename' => $u['truename'], 'role' => 'to', 'percent' => isset($u['percent']) ? $u['percent'] : 0, 'status' => isset($u['status']) ? $u['status'] : (empty($u['percent']) || $u['percent'] < 0 ? 0 : ($u['percent'] >= 100 ? 2 : 1)));
             }
             $receiver['to'][] = $item;
         }
     }
     if ($tudu->cc && ($tudu->type != 'notice' || !$tudu->reviewer)) {
         $cc = $tudu->cc;
         foreach ($cc as $u) {
             if (!empty($u['groupid'])) {
                 $receiver['cc'][] = array('groupid' => $u['groupid']);
             } else {
                 $receiver['cc'][] = array('username' => $u['username'], 'truename' => $u['truename']);
             }
         }
     }
     if ($tudu->bcc) {
         $bcc = $tudu->bcc;
         foreach ($bcc as $u) {
             if ($u['groupid']) {
                 $receiver['bcc'][] = array('groupid' => $u['groupid']);
             } else {
                 $receiver['bcc'][] = array('username' => $u['username'], 'truename' => $u['truename']);
             }
         }
     }
     $object['receiver'] = $receiver;
     $error = null;
     do {
         $connection = $this->_getConnection();
         $bytes = @fwrite($connection, json_encode(array('type' => 'queue', 'data' => $object)));
         if (!$bytes) {
             $error = 'Data transfer error, posting tudu data to deliver service failed.';
             break;
         }
         $response = @fgets($connection);
         if (!$response || !($resposne = @json_decode($response, true))) {
             $error = 'Invalid response data.';
             break;
         }
     } while (false);
     if ($error) {
         require_once 'Model/Tudu/Exception.php';
         throw new Model_Tudu_Exception('连接发送服务器失败,请稍候重试');
     }
     // 标记发送
     Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Tudu', Tudu_Dao_Manager::DB_TS)->sendTudu($tudu->tuduId);
     return $response['code'] == self::CODE_SUCCESS;
 }
Esempio n. 15
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));
 }
Esempio n. 16
0
 /**
  *
  * @param Model_Tudu_Tudu $tudu
  */
 protected function _getLogDetail(Model_Tudu_Tudu $tudu)
 {
     $detail = array();
     $params = $tudu->getStorageParams();
     if (!$this->_fromTudu || $this->_fromTudu->isDraft) {
         foreach ($params as $key => $value) {
             if (!empty($value)) {
                 $detail[$key] = $value;
             }
         }
         return $detail;
     }
     $excepts = array('attach', 'uniqueid', 'status', 'poster', 'posterinfo', 'lastposter', 'issend');
     $tudu = $this->_fromTudu->toArray();
     $ret = array();
     foreach ($params as $key => $val) {
         if (in_array($key, $excepts) || empty($val)) {
             continue;
         }
         if ($key == 'to') {
             if (count($params[$key]) != count($tudu['accepter'])) {
                 $val = Tudu_Tudu_Storage::formatReceiver($params[$key]);
             } elseif (is_array($params[$key])) {
                 foreach ($params[$key] as $k => $val) {
                     if (!in_array($k, $tudu['accepter'])) {
                         $val = Tudu_Tudu_Storage::formatReceiver($params[$key]);
                     }
                 }
             }
             continue;
         }
         if ($key == 'cc' || $key == 'bcc') {
             $val = Tudu_Tudu_Storage::formatReceiver($params[$key]);
         }
         if (array_key_exists($key, $tudu) && $params[$key] != $tudu[$key]) {
             $detail[$key] = $val;
         }
     }
     return $detail;
 }
Esempio n. 17
0
 /**
  *
  * @param Model_Tudu_Tudu $tudu
  */
 public function saveTuduFlow(Model_Tudu_Tudu &$tudu)
 {
     $flow = $tudu->getExtension('Model_Tudu_Extension_Flow');
     if (null === $flow) {
         return;
     }
     if (!$flow->tuduId) {
         $flow->tuduId = $tudu->tuduId;
     }
     if ($flow->fromFlow) {
         $this->updateFlow($flow);
     } else {
         $this->createFlow($flow);
     }
 }
Esempio n. 18
0
 /**
  * (non-PHPdoc)
  * @see Model_Tudu_Compose_Abstract::compose()
  */
 public function compose(Model_Tudu_Tudu &$tudu)
 {
     /* @var $daoTudu Dao_Td_Tudu_Tudu */
     $daoTudu = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Tudu', Tudu_Dao_Manager::DB_TS);
     $user = Tudu_User::getInstance();
     $attrs = $tudu->getStorageParams();
     if ($this->_isModified) {
         $params = array();
         foreach ($attrs as $key => $val) {
             if (in_array($key, array('content', 'attach', 'attachment', 'subject', 'flowid', 'from'))) {
                 continue;
             }
             $params[$key] = $val;
         }
         if (!empty($attrs['stepid'])) {
             $params['stepid'] = $attrs['stepid'];
         }
         $time = time();
         $params['lastposttime'] = $time;
         $params['lastposter'] = $user->trueName;
         if (!$daoTudu->updateTudu($tudu->tuduId, $params)) {
             require_once 'Model/Tudu/Exception.php';
             throw new Model_Tudu_Exception('Tudu save failed', Model_Tudu_Exception::SAVE_FAILED);
         }
     } else {
         $params = array('to' => $attrs['to']);
         if (!empty($attrs['cc'])) {
             $params['cc'] = $attrs['cc'];
         }
         if (!empty($attrs['bcc'])) {
             $params['bcc'] = $attrs['bcc'];
         }
         if (!empty($attrs['stepid'])) {
             $params['stepid'] = $attrs['stepid'];
         }
         if (!$daoTudu->updateTudu($tudu->tuduId, $params)) {
             require_once 'Model/Tudu/Exception.php';
             throw new Model_Tudu_Exception('Tudu save failed', Model_Tudu_Exception::SAVE_FAILED);
         }
     }
     /* @var $daoPost Dao_Td_Tudu_Post */
     $daoPost = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Post', Tudu_Dao_Manager::DB_TS);
     /* @var $daoAttach Dao_Td_Attachment_File */
     $daoAttach = Tudu_Dao_Manager::getDao('Dao_Td_Attachment_File', Tudu_Dao_Manager::DB_TS);
     /* @var $daoFile Dao_Td_Netdisk_File */
     $daoFile = Tudu_Dao_Manager::getDao('Dao_Td_Netdisk_File', Tudu_Dao_Manager::DB_TS);
     $toArr = array();
     foreach ($tudu->to as $sec) {
         foreach ($sec as $item) {
             $toArr[] = array('username' => $item['username'], 'truename' => $item['truename']);
         }
         break;
     }
     $header = array('action' => 'forward', 'to' => $toArr);
     if ($tudu->reviewer) {
         $header['reviewer'] = array();
         foreach ($tudu->reviewer as $sec) {
             foreach ($sec as $item) {
                 $header['reviewer'][] = array('username' => $item['username'], 'truename' => $item['truename']);
             }
         }
     }
     $attachments = $tudu->getAttachments();
     // 处理网盘附件
     $attachNum = 0;
     foreach ($attachments as $k => $attach) {
         if ($attach['isnetdisk']) {
             $fileId = $attach['fileid'];
             if (null !== $daoAttach->getFile(array('fileid' => $fileId))) {
                 $ret['attachment'][] = $fileId;
                 continue;
             }
             $file = $daoFile->getFile(array('uniqueid' => $user->uniqueId, 'fileid' => $fileId));
             if (null === $file) {
                 continue;
             }
             $fileId = $file->fromFileId ? $file->fromFileId : $file->attachFileId;
             $ret = $daoAttach->createFile(array('uniqueid' => $user->uniqueId, 'fileid' => $fileId, 'orgid' => $user->orgId, 'filename' => $file->fileName, 'path' => $file->path, 'type' => $file->type, 'size' => $file->size, 'createtime' => $this->_time));
             if ($ret) {
                 $attachments[$k]['fileid'] = $fileId;
             } else {
                 unset($attachments[$k]);
             }
         }
         if ($attach['isattach']) {
             $attachNum++;
         }
     }
     $postParams = array('orgid' => $tudu->orgId, 'tuduid' => $tudu->tuduId, 'boardid' => $tudu->boardId, 'postid' => Dao_Td_Tudu_Post::getPostId($tudu->tuduId), 'uniqueid' => $this->_user->uniqueId, 'poster' => $this->_user->trueName, 'email' => $this->_user->userName, 'content' => $tudu->content, 'attachnum' => $attachNum, 'createtime' => time(), 'header' => $header);
     $postId = $daoPost->createPost($postParams);
     $daoPost->sendPost($tudu->tuduId, $postId);
     $attachments = $tudu->getAttachments();
     foreach ($attachments as $id => $attach) {
         $daoAttach->addPost($tudu->tuduId, $postId, $attach['fileid'], $attach['isattach']);
     }
     $this->_tuduLog('forward', $tudu);
 }
Esempio n. 19
0
 /**
  * 发送图度
  *
  * @param Model_Tudu_Tudu $tudu
  * @throws Model_Tudu_Exception
  */
 public function compose(Model_Tudu_Tudu &$tudu)
 {
     if (!$tudu->tuduId) {
         $tudu->setAttribute('tuduid', Dao_Td_Tudu_Tudu::getTuduId());
     }
     // 保存图度
     if (null !== $tudu->fromTudu) {
         if (!$tudu->fromTudu->isDraft) {
             $user = Tudu_User::getInstance();
             $time = time();
             $tudu->lastPostTime = $time;
             $tudu->lastPoster = $user->trueName;
             $tudu->lastModify = implode(chr(9), array($user->uniqueId, $time, $user->trueName));
         }
         $this->_updateTudu($tudu);
     } else {
         $this->_createTudu($tudu);
     }
     $logAction = null !== $tudu->fromTudu && !$tudu->fromTudu->isDraft ? 'update' : 'send';
     $this->_tuduLog($logAction, $tudu);
 }